diff options
| author | aura <nw@moneybot.cc> | 2026-03-04 00:51:18 +0100 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-03-04 00:51:18 +0100 |
| commit | 890bea19359649695df1b618a41ce580cf3dfbda (patch) | |
| tree | 8bc10ae4e613b0ad57fae9a68cec38c7d59cf067 /src/gui/list.cpp | |
| parent | 61aea7311c2e1af78fd9da544499f2198f2da1dd (diff) | |
| parent | be91342733fd56d1e7bafe72e82a8ac4dc67b79d (diff) | |
Merge branch 'ui-rework'
Diffstat (limited to 'src/gui/list.cpp')
| -rw-r--r-- | src/gui/list.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/gui/list.cpp b/src/gui/list.cpp index 90f2f49..2feff47 100644 --- a/src/gui/list.cpp +++ b/src/gui/list.cpp @@ -10,18 +10,33 @@ void gui_list_draw_fn( void* ptr ) { I32 y = gui_rely( list ); gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, list->name ); - y += LIST_TITLE_OFFSET; + I32 panel_y = y + LIST_TITLE_OFFSET; CLR col = gui_is_fg_window( list )? ui_clr.border : ui_clr.border_inactive; - gui_draw_frect( x, y, list->w, list->h, col ); - gui_draw_frect( x+1, y+1, list->w-2, list->h-2, ui_clr.bg_sec ); + gui_draw_frect( x, panel_y, list->w, list->h, col ); + gui_draw_frect( x + 1, panel_y + 1, list->w - 2, list->h - 2, ui_clr.bg_sec ); + + I32 txt_h = 12; + gui_draw_get_str_bounds( 0, &txt_h, FNT_JPN12, "ag" ); I32 yoff = 0; list->plist->each( fn( GUI_LIST_ENTRY* e ) { U8 selected = e->val == *list->pval; - CLR col = selected? ui_clr.txt : ui_clr.txt_inactive; + I32 row_x = x + 1; + I32 row_y = panel_y + 1 + yoff; + I32 row_w = list->w - 2; + if( row_w < 1 ) row_w = 1; + I32 row_h = LIST_ITEM_HEIGHT; + + if( selected ) { + CLR sel_bg = CLR::blend( ui_clr.border, ui_clr.bg, 0.70f ); + gui_draw_frect( row_x, row_y, row_w, row_h, sel_bg ); + } + + CLR col = selected ? ui_clr.txt : ui_clr.txt_inactive; + I32 txt_y = row_y + ( row_h - txt_h ) / 2; - gui_draw_str( x + 4, y + yoff + 6, ALIGN_L, FNT_JPN12, col, e->title ); + gui_draw_str( row_x + 3, txt_y, ALIGN_L, FNT_JPN12, col, e->title ); yoff += LIST_ITEM_HEIGHT; } ); } @@ -31,6 +46,7 @@ void gui_list_input_fn( void* ptr ) { I32 x = gui_relx( list ); I32 y = gui_rely( list ); + I32 panel_y = y + LIST_TITLE_OFFSET; I32 w = list->w; I32 h = list->h; @@ -38,12 +54,12 @@ void gui_list_input_fn( void* ptr ) { I32 mx, my; gui_cursor_pos( &mx, &my ); - U8 inbounds = mx >= x && mx <= x + w && my >= y && my <= y + h; + U8 inbounds = mx >= x && mx <= x + w && my >= panel_y && my <= panel_y + h; if( !inbounds ) return; - I32 diff = my - y; - I32 idx = diff / LIST_ITEM_HEIGHT - 1; + I32 diff = my - panel_y; + I32 idx = diff / LIST_ITEM_HEIGHT; if( idx >= list->plist->size ) idx = list->plist->size - 1; if( idx < 0 ) idx = 0; |
