Factor out app_widget_by_id()

This commit is contained in:
Přemysl Eric Janouch 2023-06-02 17:03:52 +02:00
parent 13cf0da8c4
commit b11f5d0e3c
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 12 additions and 14 deletions

View File

@ -2061,14 +2061,19 @@ app_layout_header (void)
app_layout_text (header, APP_ATTR (HEADER)); app_layout_text (header, APP_ATTR (HEADER));
} }
static struct widget *
app_widget_by_id (int id)
{
LIST_FOR_EACH (struct widget, w, g.widgets.head)
if (w->id == id)
return w;
return NULL;
}
static int static int
app_visible_items_height (void) app_visible_items_height (void)
{ {
struct widget *list = NULL; struct widget *list = app_widget_by_id (WIDGET_LIST);
LIST_FOR_EACH (struct widget, w, g.widgets.head)
if (w->id == WIDGET_LIST)
list = w;
hard_assert (list != NULL); hard_assert (list != NULL);
// The raw number of items that would have fit on the terminal // The raw number of items that would have fit on the terminal
@ -2948,11 +2953,7 @@ app_process_mouse (termo_mouse_event_t type, int x, int y, int button,
&& g.ui_dragging != WIDGET_SCROLLBAR) && g.ui_dragging != WIDGET_SCROLLBAR)
return true; return true;
struct widget *target = NULL; struct widget *target = app_widget_by_id (g.ui_dragging);
LIST_FOR_EACH (struct widget, w, g.widgets.head)
if (w->id == g.ui_dragging)
target = w;
x -= target->x; x -= target->x;
y -= target->y; y -= target->y;
return app_process_left_mouse_click (target, x, y, modifiers); return app_process_left_mouse_click (target, x, y, modifiers);
@ -4824,10 +4825,7 @@ spectrum_redraw (void)
{ {
// A full refresh would be too computationally expensive, // A full refresh would be too computationally expensive,
// let's hack around it in this case // let's hack around it in this case
struct widget *spectrum = NULL; struct widget *spectrum = app_widget_by_id (WIDGET_SPECTRUM);
LIST_FOR_EACH (struct widget, w, g.widgets.head)
if (w->id == WIDGET_SPECTRUM)
spectrum = w;
if (spectrum) if (spectrum)
spectrum->on_render (spectrum); spectrum->on_render (spectrum);