Skip to content

Commit

Permalink
Dark Mode & Wii Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueMaster committed May 17, 2023
1 parent b96c445 commit 83e836f
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 102 deletions.
4 changes: 3 additions & 1 deletion applications/main/archive/views/archive_browser_view.c
Expand Up @@ -327,7 +327,9 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
((scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX) - x_offset),
str_buf,
scroll_counter,
(model->item_idx != idx));
(model->item_idx != idx),
false
);

furi_string_free(str_buf);
}
Expand Down
4 changes: 3 additions & 1 deletion applications/main/subghz/views/receiver.c
Expand Up @@ -269,7 +269,9 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
(scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX),
str_buff,
scroll_counter,
(model->idx != idx));
(model->idx != idx),
false
);
furi_string_reset(str_buff);
}
if(scrollbar) {
Expand Down
33 changes: 26 additions & 7 deletions applications/services/gui/canvas.c
Expand Up @@ -7,6 +7,7 @@
#include <furi_hal_rtc.h>
#include <stdint.h>
#include <u8g2_glue.h>
#include <cfw.h>

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

void canvas_clear(Canvas* canvas) {
furi_assert(canvas);
u8g2_ClearBuffer(&canvas->fb);
if(CFW_SETTINGS()->dark_mode) {
u8g2_FillBuffer(&canvas->fb);
} else {
u8g2_ClearBuffer(&canvas->fb);
}
}

void canvas_set_color(Canvas* canvas, Color color) {
furi_assert(canvas);
if(CFW_SETTINGS()->dark_mode) {
if(color == ColorBlack) {
color = ColorWhite;
} else if(color == ColorWhite) {
color = ColorBlack;
}
}
u8g2_SetDrawColor(&canvas->fb, color);
}

Expand All @@ -128,18 +140,25 @@ void canvas_invert_color(Canvas* canvas) {
void canvas_set_font(Canvas* canvas, Font font) {
furi_assert(canvas);
u8g2_SetFontMode(&canvas->fb, 1);
if(font == FontPrimary) {
switch(font) {
case FontPrimary:
u8g2_SetFont(&canvas->fb, u8g2_font_helvB08_tr);
} else if(font == FontSecondary) {
break;
case FontSecondary:
u8g2_SetFont(&canvas->fb, u8g2_font_haxrcorp4089_tr);
} else if(font == FontKeyboard) {
break;
case FontKeyboard:
u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mr);
} else if(font == FontBigNumbers) {
break;
case FontBigNumbers:
u8g2_SetFont(&canvas->fb, u8g2_font_profont22_tn);
} else if(font == FontBatteryPercent) {
break;
case FontBatteryPercent:
u8g2_SetFont(&canvas->fb, u8g2_font_5x7_tf); //u8g2_font_micro_tr);
} else {
break;
default:
furi_crash(NULL);
break;
}
}

Expand Down
42 changes: 4 additions & 38 deletions applications/services/gui/elements.c
Expand Up @@ -638,44 +638,10 @@ void elements_scrollable_text_line(
uint8_t width,
FuriString* string,
size_t scroll,
bool ellipsis) {
FuriString* line = furi_string_alloc_set(string);

size_t len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
if(len_px > width) {
if(ellipsis) {
width -= canvas_string_width(canvas, "...");
}

// Calculate scroll size
size_t scroll_size = furi_string_size(line);
size_t right_width = 0;
for(size_t i = scroll_size; i > 0; i--) {
right_width += canvas_glyph_width(canvas, furi_string_get_char(line, i));
if(right_width > width) break;
scroll_size--;
if(!scroll_size) break;
}
// Ensure that we have something to scroll
if(scroll_size) {
scroll_size += 3;
scroll = scroll % scroll_size;
furi_string_right(line, scroll);
}

len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
while(len_px > width) {
furi_string_left(line, furi_string_size(line) - 1);
len_px = canvas_string_width(canvas, furi_string_get_cstr(line));
}

if(ellipsis) {
furi_string_cat(line, "...");
}
}

canvas_draw_str(canvas, x, y, furi_string_get_cstr(line));
furi_string_free(line);
bool ellipsis,
bool centered) {
elements_scrollable_text_line_str(
canvas, x, y, width, furi_string_get_cstr(string), scroll, ellipsis, centered);
}

void elements_text_box(
Expand Down
13 changes: 7 additions & 6 deletions applications/services/gui/elements.h
Expand Up @@ -218,22 +218,23 @@ void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width
* @param string The string
* @param[in] scroll The scroll counter: 0 - no scroll, any other number - scroll. Just count up, everything else will be calculated on the inside.
* @param[in] ellipsis The ellipsis flag: true to add ellipse
* @param[in] centered The centered flag: true to center text on x and y
*/
void elements_scrollable_text_line(
void elements_scrollable_text_line_str(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
FuriString* string,
const char* string,
size_t scroll,
bool ellipsis);

void elements_scrollable_text_line_str(
bool ellipsis,
bool centered);
void elements_scrollable_text_line(
Canvas* canvas,
uint8_t x,
uint8_t y,
uint8_t width,
const char* string,
FuriString* string,
size_t scroll,
bool ellipsis,
bool centered);
Expand Down
14 changes: 7 additions & 7 deletions applications/services/gui/modules/byte_input.c
Expand Up @@ -17,17 +17,17 @@ typedef struct {
typedef struct {
const char* header;
uint8_t* bytes;
uint16_t bytes_count;
uint8_t bytes_count;

ByteInputCallback input_callback;
ByteChangedCallback changed_callback;
void* callback_context;

bool selected_high_nibble;
uint16_t selected_byte;
uint8_t selected_byte;
int8_t selected_row; // row -1 - input, row 0 & 1 - keyboard
uint8_t selected_column;
uint16_t first_visible_byte;
uint8_t first_visible_byte;
} ByteInputModel;

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

for(uint16_t i = model->first_visible_byte;
for(uint8_t i = model->first_visible_byte;
i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
i++) {
uint8_t byte_position = i - model->first_visible_byte;
Expand Down Expand Up @@ -253,7 +253,7 @@ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model
canvas_draw_icon(canvas, 2, 19, &I_ButtonLeftSmall_3x5);
canvas_draw_icon(canvas, 122, 19, &I_ButtonRightSmall_3x5);

for(uint16_t i = model->first_visible_byte;
for(uint8_t i = model->first_visible_byte;
i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
i++) {
uint8_t byte_position = i - model->first_visible_byte;
Expand Down Expand Up @@ -305,7 +305,7 @@ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model
* @param value char value
* @param high_nibble set high nibble
*/
static void byte_input_set_nibble(uint8_t* data, uint16_t position, char value, bool high_nibble) {
static void byte_input_set_nibble(uint8_t* data, uint8_t position, char value, bool high_nibble) {
switch(value) {
case '0':
case '1':
Expand Down Expand Up @@ -750,7 +750,7 @@ void byte_input_set_result_callback(
ByteChangedCallback changed_callback,
void* callback_context,
uint8_t* bytes,
uint16_t bytes_count) {
uint8_t bytes_count) {
with_view_model(
byte_input->view,
ByteInputModel * model,
Expand Down
2 changes: 1 addition & 1 deletion applications/services/gui/modules/byte_input.h
Expand Up @@ -55,7 +55,7 @@ void byte_input_set_result_callback(
ByteChangedCallback changed_callback,
void* callback_context,
uint8_t* bytes,
uint16_t bytes_count);
uint8_t bytes_count);

/** Set byte input header text
*
Expand Down
4 changes: 3 additions & 1 deletion applications/services/gui/modules/file_browser.c
Expand Up @@ -600,7 +600,9 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
(show_scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX),
filename,
scroll_counter,
(model->item_idx != idx));
(model->item_idx != idx),
false
);
}

if(show_scrollbar) {
Expand Down

0 comments on commit 83e836f

Please sign in to comment.