aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/root.c
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2023-11-25 03:38:40 -0600
committerLibravatar bigfoot547 <[email protected]>2023-11-25 03:38:40 -0600
commit1c9d93cce891d768a75ae1a075ca6e3155a12c73 (patch)
tree8b18a43c48a75f67e88ddd0b3b918e4c6080e043 /src/ui/root.c
parentmake debug code worse-looking (but more verbose) (diff)
add key handling and some other stuff
Diffstat (limited to 'src/ui/root.c')
-rw-r--r--src/ui/root.c81
1 files changed, 71 insertions, 10 deletions
diff --git a/src/ui/root.c b/src/ui/root.c
index 00eda14..6846d45 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -1,6 +1,7 @@
#include "ui.internal.h"
#include "macros.h"
#include "ui/uimenu.internal.h"
+#include <curses.h>
#include <string.h>
#define UI__ROOT_MIN_Y (24)
@@ -51,6 +52,7 @@ void ui__root_draw_proc(struct ui_window_base *base)
ui__root_draw_status(root);
wnoutrefresh(root->cwindow);
+ wnoutrefresh(root->menu_cwindow);
if (root->content) {
ui__call_draw_proc(root->content);
@@ -65,17 +67,18 @@ void ui__root_draw_proc(struct ui_window_base *base)
void ui__root_draw_menu(struct ui_window_root *root)
{
- WINDOW *mywin = root->cwindow;
- attron(A_REVERSE);
- mvwhline(mywin, 0, 0, ' ', getmaxx(mywin));
- mvwaddstr(mywin, 0, 0, " UMPS v0.1.0-dev");
+ wattron(root->menu_cwindow, A_REVERSE);
+ mvwhline(root->menu_cwindow, 0, 0, ' ', getmaxx(root->menu_cwindow));
+ mvwaddstr(root->menu_cwindow, 0, 0, " UMPS v0.1.0-dev");
char *text;
- for (struct uimenu_item_header *item = root->menu_root->head; item; item = item->next) {
- waddstr(mywin, " ");
+ int idx = 0;
+ for (struct uimenu_item_header *item = root->menu_root->head; item; item = item->next, ++idx) {
+ waddstr(root->menu_cwindow, " ");
+
switch (item->type) {
case UMPS__MENU_TYPE_SPACER:
- waddstr(mywin, "--");
+ waddstr(root->menu_cwindow, "--");
continue;
case UMPS__MENU_TYPE_BUTTON:
text = ((struct uimenu_item_button *)item)->text;
@@ -87,11 +90,23 @@ void ui__root_draw_menu(struct ui_window_root *root)
umps_trap;
}
- if (text) waddstr(mywin, text);
- else waddstr(mywin, "???");
+ if (item == root->menu_selected)
+ wattroff(root->menu_cwindow, A_REVERSE);
+
+ if (text) waddstr(root->menu_cwindow, text);
+ else waddstr(root->menu_cwindow, "???");
+
+ wattron(root->menu_cwindow, A_REVERSE);
}
- attroff(A_REVERSE);
+ wattroff(root->menu_cwindow, A_REVERSE);
+}
+
+void ui__root_redraw_menu(struct ui_window_root *root)
+{
+ ui__root_draw_menu(root);
+ wnoutrefresh(root->menu_cwindow);
+ doupdate();
}
void ui__root_draw_status(struct ui_window_root *root)
@@ -117,6 +132,9 @@ void ui__root_layout_proc(struct ui_window_base *base)
root->cwindow = newwin(root->super.dims.maxy, root->super.dims.maxx, root->super.dims.begy, root->super.dims.begx);
}
+ delwin(root->menu_cwindow);
+ root->menu_cwindow = newwin(1, root->super.dims.maxx, 0, 0);
+
if (root->super.dims.maxy < UI__ROOT_MIN_Y || root->super.dims.maxx < UI__ROOT_MIN_X) {
root->undersize_scr = true;
return;
@@ -130,6 +148,49 @@ void ui__root_layout_proc(struct ui_window_base *base)
}
}
+struct ui_window_base *ui__root_control_proc(struct ui_window_base *base, ui_control inp)
+{
+ struct ui_window_root *root = ui__cast(root, base);
+
+ if (root->undersize_scr) return NULL;
+
+ switch (inp) {
+ case NS('h'):
+ ui__status_text = "Hello...";
+ ui__call_draw_proc(ui__cast(base, ui_root));
+ break;
+ case NS('w'):
+ ui__status_text = "World!";
+ ui__call_draw_proc(ui__cast(base, ui_root));
+ break;
+ case NS('m'):
+ if (root->menu_selected) {
+ root->menu_selected = NULL;
+ } else {
+ root->menu_selected = root->menu_root->head;
+ }
+ ui__root_redraw_menu(root);
+ return NULL;
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ if (root->menu_selected) {
+ struct uimenu_item_header *nxt = inp == KEY_RIGHT ? root->menu_selected->next : root->menu_selected->prev;
+ if (nxt) {
+ root->menu_selected = nxt;
+ ui__root_redraw_menu(root);
+ }
+ return NULL;
+ }
+ break;
+ }
+
+ if (root->menu_selected) {
+ return NULL;
+ } else {
+ return root->content;
+ }
+}
+
void ui__root_set_content(struct ui_window_root *root, struct ui_window_base *window)
{
umps_assert(!window->parent);