Skip to content

Commit

Permalink
2.30.1
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed Sep 7, 2021
1 parent 30293e4 commit 55639a3
Show file tree
Hide file tree
Showing 11 changed files with 935 additions and 107 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Description: https://github.com/olikraus/u8g2/wiki

Issue Tracker: https://github.com/olikraus/u8g2/issues

Download (2.29.11): https://github.com/olikraus/U8g2_Arduino/archive/master.zip
Download (2.30.1): https://github.com/olikraus/U8g2_Arduino/archive/master.zip

372 changes: 372 additions & 0 deletions examples/page_buffer/ButtonEmoticon/ButtonEmoticon.ino

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion extras/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ https://github.com/olikraus/u8g2 ChangeLog
* U8g2 16 Bit Mode enabled by default for ARM and ESP Systems (issue 1222)
2021-09-03 v2.29.11 [email protected]
* Update for getStrWidth/getUTF8Width: The new return value might be little bit larger (issue 1561)
* New draw procedure drawButtonUTF8: (issue 1577)
* New draw procedure drawButtonUTF8 (issue 1577)
* Added vertical mirror option U8G2_MIRROR_VERTICAL for u8g2 ([email protected], issue 1474).
* Added support for UC1638 based 196x96 display (issue 371)
* Added support for HD44102 and T7932 displays (issue 1492)
Expand All @@ -267,3 +267,5 @@ https://github.com/olikraus/u8g2 ChangeLog
* Added support for SSD1306 EA OLEDS102 (issue 1493)
* Added support for UC1601 128x64 (issue 1501)
* Font Wiki page splitted into four sub-pages to avoid the GitHub 'abuse' message.
2021-09-07 v2.30.1 [email protected]
* Bugfix drawButtonUTF8 (added C++ code, issue 1577)
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=U8g2
version=2.29.11
version=2.30.1
author=oliver <[email protected]>
maintainer=oliver <[email protected]>
sentence=Monochrome LCD, OLED and eInk Library. Display controller: SSD1305, SSD1306, SSD1309, SSD1316, SSD1320, SSD1322, SSD1325, SSD1327, SSD1329, SSD1606, SSD1607, SH1106, SH1107, SH1108, SH1122, T6963, RA8835, LC7981, PCD8544, PCF8812, HX1230, UC1601, UC1604, UC1608, UC1610, UC1611, UC1617, UC1638, UC1701, ST7511, ST7528, ST7565, ST7567, ST7571, ST7586, ST7588, ST75256, ST75320, NT7534, ST7920, IST3020, IST7920, LD7032, KS0108, KS0713, HD44102, T7932, SED1520, SBN1661, IL3820, MAX7219. Interfaces: I2C, SPI, Parallel.
Expand Down
6 changes: 5 additions & 1 deletion src/U8g2lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ class U8G2 : public Print
void drawRFrame(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r) { u8g2_DrawRFrame(&u8g2, x, y, w, h,r); }
void drawBox(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) { u8g2_DrawBox(&u8g2, x, y, w, h); }
void drawRBox(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r) { u8g2_DrawRBox(&u8g2, x, y, w, h,r); }


/* u8g2_button.c */
void drawButtonUTF8(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t flags, u8g2_uint_t width, u8g2_uint_t padding_h, u8g2_uint_t padding_v, const char *text) {
u8g2_DrawButtonUTF8(&u8g2, x, y, flags, width, padding_h, padding_v, text); }

/* u8g2_circle.c */
void drawCircle(u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t opt = U8G2_DRAW_ALL) { u8g2_DrawCircle(&u8g2, x0, y0, rad, opt); }
void drawDisc(u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t opt = U8G2_DRAW_ALL) { u8g2_DrawDisc(&u8g2, x0, y0, rad, opt); }
Expand Down
129 changes: 102 additions & 27 deletions src/clib/mui.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, [email protected]
Copyright (c) 2021, [email protected]
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -80,7 +80,9 @@

//#define mui_get_fds_char(s) ((uint8_t)(*s))


//#include <stdio.h>
//#define MUI_DEBUG(...) printf(__VA_ARGS__)
#define MUI_DEBUG(...)

uint8_t mui_get_fds_char(fds_t *s)
{
Expand All @@ -92,8 +94,8 @@ uint8_t mui_get_fds_char(fds_t *s)
/*
s must point to a valid command within FDS
*/
static size_t mui_fds_get_cmd_size_without_text(mui_t *ui, fds_t *s) MUI_NOINLINE;
static size_t mui_fds_get_cmd_size_without_text(mui_t *ui, fds_t *s)
static size_t mui_fds_get_cmd_size_without_text(fds_t *s) MUI_NOINLINE;
static size_t mui_fds_get_cmd_size_without_text(fds_t *s)
{
uint8_t c = mui_get_fds_char(s);
c &= 0xdf; /* consider upper and lower case */
Expand Down Expand Up @@ -180,7 +182,7 @@ static size_t mui_fds_parse_text(mui_t *ui, fds_t *s)
uint8_t mui_fds_first_token(mui_t *ui)
{
ui->token = ui->fds;
ui->token += mui_fds_get_cmd_size_without_text(ui, ui->fds);
ui->token += mui_fds_get_cmd_size_without_text(ui->fds);
ui->delimiter = mui_get_fds_char(ui->token);
ui->token++; // place ui->token on the first char of the token
return mui_fds_next_token(ui);
Expand Down Expand Up @@ -271,7 +273,7 @@ uint8_t mui_fds_get_token_cnt(mui_t *ui)
static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s) MUI_NOINLINE;
static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s)
{
size_t l = mui_fds_get_cmd_size_without_text(ui, s);
size_t l = mui_fds_get_cmd_size_without_text(s);
uint8_t c = mui_get_fds_char(s);
ui->text[0] = '\0' ; /* always reset the text buffer */
if ( mui_fds_is_text(c) )
Expand All @@ -298,7 +300,7 @@ void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, si

int mui_find_uif(mui_t *ui, uint8_t id0, uint8_t id1)
{
int i;
size_t i;
for( i = 0; i < ui->muif_tcnt; i++ )
{
/*
Expand All @@ -321,7 +323,8 @@ int mui_find_uif(mui_t *ui, uint8_t id0, uint8_t id1)
will return 1 if the field id was found.
will return 0 if the field id was not found in uif or if ui->fds points to something else than a field
*/
uint8_t mui_prepare_current_field(mui_t *ui)
static uint8_t mui_prepare_current_field(mui_t *ui) MUI_NOINLINE;
static uint8_t mui_prepare_current_field(mui_t *ui)
{
int muif_tidx;

Expand All @@ -338,7 +341,7 @@ uint8_t mui_prepare_current_field(mui_t *ui)

/* get the command and check whether end of form is reached */
ui->cmd = mui_get_fds_char(ui->fds);
//printf("mui_prepare_current_field cmd='%c'\n", ui->cmd);
//printf("mui_prepare_current_field cmd='%c' len=%d\n", ui->cmd, ui->len);

/* Copy the cmd also to second id value. This is required for some commands, others will overwrite this below */
ui->id1 = ui->cmd;
Expand Down Expand Up @@ -384,6 +387,9 @@ uint8_t mui_prepare_current_field(mui_t *ui)
ui->arg = mui_get_fds_char(ui->fds+3);
}
}

//MUI_DEBUG("mui_prepare_current_field cmd='%c' len=%d arg=%d\n", ui->cmd, ui->len, ui->arg);


/* find the field */
muif_tidx = mui_find_uif(ui, ui->id0, ui->id1);
Expand All @@ -404,10 +410,12 @@ uint8_t mui_prepare_current_field(mui_t *ui)
*/

void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
static void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
static void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
{
uint8_t cmd;

//MUI_DEBUG("mui_inner_loop_over_form start %p\n", task);

ui->fds += mui_fds_get_cmd_size(ui, ui->fds); // skip the first entry, it is U always
for(;;)
Expand All @@ -419,13 +427,18 @@ void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
break;
if ( mui_prepare_current_field(ui) )
if ( task(ui) ) /* call the task, which was provided as argument to this function */
{
//MUI_DEBUG("mui_inner_loop_over_form break by task\n");
break;
}
ui->fds += ui->len;
}
//printf("mui_loop_over_form ended\n");

//MUI_DEBUG("mui_inner_loop_over_form end %p\n", task);
}

void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
static void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
static void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
{
if ( mui_IsFormActive(ui) == 0 )
return;
Expand Down Expand Up @@ -486,10 +499,20 @@ uint8_t mui_task_form_end(mui_t *ui)
return 0; /* continue with the loop */
}

static uint8_t mui_uif_is_cursor_selectable(mui_t *ui) MUI_NOINLINE;
static uint8_t mui_uif_is_cursor_selectable(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
{
return 1;
}
return 0;
}

uint8_t mui_task_find_prev_cursor_uif(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
if ( mui_uif_is_cursor_selectable(ui) )
{
if ( ui->fds == ui->cursor_focus_fds )
{
Expand All @@ -503,7 +526,8 @@ uint8_t mui_task_find_prev_cursor_uif(mui_t *ui)

uint8_t mui_task_find_first_cursor_uif(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
if ( mui_uif_is_cursor_selectable(ui) )
{
// if ( ui->target_fds == NULL )
// {
Expand All @@ -516,7 +540,8 @@ uint8_t mui_task_find_first_cursor_uif(mui_t *ui)

uint8_t mui_task_find_last_cursor_uif(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
if ( mui_uif_is_cursor_selectable(ui) )
{
//ui->cursor_focus_position++;
ui->target_fds = ui->fds;
Expand All @@ -526,7 +551,8 @@ uint8_t mui_task_find_last_cursor_uif(mui_t *ui)

uint8_t mui_task_find_next_cursor_uif(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
if ( mui_uif_is_cursor_selectable(ui) )
{
if ( ui->tmp_fds != NULL )
{
Expand All @@ -544,7 +570,8 @@ uint8_t mui_task_find_next_cursor_uif(mui_t *ui)

uint8_t mui_task_get_current_cursor_focus_position(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
if ( mui_uif_is_cursor_selectable(ui) )
{
if ( ui->fds == ui->cursor_focus_fds )
return 1; /* stop looping */
Expand All @@ -553,9 +580,10 @@ uint8_t mui_task_get_current_cursor_focus_position(mui_t *ui)
return 0; /* continue with the loop */
}

uint8_t mui_task_read_nth_seleectable_field(mui_t *ui)
uint8_t mui_task_read_nth_selectable_field(mui_t *ui)
{
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
if ( mui_uif_is_cursor_selectable(ui) )
{
if ( ui->tmp8 == 0 )
return 1; /* stop looping */
Expand All @@ -567,14 +595,16 @@ uint8_t mui_task_read_nth_seleectable_field(mui_t *ui)

/* === utility functions for the user API === */

void mui_send_cursor_msg(mui_t *ui, uint8_t msg)
static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg) MUI_NOINLINE;
static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg)
{
if ( ui->cursor_focus_fds )
{
ui->fds = ui->cursor_focus_fds;
if ( mui_prepare_current_field(ui) )
muif_get_cb(ui->uif)(ui, msg);
return muif_get_cb(ui->uif)(ui, msg);
}
return 0; /* not called, msg not handled */
}

/* === user API === */
Expand Down Expand Up @@ -626,7 +656,8 @@ void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor

// use the inner_loop procedure, because ui->fds has been assigned already
ui->tmp8 = cursor_position; // maybe we should also backup tmp8, but at the moment tmp8 is only used by mui_task_get_current_cursor_focus_position
mui_inner_loop_over_form(ui, mui_task_read_nth_seleectable_field);
//MUI_DEBUG("mui_GetSelectableFieldTextOption\n");
mui_inner_loop_over_form(ui, mui_task_read_nth_selectable_field);
// at this point ui->fds contains the field which was selected from above

// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
Expand All @@ -637,6 +668,42 @@ void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor
// result is stored in ui->text
}

/*
this function will overwrite the ui field related member variables
return the number of options in the referenced field
*/
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, uint8_t form_id, uint8_t cursor_position)
{
fds_t *fds = ui->fds; // backup the current fds, so that this function can be called inside a task loop
int len = ui->len; // backup length of the current command
uint8_t cnt = 0;

ui->fds = mui_find_form(ui, form_id); // search for the target form and overwrite the current fds

// use the inner_loop procedure, because ui->fds has been assigned already
ui->tmp8 = cursor_position; // maybe we should also backup tmp8, but at the moment tmp8 is only used by mui_task_get_current_cursor_focus_position
//MUI_DEBUG("mui_GetSelectableFieldOptionCnt\n");
mui_inner_loop_over_form(ui, mui_task_read_nth_selectable_field);
// at this point ui->fds contains the field which was selected from above

// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
cnt = mui_fds_get_token_cnt(ui);

ui->fds = fds; // restore the previous fds position
ui->len = len;
// result is stored in ui->text
return cnt;
}



//static void mui_send_cursor_enter_msg(mui_t *ui) MUI_NOINLINE;
static void mui_send_cursor_enter_msg(mui_t *ui)
{
ui->is_mud = 0;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
}

/*
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
mui_EnterForm is similar to mui_GotoForm and differes only in the second argument (which is the form id instead of the fds pointer)
Expand All @@ -654,19 +721,22 @@ void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
ui->current_form_fds = fds;

/* inform all fields that we start a new form */
MUI_DEBUG("mui_EnterForm: form_start\n");
mui_loop_over_form(ui, mui_task_form_start);

/* assign initional cursor focus */
MUI_DEBUG("mui_EnterForm: find_first_cursor_uif\n");
mui_loop_over_form(ui, mui_task_find_first_cursor_uif);
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
MUI_DEBUG("mui_EnterForm: find_first_cursor_uif target_fds=%p\n", ui->target_fds);

while( initial_cursor_position > 0 )
{
mui_next_field(ui);
mui_NextField(ui); // mui_next_field(ui) is not sufficient in case of scrolling
initial_cursor_position--;
}

mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
mui_send_cursor_enter_msg(ui);
}

/* input: current_form_fds */
Expand All @@ -682,6 +752,7 @@ void mui_LeaveForm(mui_t *ui)
ui->cursor_focus_fds = NULL;

/* inform all fields that we leave the form */
MUI_DEBUG("mui_LeaveForm: form_end\n");
mui_loop_over_form(ui, mui_task_form_end);
ui->current_form_fds = NULL;
}
Expand Down Expand Up @@ -725,9 +796,11 @@ void mui_RestoreForm(mui_t *ui)
*/
void mui_NextField(mui_t *ui)
{
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_NEXT) )
return;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
mui_next_field(ui);
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
mui_send_cursor_enter_msg(ui);
}

/*
Expand All @@ -738,6 +811,8 @@ void mui_NextField(mui_t *ui)
*/
void mui_PrevField(mui_t *ui)
{
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_PREV) )
return;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);

mui_loop_over_form(ui, mui_task_find_prev_cursor_uif);
Expand All @@ -750,7 +825,7 @@ void mui_PrevField(mui_t *ui)
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
}

mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
mui_send_cursor_enter_msg(ui);
}


Expand Down
Loading

0 comments on commit 55639a3

Please sign in to comment.