Skip to content

Commit f7ab75a

Browse files
committed
Refactor checklist plugin
The select widget is no longer just a simple selection from a list of items. It is a list of widgets that can be scrolled through. Signed-off-by: Alexey Gladkov <legion@kernel.org>
1 parent d6f6246 commit f7ab75a

11 files changed

Lines changed: 558 additions & 218 deletions

Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ COMMON_SRC = src/ipc.c src/request.c src/plugin.c src/dump.c \
5353
src/widget_hscroll.c \
5454
src/widget_input.c \
5555
src/widget_label.c \
56+
src/widget_list_vbox.c \
5657
src/widget_meter.c \
5758
src/widget_pad_box.c \
5859
src/widget_scroll_vbox.c \

src/macros.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
4141
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
4242

43+
#ifndef CLAMP
44+
#define CLAMP(x, lo, hi) ((x) < (lo) ? (lo) : ((x) > (hi) ? (hi) : (x)))
45+
#endif
46+
4347
#include <string.h>
4448

4549
#define streq(a, b) (strcmp((a), (b)) == 0)

src/plugins/checklist-main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ static struct widget *p_checklist_create(struct request *req)
6767

6868
for (size_t i = 0; i < p->num_kv; i++) {
6969
if (streq(p->kv[i].key, "option")) {
70-
wchar_t *opt = req_get_kv_wchars(p->kv + i);
71-
make_select_option(select, opt);
72-
free(opt);
70+
wchar_t *txt = req_get_kv_wchars(p->kv + i);
71+
struct widget *option = make_select_option(txt, false, (maxsel > 1));
72+
free(txt);
73+
widget_add(select, option);
7374
}
7475
}
7576

src/widget.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const char *widget_type(struct widget *w)
115115
[WIDGET_VBOX] = "vbox",
116116
[WIDGET_HBOX] = "hbox",
117117
[WIDGET_TOOLTIP] = "tooltip",
118+
[WIDGET_LIST_VBOX] = "list_vbox",
118119
[WIDGET_SELECT] = "select",
119120
[WIDGET_SELECT_OPT] = "select_option",
120121
[WIDGET_SPINBOX] = "spinbox",

src/widget.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enum widget_type {
7979
WIDGET_VBOX,
8080
WIDGET_HBOX,
8181
WIDGET_TOOLTIP,
82+
WIDGET_LIST_VBOX,
8283
WIDGET_SELECT,
8384
WIDGET_SELECT_OPT,
8485
WIDGET_SPINBOX,
@@ -117,8 +118,10 @@ enum widget_property {
117118
struct widget_border;
118119
struct widget_button;
119120
struct widget_checkbox;
121+
struct widget_hscroll;
120122
struct widget_input;
121123
struct widget_label;
124+
struct widget_list_vbox;
122125
struct widget_meter;
123126
struct widget_pad_box;
124127
struct widget_select;
@@ -127,7 +130,6 @@ struct widget_svbox;
127130
struct widget_textview;
128131
struct widget_tooltip;
129132
struct widget_vscroll;
130-
struct widget_hscroll;
131133

132134
enum widget_flags {
133135
FLAG_NONE = 0, // Nothing has been set
@@ -216,20 +218,21 @@ struct widget {
216218

217219
/* Widget-specific state */
218220
union {
219-
struct widget_border *border;
220-
struct widget_button *button;
221-
struct widget_checkbox *checkbox;
222-
struct widget_input *input;
223-
struct widget_label *label;
224-
struct widget_meter *meter;
225-
struct widget_pad_box *pad_box;
226-
struct widget_select *select;
227-
struct widget_spinbox *spinbox;
228-
struct widget_svbox *svbox;
229-
struct widget_textview *textview;
230-
struct widget_tooltip *tooltip;
231-
struct widget_vscroll *vscroll;
232-
struct widget_hscroll *hscroll;
221+
struct widget_border *border;
222+
struct widget_button *button;
223+
struct widget_checkbox *checkbox;
224+
struct widget_hscroll *hscroll;
225+
struct widget_input *input;
226+
struct widget_label *label;
227+
struct widget_list_vbox *list_vbox;
228+
struct widget_meter *meter;
229+
struct widget_pad_box *pad_box;
230+
struct widget_select *select;
231+
struct widget_spinbox *spinbox;
232+
struct widget_svbox *svbox;
233+
struct widget_textview *textview;
234+
struct widget_tooltip *tooltip;
235+
struct widget_vscroll *vscroll;
233236
} state;
234237

235238
/*
@@ -292,10 +295,10 @@ struct widget *make_input_password(const wchar_t *initdata, const wchar_t *place
292295
struct widget *make_meter(int total);
293296
struct widget *make_tooltip(const wchar_t *line);
294297
struct widget *make_spinbox(int min, int max, int step, int initial, int width);
298+
struct widget *make_list_vbox(int view_rows);
295299

296300
struct widget *make_select(int max_selected, int view_rows);
297-
bool make_select_option(struct widget *select, const wchar_t *item);
298-
struct widget *make_select_opt(const wchar_t *text, bool checked, bool is_radio);
301+
struct widget *make_select_option(const wchar_t *text, bool checked, bool is_radio);
299302

300303
struct widget *make_border(void);
301304
struct widget *make_border_vbox(struct widget *parent);

0 commit comments

Comments
 (0)