Browse Source

text box alignment

Thomas Buck 6 months ago
parent
commit
a13aa6581c
8 changed files with 14 additions and 12 deletions
  1. 3
    1
      include/menu.h
  2. 1
    1
      include/text.h
  3. 2
    2
      src/menu.c
  4. 1
    1
      src/state_crafty.c
  5. 1
    1
      src/state_scan.c
  6. 1
    1
      src/state_volcano_run.c
  7. 1
    1
      src/state_volcano_workflow.c
  8. 4
    4
      src/text.c

+ 3
- 1
include/menu.h View File

@@ -19,6 +19,8 @@
19 19
 #ifndef __MENU_H__
20 20
 #define __MENU_H__
21 21
 
22
+#include <stdbool.h>
23
+
22 24
 #define MENU_MAX_LINES 5
23 25
 #define MENU_MAX_LEN (MENU_MAX_LINES * 32)
24 26
 
@@ -32,6 +34,6 @@ struct menu_state {
32 34
 void menu_init(void (*enter)(int), void (*exit)(void));
33 35
 void menu_deinit(void);
34 36
 
35
-void menu_run(void (*cb)(struct menu_state *));
37
+void menu_run(void (*cb)(struct menu_state *), bool centered);
36 38
 
37 39
 #endif // __MENU_H__

+ 1
- 1
include/text.h View File

@@ -48,6 +48,6 @@ struct text_conf {
48 48
 void text_prepare_font(struct text_font *tf);
49 49
 void text_draw(struct text_conf *tc);
50 50
 
51
-void text_box(const char *s);
51
+void text_box(const char *s, bool centered);
52 52
 
53 53
 #endif // __TEXT_H__

+ 2
- 2
src/menu.c View File

@@ -102,13 +102,13 @@ void menu_deinit(void) {
102 102
     buttons_callback(NULL);
103 103
 }
104 104
 
105
-void menu_run(void (*draw)(struct menu_state *)) {
105
+void menu_run(void (*draw)(struct menu_state *), bool centered) {
106 106
     if (draw) {
107 107
         draw(&menu);
108 108
     }
109 109
 
110 110
     if (strncmp(buff, prev_buff, MENU_MAX_LEN) != 0) {
111 111
         strncpy(prev_buff, buff, MENU_MAX_LEN);
112
-        text_box(buff);
112
+        text_box(buff, centered);
113 113
     }
114 114
 }

+ 1
- 1
src/state_crafty.c View File

@@ -116,7 +116,7 @@ void state_crafty_run(void) {
116 116
     uint32_t now = to_ms_since_boot(get_absolute_time());
117 117
     if (((now - last) >= CRAFTY_UPDATE_TIME_MS) || (last == 0)) {
118 118
         last = now;
119
-        menu_run(draw);
119
+        menu_run(draw, true);
120 120
     }
121 121
 
122 122
     if (wait_for_disconnect && !ble_is_connected()) {

+ 1
- 1
src/state_scan.c View File

@@ -128,5 +128,5 @@ static void draw(struct menu_state *menu) {
128 128
 }
129 129
 
130 130
 void state_scan_run(void) {
131
-    menu_run(draw);
131
+    menu_run(draw, false);
132 132
 }

+ 1
- 1
src/state_volcano_run.c View File

@@ -136,7 +136,7 @@ void state_volcano_run_run(void) {
136 136
     }
137 137
 
138 138
     // visualize workflow status
139
-    menu_run(draw);
139
+    menu_run(draw, true);
140 140
 
141 141
     // auto disconnect when end of workflow is reached
142 142
     if ((!wait_for_connect) && (!aborted)) {

+ 1
- 1
src/state_volcano_workflow.c View File

@@ -74,5 +74,5 @@ static void draw(struct menu_state *menu) {
74 74
 }
75 75
 
76 76
 void state_volcano_wf_run(void) {
77
-    menu_run(draw);
77
+    menu_run(draw, false);
78 78
 }

+ 4
- 4
src/text.c View File

@@ -152,7 +152,7 @@ void text_draw(struct text_conf *tc) {
152 152
                 tc->text, line_callback, &state);
153 153
 }
154 154
 
155
-void text_box(const char *s) {
155
+void text_box(const char *s, bool centered) {
156 156
     static struct text_font font = {
157 157
         .fontname = "fixed_10x20",
158 158
         .font = NULL,
@@ -172,9 +172,9 @@ void text_box(const char *s) {
172 172
         .x = x,
173 173
         .y = y,
174 174
         .justify = false,
175
-        .alignment = MF_ALIGN_CENTER,
176
-        .width = width,
177
-        .height = height,
175
+        .alignment = centered ? MF_ALIGN_CENTER : MF_ALIGN_LEFT,
176
+        .width = width - 4,
177
+        .height = height - 4,
178 178
         .margin = 2,
179 179
         .fg = RGB_565(0xFF, 0xFF, 0xFF),
180 180
         .bg = RGB_565(0x00, 0x00, 0x00),

Loading…
Cancel
Save