|
|
@@ -27,6 +27,7 @@
|
|
|
#define THEME_H 140
|
|
|
#define ICONS_H 100
|
|
|
#define BUTTONS_H 140
|
|
|
+#define TABS_H 166
|
|
|
#define INPUTS_H 440
|
|
|
#define SCROLL_H 220
|
|
|
#define LAYOUT_H 190
|
|
|
@@ -41,6 +42,7 @@ enum section {
|
|
|
SEC_THEME,
|
|
|
SEC_ICONS,
|
|
|
SEC_BUTTONS,
|
|
|
+ SEC_TABS,
|
|
|
SEC_INPUTS,
|
|
|
SEC_SCROLL,
|
|
|
SEC_LAYOUT,
|
|
|
@@ -67,6 +69,7 @@ enum {
|
|
|
ID_IN_TEXTAREA,
|
|
|
ID_BTN_RESET_FIELDS,
|
|
|
ID_BTN_FILE_DIALOG,
|
|
|
+ ID_BTN_TAB_FRESH,
|
|
|
|
|
|
ID_NAV_BASE = 0x100,
|
|
|
ID_ICON_BASE = 0x200
|
|
|
@@ -74,12 +77,12 @@ enum {
|
|
|
|
|
|
static const int sec_card_h[SEC_COUNT] = {
|
|
|
TYPO_H, SHAPES_H, THEME_H, ICONS_H,
|
|
|
- BUTTONS_H, INPUTS_H, SCROLL_H, LAYOUT_H, CURSORS_H
|
|
|
+ BUTTONS_H, TABS_H, INPUTS_H, SCROLL_H, LAYOUT_H, CURSORS_H
|
|
|
};
|
|
|
|
|
|
static const char *const sec_titles[SEC_COUNT] = {
|
|
|
"Text", "Shapes", "Theme", "Icons",
|
|
|
- "Buttons", "Inputs", "Scroll", "Layout", "Cursors"
|
|
|
+ "Buttons", "Tabs", "Inputs", "Scroll", "Layout", "Cursors"
|
|
|
};
|
|
|
|
|
|
static const char *const sec_descs[SEC_COUNT] = {
|
|
|
@@ -88,6 +91,7 @@ static const char *const sec_descs[SEC_COUNT] = {
|
|
|
"the ngui_theme_dark palette",
|
|
|
"every Adwaita symbolic icon",
|
|
|
"buttons and icon buttons",
|
|
|
+ "horizontal tab strips and fresh-output dots",
|
|
|
"single-line fields, the text area and file dialog",
|
|
|
"a nested draggable scroll pane",
|
|
|
"ngui_cut_* layout helpers",
|
|
|
@@ -131,6 +135,22 @@ static char event_text[96];
|
|
|
static char input_feedback[160];
|
|
|
static int quit;
|
|
|
|
|
|
+/* Live ngui_tabs demo: four tabs, one marked with unseen output. */
|
|
|
+static struct ngui_tabs demo_tabs;
|
|
|
+static struct ngui_tab demo_tab_list[4] = {
|
|
|
+ { "Overview", 0 },
|
|
|
+ { "Activity", 1 },
|
|
|
+ { "Members", 0 },
|
|
|
+ { "Settings", 0 },
|
|
|
+};
|
|
|
+
|
|
|
+static const char *const demo_tab_bodies[4] = {
|
|
|
+ "The active tab fills its background and underlines in the accent colour.",
|
|
|
+ "The dot marks a hidden tab that received new output; clicking clears it.",
|
|
|
+ "ngui_tabs() returns 1 when the user clicks a different tab.",
|
|
|
+ "The caller owns the selection, content and fresh flags.",
|
|
|
+};
|
|
|
+
|
|
|
/* ---- tiny freestanding string helpers ---- */
|
|
|
|
|
|
static unsigned int s_len(const char *s)
|
|
|
@@ -782,6 +802,63 @@ static void draw_buttons(struct ngui *g, struct ngui_rect card)
|
|
|
g->theme.border);
|
|
|
}
|
|
|
|
|
|
+static void draw_tabs_demo(struct ngui *g, struct ngui_rect card)
|
|
|
+{
|
|
|
+ int x = card.x + CARD_PAD;
|
|
|
+ int y = card.y + 12;
|
|
|
+ int w = card.w - 2 * CARD_PAD;
|
|
|
+ struct ngui_rect strip, panel;
|
|
|
+
|
|
|
+ ngui_text_ellipsis(g, rect_make(x, y, w, 16), x, y,
|
|
|
+ "ngui_tabs - click a tab; the dot marks unseen output.",
|
|
|
+ g->theme.text_dim);
|
|
|
+ y += 22;
|
|
|
+
|
|
|
+ strip = rect_make(x, y, w, 28);
|
|
|
+ ngui_fill_rect(g, strip, g->theme.panel);
|
|
|
+ ngui_fill_rect(g, rect_make(strip.x, strip.y + strip.h - 1,
|
|
|
+ strip.w, 1), g->theme.border);
|
|
|
+ if (rect_visible(g, strip) &&
|
|
|
+ ngui_tabs(g, &demo_tabs, rect_make(x + 4, y + 2, w - 8, 24),
|
|
|
+ demo_tab_list, 4)) {
|
|
|
+ char b[64];
|
|
|
+ unsigned int n = 0;
|
|
|
+
|
|
|
+ demo_tab_list[demo_tabs.active].fresh = 0;
|
|
|
+ s_append(b, &n, "tabs: switched to ", sizeof(b));
|
|
|
+ s_append(b, &n, demo_tab_list[demo_tabs.active].label,
|
|
|
+ sizeof(b));
|
|
|
+ event_set(b);
|
|
|
+ }
|
|
|
+ y += 28 + 10;
|
|
|
+
|
|
|
+ panel = rect_make(x, y, w, 48);
|
|
|
+ ngui_fill_round_rect(g, panel, 6, 6, 6, 6, g->theme.panel_alt);
|
|
|
+ ngui_text(g, panel.x + 12, panel.y + 9,
|
|
|
+ demo_tab_list[demo_tabs.active].label, g->theme.text);
|
|
|
+ ngui_text_ellipsis(g, rect_make(panel.x + 12, panel.y + 28,
|
|
|
+ panel.w - 24, 16),
|
|
|
+ panel.x + 12, panel.y + 28,
|
|
|
+ demo_tab_bodies[demo_tabs.active],
|
|
|
+ g->theme.text_dim);
|
|
|
+ y += 48 + 10;
|
|
|
+
|
|
|
+ if (gallery_button(g, ID_BTN_TAB_FRESH, rect_make(x, y, 170, 26),
|
|
|
+ "Mark a tab as unseen")) {
|
|
|
+ int mark = (demo_tabs.active + 1) % 4;
|
|
|
+
|
|
|
+ demo_tab_list[mark].fresh = 1;
|
|
|
+ event_set("tabs: the next tab now shows an unseen dot");
|
|
|
+ ngui_invalidate(g);
|
|
|
+ }
|
|
|
+ if (w > 380)
|
|
|
+ ngui_text_ellipsis(g,
|
|
|
+ rect_make(x + 182, y + 5, w - 182, 16),
|
|
|
+ x + 182, y + 5,
|
|
|
+ "ngui_tabs() handles press/release and returns 1 on a change.",
|
|
|
+ g->theme.text_dim);
|
|
|
+}
|
|
|
+
|
|
|
static void area_reset(void)
|
|
|
{
|
|
|
static const char demo[] =
|
|
|
@@ -1239,6 +1316,9 @@ static void draw_body(struct ngui *g, struct ngui_rect body)
|
|
|
case SEC_BUTTONS:
|
|
|
draw_buttons(g, card);
|
|
|
break;
|
|
|
+ case SEC_TABS:
|
|
|
+ draw_tabs_demo(g, card);
|
|
|
+ break;
|
|
|
case SEC_INPUTS:
|
|
|
draw_inputs(g, card);
|
|
|
break;
|