summaryrefslogtreecommitdiff
path: root/src/main.c
blob: c1a256302504af0154a4d321be0cae461ce7b7b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <unistd.h>

#include "ui/tui.h"

bool is_clicked = false;

void on_button_click(const MOUSE_ACTION *mouse_action) {
  is_clicked = !is_clicked;
}

WIDGET *ui_build(TUI *tui) {
  if (is_clicked) {
    return tui_make_box(
        -1, -1,
        tui_make_column(tui_make_widget_array(
            2, tui_make_box(0, 12, NULL, COLOR_NO_COLOR),
            tui_make_row(tui_make_widget_array(
                2, tui_make_box(50, 0, NULL, COLOR_NO_COLOR),
                tui_make_box(
                    20, 3,
                    tui_make_column(tui_make_widget_array(
                        2, tui_make_text("This is the second page", COLOR_BLUE),
                        tui_make_button(tui_make_text("       Back", COLOR_RED),
                                        on_button_click))),

                    COLOR_WHITE))))),
        COLOR_MAGENTA);
  } else {
    return tui_make_box(
        -1, -1,
        tui_make_column(tui_make_widget_array(
            2, tui_make_box(0, 12, NULL, COLOR_NO_COLOR),
            tui_make_row(tui_make_widget_array(
                2, tui_make_box(50, 0, NULL, COLOR_NO_COLOR),
                tui_make_button(
                    tui_make_box(16, 3,
                                 tui_make_text("\nClick here", COLOR_BLUE),
                                 COLOR_WHITE),
                    on_button_click))))),
        COLOR_MAGENTA);
  }
}

int main() {
  TUI *tui = tui_init();

  tui_start_app(tui, ui_build, 144);

  tui_delete(tui);

  return 0;
}