Kaynağa Gözat

string editing ui

Thomas Buck 5 ay önce
ebeveyn
işleme
8b5ea7054b
2 değiştirilmiş dosya ile 46 ekleme ve 7 silme
  1. 1
    1
      src/mem.c
  2. 45
    6
      src/state_string.c

+ 1
- 1
src/mem.c Dosyayı Görüntüle

@@ -86,7 +86,7 @@ void mem_load_defaults(void) {
86 86
         data_ram.data.wf[i] = wf_default_data[i];
87 87
     }
88 88
 
89
-    // TODO
89
+    // TODO better way to pre-define WiFi credentials
90 90
     data_ram.data.net_count = 1;
91 91
     strcpy(data_ram.data.net[0].name, DEFAULT_WIFI_SSID);
92 92
     strcpy(data_ram.data.net[0].pass, DEFAULT_WIFI_PASS);

+ 45
- 6
src/state_string.c Dosyayı Görüntüle

@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include <stdio.h>
20
+#include <string.h>
20 21
 
21 22
 #include "config.h"
22 23
 #include "buttons.h"
@@ -30,6 +31,7 @@ static char *str_p = NULL;
30 31
 static size_t str_len = 0;
31 32
 static const char *str_name = NULL;
32 33
 static enum system_state str_ret_state = STATE_SCAN;
34
+static size_t edit = 0, offset = 0;
33 35
 
34 36
 void state_string_set(char *value, size_t length,
35 37
                       const char *name) {
@@ -48,32 +50,69 @@ static void draw(void) {
48 50
     if ((str_p == NULL) || (str_len <= 0) || (str_name == NULL)) {
49 51
         snprintf(buff, sizeof(buff), "error");
50 52
     } else {
51
-        snprintf(buff, sizeof(buff), "%s:\n\n%s", str_name, str_p);
53
+        snprintf(buff, sizeof(buff), "%s:\n\n'%s'", str_name, str_p + offset);
52 54
     }
53 55
 
54
-    text_box(buff, true,
56
+    text_box(buff, false,
55 57
              "fixed_10x20",
56 58
              0, LCD_WIDTH,
57 59
              50, MENU_BOX_HEIGHT(MENU_MAX_LINES, 20, 2),
58 60
              0);
61
+
62
+    size_t ch = edit - offset + 1;
63
+    lcd_write_rect(ch * 10,
64
+                   50 + 3 * 22,
65
+                   ch * 10 + 10,
66
+                   50 + 3 * 22 + 3,
67
+                   LCD_WHITE);
59 68
 }
60 69
 
61 70
 static void string_buttons(enum buttons btn, bool state) {
62 71
     if (state && (btn == BTN_Y)) {
63 72
         state_switch(str_ret_state);
64 73
     } else if (state && (btn == BTN_LEFT)) {
65
-        // TODO
74
+        if (edit > 0) {
75
+            edit--;
76
+        }
66 77
     } else if (state && (btn == BTN_RIGHT)) {
67
-        // TODO
78
+        if (edit < (str_len - 1)) {
79
+            edit++;
80
+        }
81
+        size_t l = strlen(str_p);
82
+        while (edit >= l) {
83
+            str_p[l++] = ' ';
84
+        }
68 85
     } else if (state && (btn == BTN_UP)) {
69
-        // TODO
86
+        char *c = str_p + edit;
87
+        if ((*c >= ' ') && (*c < '~')) {
88
+            (*c)++;
89
+        }
70 90
     } else if (state && (btn == BTN_DOWN)) {
71
-        // TODO
91
+        char *c = str_p + edit;
92
+        if ((*c > ' ') && (*c <= '~')) {
93
+            (*c)--;
94
+        }
95
+    } else if (state && (btn == BTN_B)) {
96
+        char *c = str_p + edit;
97
+        *c = '\0';
98
+    } else {
99
+        return;
100
+    }
101
+
102
+    while (edit < offset) {
103
+        offset -= 1;
72 104
     }
105
+    while (edit >= (offset + (LCD_WIDTH / 10 - 2))) {
106
+        offset += 1;
107
+    }
108
+
109
+    draw();
73 110
 }
74 111
 
75 112
 void state_string_enter(void) {
76 113
     buttons_callback(string_buttons);
114
+    edit = 0;
115
+    offset = 0;
77 116
     draw();
78 117
 }
79 118
 

Loading…
İptal
Kaydet