diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-06-02 17:03:52 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-06-09 17:44:43 +0200 |
commit | b11f5d0e3cf0cd0aab2a2961803c6b5a44693801 (patch) | |
tree | f940fc4e3c5e0d5ef0630b77d19f8764d710ddc4 | |
parent | 13cf0da8c4e7efbb966444cb7e0964c1a7e8466d (diff) | |
download | nncmpp-b11f5d0e3cf0cd0aab2a2961803c6b5a44693801.tar.gz nncmpp-b11f5d0e3cf0cd0aab2a2961803c6b5a44693801.tar.xz nncmpp-b11f5d0e3cf0cd0aab2a2961803c6b5a44693801.zip |
Factor out app_widget_by_id()
-rw-r--r-- | nncmpp.c | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -2061,14 +2061,19 @@ app_layout_header (void) app_layout_text (header, APP_ATTR (HEADER)); } -static int -app_visible_items_height (void) +static struct widget * +app_widget_by_id (int id) { - struct widget *list = NULL; LIST_FOR_EACH (struct widget, w, g.widgets.head) - if (w->id == WIDGET_LIST) - list = w; + if (w->id == id) + return w; + return NULL; +} +static int +app_visible_items_height (void) +{ + struct widget *list = app_widget_by_id (WIDGET_LIST); hard_assert (list != NULL); // 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) return true; - struct widget *target = NULL; - LIST_FOR_EACH (struct widget, w, g.widgets.head) - if (w->id == g.ui_dragging) - target = w; - + struct widget *target = app_widget_by_id (g.ui_dragging); x -= target->x; y -= target->y; 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, // let's hack around it in this case - struct widget *spectrum = NULL; - LIST_FOR_EACH (struct widget, w, g.widgets.head) - if (w->id == WIDGET_SPECTRUM) - spectrum = w; + struct widget *spectrum = app_widget_by_id (WIDGET_SPECTRUM); if (spectrum) spectrum->on_render (spectrum); |