Skip to content

Commit 83e836f

Browse files
committed
Dark Mode & Wii Menu
1 parent b96c445 commit 83e836f

File tree

12 files changed

+315
-102
lines changed

12 files changed

+315
-102
lines changed

applications/main/archive/views/archive_browser_view.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
327327
((scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX) - x_offset),
328328
str_buf,
329329
scroll_counter,
330-
(model->item_idx != idx));
330+
(model->item_idx != idx),
331+
false
332+
);
331333

332334
furi_string_free(str_buf);
333335
}

applications/main/subghz/views/receiver.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
269269
(scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX),
270270
str_buff,
271271
scroll_counter,
272-
(model->idx != idx));
272+
(model->idx != idx),
273+
false
274+
);
273275
furi_string_reset(str_buff);
274276
}
275277
if(scrollbar) {

applications/services/gui/canvas.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <furi_hal_rtc.h>
88
#include <stdint.h>
99
#include <u8g2_glue.h>
10+
#include <cfw.h>
1011

1112
const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
1213
[FontPrimary] = {.leading_default = 12, .leading_min = 11, .height = 8, .descender = 2},
@@ -108,11 +109,22 @@ const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font fo
108109

109110
void canvas_clear(Canvas* canvas) {
110111
furi_assert(canvas);
111-
u8g2_ClearBuffer(&canvas->fb);
112+
if(CFW_SETTINGS()->dark_mode) {
113+
u8g2_FillBuffer(&canvas->fb);
114+
} else {
115+
u8g2_ClearBuffer(&canvas->fb);
116+
}
112117
}
113118

114119
void canvas_set_color(Canvas* canvas, Color color) {
115120
furi_assert(canvas);
121+
if(CFW_SETTINGS()->dark_mode) {
122+
if(color == ColorBlack) {
123+
color = ColorWhite;
124+
} else if(color == ColorWhite) {
125+
color = ColorBlack;
126+
}
127+
}
116128
u8g2_SetDrawColor(&canvas->fb, color);
117129
}
118130

@@ -128,18 +140,25 @@ void canvas_invert_color(Canvas* canvas) {
128140
void canvas_set_font(Canvas* canvas, Font font) {
129141
furi_assert(canvas);
130142
u8g2_SetFontMode(&canvas->fb, 1);
131-
if(font == FontPrimary) {
143+
switch(font) {
144+
case FontPrimary:
132145
u8g2_SetFont(&canvas->fb, u8g2_font_helvB08_tr);
133-
} else if(font == FontSecondary) {
146+
break;
147+
case FontSecondary:
134148
u8g2_SetFont(&canvas->fb, u8g2_font_haxrcorp4089_tr);
135-
} else if(font == FontKeyboard) {
149+
break;
150+
case FontKeyboard:
136151
u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mr);
137-
} else if(font == FontBigNumbers) {
152+
break;
153+
case FontBigNumbers:
138154
u8g2_SetFont(&canvas->fb, u8g2_font_profont22_tn);
139-
} else if(font == FontBatteryPercent) {
155+
break;
156+
case FontBatteryPercent:
140157
u8g2_SetFont(&canvas->fb, u8g2_font_5x7_tf); //u8g2_font_micro_tr);
141-
} else {
158+
break;
159+
default:
142160
furi_crash(NULL);
161+
break;
143162
}
144163
}
145164

applications/services/gui/elements.c

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -638,44 +638,10 @@ void elements_scrollable_text_line(
638638
uint8_t width,
639639
FuriString* string,
640640
size_t scroll,
641-
bool ellipsis) {
642-
FuriString* line = furi_string_alloc_set(string);
643-
644-
size_t len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
645-
if(len_px > width) {
646-
if(ellipsis) {
647-
width -= canvas_string_width(canvas, "...");
648-
}
649-
650-
// Calculate scroll size
651-
size_t scroll_size = furi_string_size(line);
652-
size_t right_width = 0;
653-
for(size_t i = scroll_size; i > 0; i--) {
654-
right_width += canvas_glyph_width(canvas, furi_string_get_char(line, i));
655-
if(right_width > width) break;
656-
scroll_size--;
657-
if(!scroll_size) break;
658-
}
659-
// Ensure that we have something to scroll
660-
if(scroll_size) {
661-
scroll_size += 3;
662-
scroll = scroll % scroll_size;
663-
furi_string_right(line, scroll);
664-
}
665-
666-
len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
667-
while(len_px > width) {
668-
furi_string_left(line, furi_string_size(line) - 1);
669-
len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
670-
}
671-
672-
if(ellipsis) {
673-
furi_string_cat(line, "...");
674-
}
675-
}
676-
677-
canvas_draw_str(canvas, x, y, furi_string_get_cstr(line));
678-
furi_string_free(line);
641+
bool ellipsis,
642+
bool centered) {
643+
elements_scrollable_text_line_str(
644+
canvas, x, y, width, furi_string_get_cstr(string), scroll, ellipsis, centered);
679645
}
680646

681647
void elements_text_box(

applications/services/gui/elements.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,23 @@ void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width
218218
* @param string The string
219219
* @param[in] scroll The scroll counter: 0 - no scroll, any other number - scroll. Just count up, everything else will be calculated on the inside.
220220
* @param[in] ellipsis The ellipsis flag: true to add ellipse
221+
* @param[in] centered The centered flag: true to center text on x and y
221222
*/
222-
void elements_scrollable_text_line(
223+
void elements_scrollable_text_line_str(
223224
Canvas* canvas,
224225
uint8_t x,
225226
uint8_t y,
226227
uint8_t width,
227-
FuriString* string,
228+
const char* string,
228229
size_t scroll,
229-
bool ellipsis);
230-
231-
void elements_scrollable_text_line_str(
230+
bool ellipsis,
231+
bool centered);
232+
void elements_scrollable_text_line(
232233
Canvas* canvas,
233234
uint8_t x,
234235
uint8_t y,
235236
uint8_t width,
236-
const char* string,
237+
FuriString* string,
237238
size_t scroll,
238239
bool ellipsis,
239240
bool centered);

applications/services/gui/modules/byte_input.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ typedef struct {
1717
typedef struct {
1818
const char* header;
1919
uint8_t* bytes;
20-
uint16_t bytes_count;
20+
uint8_t bytes_count;
2121

2222
ByteInputCallback input_callback;
2323
ByteChangedCallback changed_callback;
2424
void* callback_context;
2525

2626
bool selected_high_nibble;
27-
uint16_t selected_byte;
27+
uint8_t selected_byte;
2828
int8_t selected_row; // row -1 - input, row 0 & 1 - keyboard
2929
uint8_t selected_column;
30-
uint16_t first_visible_byte;
30+
uint8_t first_visible_byte;
3131
} ByteInputModel;
3232

3333
static const uint8_t keyboard_origin_x = 7;
@@ -164,7 +164,7 @@ static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) {
164164
canvas_draw_icon(canvas, 2, 19, &I_ButtonLeftSmall_3x5);
165165
canvas_draw_icon(canvas, 123, 19, &I_ButtonRightSmall_3x5);
166166

167-
for(uint16_t i = model->first_visible_byte;
167+
for(uint8_t i = model->first_visible_byte;
168168
i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
169169
i++) {
170170
uint8_t byte_position = i - model->first_visible_byte;
@@ -253,7 +253,7 @@ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model
253253
canvas_draw_icon(canvas, 2, 19, &I_ButtonLeftSmall_3x5);
254254
canvas_draw_icon(canvas, 122, 19, &I_ButtonRightSmall_3x5);
255255

256-
for(uint16_t i = model->first_visible_byte;
256+
for(uint8_t i = model->first_visible_byte;
257257
i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
258258
i++) {
259259
uint8_t byte_position = i - model->first_visible_byte;
@@ -305,7 +305,7 @@ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model
305305
* @param value char value
306306
* @param high_nibble set high nibble
307307
*/
308-
static void byte_input_set_nibble(uint8_t* data, uint16_t position, char value, bool high_nibble) {
308+
static void byte_input_set_nibble(uint8_t* data, uint8_t position, char value, bool high_nibble) {
309309
switch(value) {
310310
case '0':
311311
case '1':
@@ -750,7 +750,7 @@ void byte_input_set_result_callback(
750750
ByteChangedCallback changed_callback,
751751
void* callback_context,
752752
uint8_t* bytes,
753-
uint16_t bytes_count) {
753+
uint8_t bytes_count) {
754754
with_view_model(
755755
byte_input->view,
756756
ByteInputModel * model,

applications/services/gui/modules/byte_input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void byte_input_set_result_callback(
5555
ByteChangedCallback changed_callback,
5656
void* callback_context,
5757
uint8_t* bytes,
58-
uint16_t bytes_count);
58+
uint8_t bytes_count);
5959

6060
/** Set byte input header text
6161
*

applications/services/gui/modules/file_browser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
600600
(show_scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX),
601601
filename,
602602
scroll_counter,
603-
(model->item_idx != idx));
603+
(model->item_idx != idx),
604+
false
605+
);
604606
}
605607

606608
if(show_scrollbar) {

0 commit comments

Comments
 (0)