two separate controls - panel and scroll_view

This commit is contained in:
2026-01-16 17:45:34 +05:00
parent f4ed55a495
commit cbd1cc0cf1
5 changed files with 199 additions and 133 deletions

View File

@@ -170,22 +170,31 @@ typedef struct TimEditState {
} TimEditState;
typedef struct TimScrollItem {
void* data;
typedef struct TimPanelItem {
// Size of item to know where to draw next item.
// Set to to A and items will be spread equally across panel
i32 w;
i32 h;
void* data; // is passed to draw()
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;
void (*draw)(void* data, TimRect place, bool is_selected);
} TimPanelItem;
typedef struct TimScrollState {
TimScrollItem* items;
i32 len;
i32 cur;
typedef struct TimPanel {
TimPanelItem* items; // array
i32 len; // number of items
i32 cur; // index of current item
i32 spacing; // distance between items
bool draw_border;
bool show_scroll_bar_vertical;
bool use_mouse_wheel;
} TimScrollState;
bool is_horizontal;
} TimPanel;
typedef struct TimScrollView {
i32 offset;
i32 content_h;
void* data; // is passed to draw()
void (*draw)(void* data, TimRect place);
} TimScrollView;
typedef struct TimState {
i32 w; // screen width
@@ -308,6 +317,7 @@ bool tim_checkbox(cstr txt, i32* state, i32 x, i32 y, i32 w, TimStyle style);
// color: radio, background, text
bool tim_radiobutton(cstr txt, i32* state, i32 v, i32 x, i32 y, i32 w, TimStyle style);
/// text edit - value in state
/// @param e persistent edit state, use TimEditState_construct() to create new state
/// @param style frame, background, text
@@ -319,16 +329,22 @@ TimKey tim_edit(TimEditState* e, i32 x, i32 y, i32 w, TimStyle style);
/// @param capacity buffer size in bytes
/// @param initial_content may be NULL
void TimEditState_construct(TimEditState* e, char* buffer, i32 capacity, cstr initial_content);
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);
/// Panel with sequence of items. You can select an item by arrow keys or mouse click.
/// @param self persistent state
/// @param is_selected if panel is not selected, it calls items[:]->draw(is_selected=false)
/// @param style frame, background, text
/// @return current item
TimPanelItem* tim_panel(TimPanel* self, bool is_selected, i32 x, i32 y, i32 w, i32 h, TimStyle style);
void TimPanel_selectNext(TimPanel* self);
void TimPanel_selectPrev(TimPanel* self);
///
void tim_scroll_view(TimScrollView* self, i32 x, i32 y, i32 w, i32 h, TimStyle style);
#pragma endregion