Browse Source

text box alignment

Thomas Buck 1 year 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
 #ifndef __MENU_H__
19
 #ifndef __MENU_H__
20
 #define __MENU_H__
20
 #define __MENU_H__
21
 
21
 
22
+#include <stdbool.h>
23
+
22
 #define MENU_MAX_LINES 5
24
 #define MENU_MAX_LINES 5
23
 #define MENU_MAX_LEN (MENU_MAX_LINES * 32)
25
 #define MENU_MAX_LEN (MENU_MAX_LINES * 32)
24
 
26
 
32
 void menu_init(void (*enter)(int), void (*exit)(void));
34
 void menu_init(void (*enter)(int), void (*exit)(void));
33
 void menu_deinit(void);
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
 #endif // __MENU_H__
39
 #endif // __MENU_H__

+ 1
- 1
include/text.h View File

48
 void text_prepare_font(struct text_font *tf);
48
 void text_prepare_font(struct text_font *tf);
49
 void text_draw(struct text_conf *tc);
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
 #endif // __TEXT_H__
53
 #endif // __TEXT_H__

+ 2
- 2
src/menu.c View File

102
     buttons_callback(NULL);
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
     if (draw) {
106
     if (draw) {
107
         draw(&menu);
107
         draw(&menu);
108
     }
108
     }
109
 
109
 
110
     if (strncmp(buff, prev_buff, MENU_MAX_LEN) != 0) {
110
     if (strncmp(buff, prev_buff, MENU_MAX_LEN) != 0) {
111
         strncpy(prev_buff, buff, MENU_MAX_LEN);
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
     uint32_t now = to_ms_since_boot(get_absolute_time());
116
     uint32_t now = to_ms_since_boot(get_absolute_time());
117
     if (((now - last) >= CRAFTY_UPDATE_TIME_MS) || (last == 0)) {
117
     if (((now - last) >= CRAFTY_UPDATE_TIME_MS) || (last == 0)) {
118
         last = now;
118
         last = now;
119
-        menu_run(draw);
119
+        menu_run(draw, true);
120
     }
120
     }
121
 
121
 
122
     if (wait_for_disconnect && !ble_is_connected()) {
122
     if (wait_for_disconnect && !ble_is_connected()) {

+ 1
- 1
src/state_scan.c View File

128
 }
128
 }
129
 
129
 
130
 void state_scan_run(void) {
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
     }
136
     }
137
 
137
 
138
     // visualize workflow status
138
     // visualize workflow status
139
-    menu_run(draw);
139
+    menu_run(draw, true);
140
 
140
 
141
     // auto disconnect when end of workflow is reached
141
     // auto disconnect when end of workflow is reached
142
     if ((!wait_for_connect) && (!aborted)) {
142
     if ((!wait_for_connect) && (!aborted)) {

+ 1
- 1
src/state_volcano_workflow.c View File

74
 }
74
 }
75
 
75
 
76
 void state_volcano_wf_run(void) {
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
                 tc->text, line_callback, &state);
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
     static struct text_font font = {
156
     static struct text_font font = {
157
         .fontname = "fixed_10x20",
157
         .fontname = "fixed_10x20",
158
         .font = NULL,
158
         .font = NULL,
172
         .x = x,
172
         .x = x,
173
         .y = y,
173
         .y = y,
174
         .justify = false,
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
         .margin = 2,
178
         .margin = 2,
179
         .fg = RGB_565(0xFF, 0xFF, 0xFF),
179
         .fg = RGB_565(0xFF, 0xFF, 0xFF),
180
         .bg = RGB_565(0x00, 0x00, 0x00),
180
         .bg = RGB_565(0x00, 0x00, 0x00),

Loading…
Cancel
Save