RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
model.h File Reference

Caller-owned indexed data and virtual windows. More...

#include <stddef.h>
#include <stdint.h>
#include "geom.h"
#include "input.h"
#include "style.h"

Data Structures

struct  rmgui_model_row_t
 One borrowed UTF-8 cell and row metadata; height comes from the prefix map. More...
struct  rmgui_model_t
struct  rmgui_model_view_t
 IDs live in disjoint caller-owned hash slots; do not mutate slots directly. More...
struct  rmgui_model_result_t

Macros

#define RMGUI_MODEL_NO_ID   UINT64_MAX
 Reserved identity/index values; all other identities are caller-defined.
#define RMGUI_MODEL_NO_ROW   SIZE_MAX
#define RMGUI_MODEL_TEXT   1u
 Fields invalidated by rows_changed; unknown bits are refused.
#define RMGUI_MODEL_ICON   2u
#define RMGUI_MODEL_STATE   4u
#define RMGUI_MODEL_DEPTH   8u
#define RMGUI_MODEL_HEIGHT   16u
#define RMGUI_MODEL_ALL_FIELDS   31u

Typedefs

typedef int(*) rmgui_model_get_fn(void *, size_t row, size_t column, rmgui_model_row_t *)
 Callbacks return 0 or refuse (-1), leaving output unchanged.
typedef int(*) rmgui_model_find_fn(void *, uint64_t id, size_t *row)
typedef int(*) rmgui_model_prefix_fn(void *, size_t boundary, int64_t *height)
typedef int(*) rmgui_model_match_fn(void *, size_t after, const char *, size_t, size_t *)
 Matcher searches the caller's index, returning NO_ROW when absent.
typedef int(*) rmgui_model_expand_fn(void *, uint64_t id, int expanded)
 Expand must atomically update the caller's projection or refuse unchanged.

Enumerations

enum  rmgui_model_selection_t { RMGUI_MODEL_SELECT_NONE , RMGUI_MODEL_SELECT_SINGLE , RMGUI_MODEL_SELECT_MULTI , RMGUI_MODEL_SELECT_EXTENDED }
 Selection modes: MULTI toggles ordinary clicks; EXTENDED toggles Ctrl and selects anchor ranges with Shift. More...
enum  rmgui_model_event_t {
  RMGUI_MODEL_EVENT_NONE , RMGUI_MODEL_EVENT_SELECT , RMGUI_MODEL_EVENT_ACTIVATE , RMGUI_MODEL_EVENT_DRAG ,
  RMGUI_MODEL_EVENT_SORT , RMGUI_MODEL_EVENT_REORDER , RMGUI_MODEL_EVENT_CLAIM
}
 Results retain full-width row identity; input.value is not a row index. More...

Functions

int rmgui_model_init (rmgui_model_t *, void *, size_t, int, rmgui_model_get_fn, rmgui_model_find_fn, rmgui_model_prefix_fn)
 Checked initialization; count < SIZE_MAX; callbacks get/find required.
int rmgui_model_rows_inserted (rmgui_model_t *, size_t first, size_t count)
 Marks follow the caller's data edit, using pre-edit indices for insertion, removal and move.
int rmgui_model_rows_removed (rmgui_model_t *, size_t first, size_t count)
int rmgui_model_rows_changed (rmgui_model_t *, size_t first, size_t count, unsigned fields)
int rmgui_model_rows_moved (rmgui_model_t *, size_t first, size_t count, size_t destination)
int rmgui_model_view_init (rmgui_model_view_t *, rmgui_model_t *, rmgui_model_selection_t, uint64_t *, size_t)
 Returns 0 or -1 unchanged; NULL selection storage is valid only at zero capacity.
int rmgui_model_visible (rmgui_model_view_t *, rmgui_rect_t, size_t *first, size_t *end)
 O(log count + visible rows) for prefix maps, O(visible rows) fixed height.
int rmgui_model_row_rect (const rmgui_model_view_t *, rmgui_rect_t, size_t, rmgui_rect_t *)
int rmgui_model_hit (rmgui_model_view_t *, rmgui_rect_t, int x, int y, size_t *row)
int rmgui_model_sync (rmgui_model_view_t *)
 Retains focus/selection by ID after caller edits; absent IDs are removed.
int rmgui_model_select (rmgui_model_view_t *, size_t row, unsigned mods)
 Selection is transactional on capacity/accessor failure.
int rmgui_model_is_selected (const rmgui_model_view_t *, uint64_t id)
 Expected O(1) identity membership; NULL/invalid views and NO_ID yield 0.
int rmgui_model_scroll_into_view (rmgui_model_view_t *, rmgui_rect_t, size_t row)
int rmgui_model_input (rmgui_model_view_t *, rmgui_rect_t, const rmgui_input_t *, const rmgui_model_painter_t *, rmgui_model_result_t *)
 Pointer, wheel, keyboard, focus and matcher-backed TEXT events.

Detailed Description

Caller-owned indexed data and virtual windows.

No operation allocates.

Macro Definition Documentation

◆ RMGUI_MODEL_NO_ID

#define RMGUI_MODEL_NO_ID   UINT64_MAX

Reserved identity/index values; all other identities are caller-defined.

◆ RMGUI_MODEL_NO_ROW

#define RMGUI_MODEL_NO_ROW   SIZE_MAX

◆ RMGUI_MODEL_TEXT

#define RMGUI_MODEL_TEXT   1u

Fields invalidated by rows_changed; unknown bits are refused.

◆ RMGUI_MODEL_ICON

#define RMGUI_MODEL_ICON   2u

◆ RMGUI_MODEL_STATE

#define RMGUI_MODEL_STATE   4u

◆ RMGUI_MODEL_DEPTH

#define RMGUI_MODEL_DEPTH   8u

◆ RMGUI_MODEL_HEIGHT

#define RMGUI_MODEL_HEIGHT   16u

◆ RMGUI_MODEL_ALL_FIELDS

#define RMGUI_MODEL_ALL_FIELDS   31u

Typedef Documentation

◆ rmgui_model_get_fn

typedef int(*) rmgui_model_get_fn(void *, size_t row, size_t column, rmgui_model_row_t *)

Callbacks return 0 or refuse (-1), leaving output unchanged.

get and find must describe the same current projection, and repeat calls for unchanged data must return the same status/value. find returns NO_ROW for absent IDs. prefix(i) is strictly increasing for i=0..count, starts at zero and fits INT64_MAX. A NULL prefix selects fixed_height > 0. Callback user data and text are borrowed; the caller serializes all access and mutation.

◆ rmgui_model_find_fn

typedef int(*) rmgui_model_find_fn(void *, uint64_t id, size_t *row)

◆ rmgui_model_prefix_fn

typedef int(*) rmgui_model_prefix_fn(void *, size_t boundary, int64_t *height)

◆ rmgui_model_match_fn

typedef int(*) rmgui_model_match_fn(void *, size_t after, const char *, size_t, size_t *)

Matcher searches the caller's index, returning NO_ROW when absent.

◆ rmgui_model_expand_fn

typedef int(*) rmgui_model_expand_fn(void *, uint64_t id, int expanded)

Expand must atomically update the caller's projection or refuse unchanged.

The caller invokes the appropriate mark functions inside the callback.

Enumeration Type Documentation

◆ rmgui_model_selection_t

Selection modes: MULTI toggles ordinary clicks; EXTENDED toggles Ctrl and selects anchor ranges with Shift.

NONE still allows focus/activation.

Enumerator
RMGUI_MODEL_SELECT_NONE 
RMGUI_MODEL_SELECT_SINGLE 
RMGUI_MODEL_SELECT_MULTI 
RMGUI_MODEL_SELECT_EXTENDED 

◆ rmgui_model_event_t

Results retain full-width row identity; input.value is not a row index.

Enumerator
RMGUI_MODEL_EVENT_NONE 
RMGUI_MODEL_EVENT_SELECT 
RMGUI_MODEL_EVENT_ACTIVATE 
RMGUI_MODEL_EVENT_DRAG 
RMGUI_MODEL_EVENT_SORT 
RMGUI_MODEL_EVENT_REORDER 
RMGUI_MODEL_EVENT_CLAIM 

Function Documentation

◆ rmgui_model_init()

int rmgui_model_init ( rmgui_model_t * ,
void * ,
size_t ,
int ,
rmgui_model_get_fn ,
rmgui_model_find_fn ,
rmgui_model_prefix_fn  )

Checked initialization; count < SIZE_MAX; callbacks get/find required.

Refusal leaves self unchanged. count=0 is valid.

◆ rmgui_model_rows_inserted()

int rmgui_model_rows_inserted ( rmgui_model_t * ,
size_t first,
size_t count )

Marks follow the caller's data edit, using pre-edit indices for insertion, removal and move.

Move destination is an index after removal. No scanning or diffing. Generation overflow, invalid ranges and zero count refuse. On refusal model state is unchanged; data rollback belongs to the caller.

◆ rmgui_model_rows_removed()

int rmgui_model_rows_removed ( rmgui_model_t * ,
size_t first,
size_t count )

◆ rmgui_model_rows_changed()

int rmgui_model_rows_changed ( rmgui_model_t * ,
size_t first,
size_t count,
unsigned fields )

◆ rmgui_model_rows_moved()

int rmgui_model_rows_moved ( rmgui_model_t * ,
size_t first,
size_t count,
size_t destination )

◆ rmgui_model_view_init()

int rmgui_model_view_init ( rmgui_model_view_t * ,
rmgui_model_t * ,
rmgui_model_selection_t ,
uint64_t * ,
size_t  )

Returns 0 or -1 unchanged; NULL selection storage is valid only at zero capacity.

Initialization empties all slots. Single selection requires at least one slot. Caller storage must not overlap the view/model records.

◆ rmgui_model_visible()

int rmgui_model_visible ( rmgui_model_view_t * ,
rmgui_rect_t ,
size_t * first,
size_t * end )

O(log count + visible rows) for prefix maps, O(visible rows) fixed height.

visible returns a half-open range; hit refuses outside rect/empty content. Rect width/height must be positive and coordinates must fit int.

◆ rmgui_model_row_rect()

int rmgui_model_row_rect ( const rmgui_model_view_t * ,
rmgui_rect_t ,
size_t ,
rmgui_rect_t *  )

◆ rmgui_model_hit()

int rmgui_model_hit ( rmgui_model_view_t * ,
rmgui_rect_t ,
int x,
int y,
size_t * row )

◆ rmgui_model_sync()

int rmgui_model_sync ( rmgui_model_view_t * )

Retains focus/selection by ID after caller edits; absent IDs are removed.

Callback refusal leaves the view and its selection storage unchanged.

◆ rmgui_model_select()

int rmgui_model_select ( rmgui_model_view_t * ,
size_t row,
unsigned mods )

Selection is transactional on capacity/accessor failure.

Ctrl/Shift use RMGUI_INPUT_MOD bits. Scrolling reveals the row without selecting it.

◆ rmgui_model_is_selected()

int rmgui_model_is_selected ( const rmgui_model_view_t * ,
uint64_t id )

Expected O(1) identity membership; NULL/invalid views and NO_ID yield 0.

◆ rmgui_model_scroll_into_view()

int rmgui_model_scroll_into_view ( rmgui_model_view_t * ,
rmgui_rect_t ,
size_t row )

◆ rmgui_model_input()

int rmgui_model_input ( rmgui_model_view_t * ,
rmgui_rect_t ,
const rmgui_input_t * ,
const rmgui_model_painter_t * ,
rmgui_model_result_t *  )

Pointer, wheel, keyboard, focus and matcher-backed TEXT events.

Drag starts after four pixels; insertion geometry is a two-pixel horizontal marker. EXTENDED Ctrl+SPACE toggles focus selection; Shift+SPACE selects the anchor range. MULTI SPACE toggles; otherwise SPACE and ENTER activate. A refusal returns -1 with view/storage/result unchanged.