added scroll list

This commit is contained in:
2026-01-12 22:02:50 +05:00
parent 717c049265
commit c5328cb9ed
2 changed files with 71 additions and 6 deletions

View File

@@ -157,6 +157,7 @@ typedef struct TimEvent {
char s[32]; // string representation of key, used by TimEvent_Key
} TimEvent;
typedef struct TimEditState {
bool masked; // if true prints '*' instead of buffer content
i32 cursor; // cursor position (utf8)
@@ -165,6 +166,22 @@ typedef struct TimEditState {
char* s; // zero terminated buffer
} TimEditState;
typedef struct TimScrollItem {
void* data;
void* focus_target; // is assigned to tim->focus
i32 h; // height of the item to know where to draw next item
void (*draw)(bool is_selected, TimRect place, void* data);
} TimScrollItem;
typedef struct TimScrollState {
TimScrollItem* items;
u32 len;
u32 cur;
bool use_mouse_wheel;
} TimScrollState;
typedef struct TimState {
i32 w; // screen width
i32 h; // screen height
@@ -247,8 +264,6 @@ i32 tim_exit_scope(void);
#pragma region widgets
// TODO: create enum TimColor and struct TimStyle
// frame
// color: background, frame
void tim_frame(i32 x, i32 y, i32 w, i32 h, TimStyle style);
@@ -281,7 +296,7 @@ bool tim_radiobutton(cstr txt, i32* state, i32 v, i32 x, i32 y, i32 w, TimStyle
/// text edit - value in state
/// @param e persistent edit state, use TimEditState_construct() to create new state
/// @param color frame, background, text
/// @param style frame, background, text
/// @return key id or 0
TimKey tim_edit(TimEditState* e, i32 x, i32 y, i32 w, TimStyle style);
@@ -291,15 +306,20 @@ TimKey tim_edit(TimEditState* e, i32 x, i32 y, i32 w, TimStyle style);
void TimEditState_construct(TimEditState* e, i32 capacity, cstr initial_content);
static inline void TimEditState_destroy(TimEditState* e) {
if(!e)
return;
if(!e) return;
free(e->s);
}
void TimEditState_insert(TimEditState* e, cstr s);
void TimEditState_delete(TimEditState* e);
/// @param l list of rows to display
/// @param style frame, background, text
TimScrollItem* tim_scroll(TimScrollState* l, i32 x, i32 y, i32 w, i32 h, TimStyle style);
void TimScrollState_selectNext(TimScrollState* l);
void TimScrollState_selectPrev(TimScrollState* l);
#pragma endregion