diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-05-27 18:30:08 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-05-30 09:26:30 +0200 |
commit | 83f11c231626f79433a021c526ffa1ac7521ae36 (patch) | |
tree | 72a3e0cfb3efd9e34455c8ad5d670a2e08900112 /ui.c | |
parent | 90b9483c806f0571988581c1712c7ca236c4a38c (diff) |
flowtop: Improve and unify up/down scrolling
Move scrolling logic to the ui.c module, it requires to have
some data iteration provided in flowtop.c and delegated to ui.c part.
So approach is that now flowtop provides 2 additional callbacks for:
1) Iterate over flows/procs list
2) Draw flow/proc on each iteration which is controlled from ui.c
it allows to unify scrolling logic and delegate it to the ui.c, in the
future it should allow to easy handle press event on selected row and
drow some additional information, or draw a cursor line per selected
row.
Also fixed case when down scrolling was bigger that printed rows, not
it is handled by ui part.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'ui.c')
-rw-r--r-- | ui.c | 70 |
1 files changed, 68 insertions, 2 deletions
@@ -214,13 +214,79 @@ void ui_table_header_print(struct ui_table *tbl) void ui_table_event_send(struct ui_table *tbl, enum ui_event_id evt_id) { - if (evt_id == UI_EVT_SCROLL_RIGHT) { + switch (evt_id) { + case UI_EVT_SCROLL_RIGHT: tbl->scroll_x += SCROLL_X_STEP; - } else if (evt_id == UI_EVT_SCROLL_LEFT) { + break; + + case UI_EVT_SCROLL_LEFT: tbl->scroll_x -= SCROLL_X_STEP; if (tbl->scroll_x < 0) tbl->scroll_x = 0; + break; + + case UI_EVT_SCROLL_UP: + tbl->scroll_y--; + if (tbl->scroll_y < 0) + tbl->scroll_y = 0; + break; + + case UI_EVT_SCROLL_DOWN: + tbl->scroll_y++; + break; + + default: /* pass the rest events */ + return; + } +} + +void ui_table_data_iter_set(struct ui_table *tbl, void * (* iter)(void *data)) +{ + tbl->data_iter = iter; +} + +void ui_table_data_bind_set(struct ui_table *tbl, + void (* bind)(struct ui_table *tbl, const void *data)) +{ + tbl->data_bind = bind; +} + +void ui_table_data_bind(struct ui_table *tbl) +{ + void *data; + int i = 0; + + bug_on(!tbl); + bug_on(!tbl->data_iter); + bug_on(!tbl->data_bind); + + ui_table_clear(tbl); + ui_table_header_print(tbl); + + tbl->data_count = 0; + + data = tbl->data_iter(NULL); + for (; data; data = tbl->data_iter(data)) { + tbl->data_count++; + + if (i++ < tbl->scroll_y) + continue; + + tbl->data_bind(tbl, data); } + + if (tbl->scroll_y > i) + tbl->scroll_y = i; +} + +int ui_table_data_count(struct ui_table *tbl) +{ + return tbl->data_count; +} + +int ui_table_scroll_height(struct ui_table *tbl) +{ + return tbl->scroll_y; } struct ui_tab *ui_tab_create(void) |