18 #include "os_helpers.h"
28 #if defined(HAVE_INDEXED_STRINGS)
34 #if (defined HAVE_BOLOS || defined(BUILD_PNG))
38 #if (BAGL_WIDTH==128 && BAGL_HEIGHT==64)
56 {{BAGL_RECTANGLE , 0x00, 0, 0, 128, 64, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, .
text=NULL},
58 {{BAGL_ICON , 0x01, 2, 28, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(
const char*)&C_icon_left},
59 {{BAGL_ICON , 0x02, 122, 28, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(
const char*)&C_icon_right},
61 {{BAGL_ICON , 0x0F, 16, 24, 16, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=NULL},
63 {{BAGL_LABELINE , 0x10, 6, 15, 116, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
64 {{BAGL_LABELINE , 0x11, 6, 29, 116, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
65 {{BAGL_LABELINE , 0x12, 6, 43, 116, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
66 {{BAGL_LABELINE , 0x13, 6, 57, 116, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
68 #elif (BAGL_WIDTH==128 && BAGL_HEIGHT==32)
80 {{BAGL_RECTANGLE , 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0}, .text=NULL},
82 {{BAGL_ICON , 0x01, 2, 12, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(
const char*)&C_icon_left},
83 {{BAGL_ICON , 0x02, 122, 12, 4, 7, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=(
const char*)&C_icon_right},
85 {{BAGL_ICON , 0x0F, 14, 8, 16, 16, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, 0 }, .text=NULL},
87 {{BAGL_LABELINE , 0x10, 6, 12, 116, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
88 {{BAGL_LABELINE , 0x11, 6, 26, 116, 32, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_REGULAR_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, .text=NULL},
94 #define BAGL_ICON_TEXT_XCOORD 38
95 #define BAGL_ICON_TEXT_WIDTH (BAGL_WIDTH - BAGL_ICON_TEXT_XCOORD)
101 const bagl_icon_details_t *update_lines_length(
const char *text,
103 unsigned short lengths[])
105 const bagl_icon_details_t *icon_details = NULL;
109 const char *string_buffer = get_string_buffer(
G_ux.layout_paging.string_buffer_id);
112 for (
int i = 0; i < UX_LAYOUT_PAGES_LINE_COUNT; i++) {
114 unsigned short length =
G_ux.layout_paging.lengths[i];
117 if (!i &&
G_ux.layout_paging.paging_title) {
120 SPRINTF(
G_ux.string_buffer,
121 (
G_ux.layout_paging.count > 1) ?
"%s (%d/%d)" :
"%s",
123 G_ux.layout_paging.current + 1,
124 G_ux.layout_paging.count);
127 SPRINTF(
G_ux.string_buffer,
129 G_ux.layout_paging.current + 1,
130 G_ux.layout_paging.count);
133 lines[0] =
G_ux.string_buffer;
134 lengths[0] = strlen(
G_ux.string_buffer);
151 txt =
G_ux.externalText;
154 txt +=
G_ux.layout_paging.offsets[i];
157 while (txt && txt[0] ==
'\e') {
160 unsigned short extra_byte = (
unsigned char) txt[1];
162 if (extra_byte >= FIRST_GLYPHS_ICON && extra_byte <= LAST_GLYPHS_ICON) {
169 icon_details = get_glyphs_icon(extra_byte);
174 while (*txt ==
' ' && length) {
186 if (extra_byte >= FIRST_STRING_BUFFER && extra_byte <= LAST_STRING_BUFFER) {
197 txt = get_string_buffer(extra_byte);
227 const char *lines[UX_LAYOUT_PAGES_LINE_COUNT];
228 unsigned short lengths[UX_LAYOUT_PAGES_LINE_COUNT];
251 const bagl_icon_details_t *icon_side_details
252 = update_lines_length(text, lines, lengths);
253 if (icon_side_details != NULL) {
254 G_ux.tmp_element.text = (
const void *) icon_side_details;
255 return &
G_ux.tmp_element;
269 unsigned short lineidx = element->
component.userid & 0xF;
271 if (lineidx >= UX_LAYOUT_PAGES_LINE_COUNT ||
G_ux.layout_paging.lengths[lineidx] == 0) {
276 const bagl_icon_details_t *icon_side_details
277 = update_lines_length(text, lines, lengths);
278 G_ux.tmp_element.component.font_id =
G_ux.layout_paging.fond_ids[lineidx];
280 if (icon_side_details != NULL) {
281 G_ux.tmp_element.component.font_id |= BAGL_FONT_ALIGNMENT_LEFT;
284 G_ux.tmp_element.component.font_id |= BAGL_FONT_ALIGNMENT_CENTER;
287 #if (BAGL_HEIGHT == 64)
288 short y_margin = BAGL_HEIGHT - FONT_HEIGHT;
290 unsigned short nb_lines = 0;
292 short x_coord =
G_ux.tmp_element.component.x;
293 unsigned short used_height = 0;
297 for (
int i = 0; i < UX_LAYOUT_PAGES_LINE_COUNT; i++) {
298 unsigned short length;
302 if ((length = lengths[i]) == 0 || (txt = lines[i]) == NULL) {
306 unsigned short height = FONT_HEIGHT;
310 if (icon_side_details != NULL) {
312 x_coord = BAGL_ICON_TEXT_XCOORD;
313 G_ux.tmp_element.component.width = BAGL_ICON_TEXT_WIDTH;
320 if (txt[0] ==
'\e') {
321 unsigned short extra_byte = (
unsigned char) txt[1];
323 if (extra_byte >= FIRST_GLYPHS_ICON && extra_byte <= LAST_GLYPHS_ICON) {
327 const bagl_icon_details_t *icon_details = get_glyphs_icon(extra_byte);
328 height = icon_details->height;
331 G_ux.tmp_element.component.type = BAGL_ICON;
332 G_ux.tmp_element.component.icon_id = 0;
333 G_ux.tmp_element.text = (
const char *) icon_details;
336 += (
G_ux.tmp_element.component.width - icon_details->width) / 2;
337 G_ux.tmp_element.component.height = icon_details->height;
338 G_ux.tmp_element.component.width = icon_details->width;
343 else if (lineidx == i) {
346 G_ux.layout_paging.line_buffer,
349 (
unsigned int) (
MIN(
sizeof(
G_ux.layout_paging.line_buffer) - 1, length)),
351 G_ux.tmp_element.text =
G_ux.layout_paging.line_buffer;
353 y_coord += FONT_BASELINE;
358 used_height += height;
360 #if (BAGL_HEIGHT == 64)
366 #if (BAGL_HEIGHT == 64)
368 used_height += 2 * y_margin;
373 y_coord += (((lineidx + 1) * (BAGL_HEIGHT - used_height)) + (nb_lines + 1) / 2)
377 G_ux.tmp_element.component.x = x_coord;
378 G_ux.tmp_element.component.y = y_coord;
382 return &
G_ux.tmp_element;
387 static bool is_loc_word_delim(
unsigned char c)
392 return c ==
' ' || c ==
'\n' || c ==
'\b' || c ==
'\f' || c ==
'\e' || c ==
'-' || c ==
'_';
396 unsigned int ux_layout_pages_compute(
const char *text_to_split,
397 unsigned int page_to_display,
398 ux_layout_paging_state_t *paging_state)
400 bagl_font_id_e font_id;
403 memset(paging_state->offsets, 0,
sizeof(paging_state->offsets));
404 memset(paging_state->lengths, 0,
sizeof(paging_state->lengths));
407 if (page_to_display >= paging_state->count && page_to_display != (
unsigned int) -1) {
412 unsigned char paging_format;
415 unsigned char use_bold_font;
416 if (
G_ux.layout_paging.format & PAGING_FORMAT_NB) {
423 unsigned int page = 0;
424 unsigned int line = 0;
425 const char *start = (text_to_split ?
STRPIC(text_to_split) :
G_ux.externalText);
426 const char *start2 = start;
427 const char *end = start + strlen(start);
428 unsigned int string_buffer_mark_offset = (
unsigned int) -1;
429 unsigned int string_buffer_mark_len = 0;
430 unsigned char string_buffer_id = 0;
431 unsigned char icon_on_side = 0;
432 unsigned char extra_byte;
433 const char *page_start = start;
434 unsigned char page_use_bold_font = use_bold_font;
435 unsigned int string_buffer_start_page = (
unsigned int) -1;
436 paging_state->string_buffer_id = string_buffer_id;
437 while (start < end) {
438 unsigned int len, icon_on_side_len;
443 if (!line &&
G_ux.layout_paging.paging_title) {
444 paging_state->fond_ids[0] = BAGL_FONT_OPEN_SANS_REGULAR_11px;
445 paging_state->lengths[0] = 1;
448 len = icon_on_side_len = 0;
453 while (*start ==
' ' && (start + 1) < end) {
457 if (*start ==
'\b') {
461 const char *last_word_delim = start;
464 font_id = BAGL_FONT_OPEN_SANS_EXTRABOLD_11px;
466 paging_format = PAGING_FORMAT_NB;
470 font_id = BAGL_FONT_OPEN_SANS_REGULAR_11px;
472 paging_format = PAGING_FORMAT_NN;
476 while (start + len < end
478 && (icon_on_side == 0 || linew <= BAGL_ICON_TEXT_WIDTH)
479 && linew <= PIXEL_PER_LINE
481 && len < (
sizeof(
G_ux.layout_paging.line_buffer) - 1)) {
486 if (start[icon_on_side_len] ==
'\e') {
487 extra_byte = start[icon_on_side_len + 1];
492 if (extra_byte >= FIRST_STRING_BUFFER && extra_byte <= LAST_STRING_BUFFER) {
494 if (string_buffer_id || !get_string_buffer(extra_byte)) {
496 if (!icon_on_side_len) {
502 string_buffer_mark_offset = start - start2;
503 string_buffer_mark_len = icon_on_side_len;
504 string_buffer_start_page = page;
506 if (string_buffer_mark_offset == 1 && start2[0] ==
'\b') {
507 string_buffer_mark_offset = 0;
509 string_buffer_id = extra_byte;
511 start = get_string_buffer(extra_byte);
513 end = start + strlen(start);
516 goto page_start_loop;
524 if (start[icon_on_side_len + 2] ==
'\n' || start[icon_on_side_len + 2] ==
'\f'
525 || start[icon_on_side_len + 2] ==
'\0') {
526 c = start[icon_on_side_len + 2];
527 len = icon_on_side_len + 3;
535 if (!icon_on_side && line) {
539 end = start + strlen(start);
541 if (string_buffer_start_page != (
unsigned int) -1
542 && string_buffer_start_page == page) {
543 start2 = (text_to_split ?
STRPIC(text_to_split) :
G_ux.externalText);
544 string_buffer_start_page = (
unsigned int) -1;
545 paging_state->string_buffer_id = string_buffer_id = 0;
546 string_buffer_mark_offset = (
unsigned int) -1;
547 string_buffer_mark_len = 0;
549 use_bold_font = page_use_bold_font;
551 if (page_to_display == page) {
552 memset(paging_state->offsets, 0,
sizeof(paging_state->offsets));
553 memset(paging_state->lengths, 0,
sizeof(paging_state->lengths));
555 goto page_start_loop;
560 while (start[len] ==
' ') {
564 icon_on_side_len = len;
577 linew = se_compute_line_width_light(start, len + 1, paging_format);
580 if ((icon_on_side != 0 && linew > BAGL_ICON_TEXT_WIDTH) || linew > PIXEL_PER_LINE) {
585 if (is_loc_word_delim(c)) {
586 last_word_delim = &start[len];
590 if (c ==
'\n' || c ==
'\f') {
597 if (start + len < end && last_word_delim != start && len) {
599 if ((!is_loc_word_delim(start[len - 1]) && !is_loc_word_delim(start[len]))) {
600 len = last_word_delim - start;
605 for (
unsigned int i = 0; i < len; i++) {
606 if (start[i] ==
'\b') {
611 if (page_to_display != (
unsigned int) -1 && page_to_display == page
612 && page_to_display < paging_state->count) {
614 if (string_buffer_mark_offset != (
unsigned int) -1) {
615 paging_state->offsets[line] = string_buffer_mark_offset;
618 paging_state->offsets[line] = start - start2;
622 if (string_buffer_start_page != (
unsigned int) -1
623 && (string_buffer_start_page < page
624 || (string_buffer_start_page == page && string_buffer_mark_offset == 0))) {
625 paging_state->string_buffer_id = string_buffer_id;
628 if (c ==
'\n' || c ==
'\f' || c ==
'\0') {
629 paging_state->lengths[line] = len - 1 + string_buffer_mark_len;
632 paging_state->lengths[line] = len + string_buffer_mark_len;
634 string_buffer_mark_offset = (
unsigned int) -1;
635 string_buffer_mark_len = 0;
637 paging_state->fond_ids[line] = font_id;
640 #if UX_LAYOUT_PAGES_LINE_COUNT > 1
641 if (line >= UX_LAYOUT_PAGES_LINE_COUNT - 1)
657 #
if UX_LAYOUT_PAGES_LINE_COUNT > 1
658 line >= UX_LAYOUT_PAGES_LINE_COUNT &&
665 string_buffer_mark_offset = (
unsigned int) -1;
666 string_buffer_mark_len = 0;
667 page_use_bold_font = use_bold_font;
677 void ux_layout_pages_display_init(
const char *text)
680 G_ux.layout_paging.current = 0;
681 G_ux.layout_paging.count = 1;
682 G_ux.layout_paging.paging_title = 0;
683 G_ux.layout_paging.format = PAGING_FORMAT_NN;
685 ux_layout_pages_compute(text,
G_ux.layout_paging.current, &
G_ux.layout_paging);
691 return ux_layout_pages_prepro_common(element, text);
697 void ux_layout_pages_redisplay_common(
unsigned int stack_slot,
709 ux_layout_pages_compute(text,
G_ux.layout_paging.current, &
G_ux.layout_paging);
720 if (NULL == params) {
725 #if defined(HAVE_INDEXED_STRINGS)
730 return ux_layout_pages_prepro_common(element, text);
733 unsigned int ux_layout_pages_button_callback_by_addr(
unsigned int button_mask,
734 unsigned int button_mask_counter);
735 unsigned int ux_loc_layout_paging_button_callback_by_addr(
unsigned int button_mask,
736 unsigned int button_mask_counter);
738 void ux_layout_pages_redisplay_by_addr(
unsigned int stack_slot)
742 if (NULL == params) {
745 #if defined(HAVE_INDEXED_STRINGS)
750 ux_layout_pages_redisplay_common(
751 stack_slot, text, ux_layout_pages_button_callback_by_addr, ux_layout_pages_prepro_by_addr);
758 if (NULL == params) {
767 return ux_layout_pages_prepro_common(element, text);
770 void ux_loc_layout_paging_redisplay_by_addr(
unsigned int stack_slot)
774 if (NULL == params) {
781 ux_layout_pages_redisplay_common(stack_slot,
783 ux_loc_layout_paging_button_callback_by_addr,
784 ux_loc_layout_paging_prepro_by_addr);
788 unsigned int ux_layout_paging_button_callback_common(
unsigned int button_mask,
789 unsigned int button_mask_counter,
790 ux_layout_paging_redisplay_t redisplay);
792 unsigned int ux_loc_layout_paging_button_callback_by_addr(
unsigned int button_mask,
793 unsigned int button_mask_counter)
795 return ux_layout_paging_button_callback_common(
796 button_mask, button_mask_counter, ux_loc_layout_paging_redisplay_by_addr);
799 unsigned int ux_layout_pages_button_callback_by_addr(
unsigned int button_mask,
800 unsigned int button_mask_counter)
802 return ux_layout_paging_button_callback_common(
803 button_mask, button_mask_counter, ux_layout_pages_redisplay_by_addr);
811 G_ux.layout_paging.format = PAGING_FORMAT_NN;
812 G_ux.layout_paging.paging_title = 0;
813 #if defined(HAVE_INDEXED_STRINGS)
818 ux_layout_pages_init_common(stack_slot, text, ux_layout_pages_redisplay_by_addr);
831 G_ux.layout_paging.format = PAGING_FORMAT_NN;
836 ux_layout_pages_init_common(stack_slot, text, ux_loc_layout_paging_redisplay_by_addr);
841 void ux_layout_pages_init_common(
unsigned int stack_slot,
843 ux_layout_paging_redisplay_t redisplay)
847 unsigned int backup_format =
G_ux.layout_paging.format;
848 unsigned int backup_title =
G_ux.layout_paging.paging_title;
853 ux_layout_paging_reset();
857 G_ux.layout_paging.current = (
unsigned int) -1;
861 ux_layout_paging_reset();
868 G_ux.layout_paging.format = backup_format;
869 G_ux.layout_paging.paging_title = backup_title;
875 if ((text == NULL) && (
G_ux.externalText == NULL)) {
880 G_ux.layout_paging.count = ux_layout_pages_compute(
881 text, (
unsigned int) -1, &
G_ux.layout_paging);
884 if (
G_ux.layout_paging.count == 0) {
885 ux_layout_paging_reset();
893 if (
G_ux.layout_paging.count &&
G_ux.layout_paging.current > (
G_ux.layout_paging.count - 1)) {
894 G_ux.layout_paging.current =
G_ux.layout_paging.count - 1;
897 redisplay(stack_slot);
#define BAGL_ENCODING_DEFAULT
const char * get_ux_loc_string(uint32_t index)
bagl_component_t component
unsigned char element_arrays_count
button_push_callback_t button_push_callback
struct ux_stack_slot_s::@45 element_arrays[UX_STACK_SLOT_ARRAY_COUNT]
bagl_element_callback_t screen_before_element_display_callback
const bagl_element_t * element_array
unsigned char element_array_count
const bagl_element_t *(* bagl_element_callback_t)(const bagl_element_t *element)
void ux_stack_display(unsigned int stack_slot)
void ux_stack_init(unsigned int stack_slot)
unsigned int(* button_push_callback_t)(unsigned int button_mask, unsigned int button_mask_counter)
@ FLOW_DIRECTION_BACKWARD
ux_flow_direction_t ux_flow_direction(void)
unsigned int ux_flow_is_first(void)
const void * ux_stack_get_step_params(unsigned int stack_slot)
const void * ux_stack_get_current_step_params(void)
unsigned int ux_flow_is_last(void)
void ux_layout_pages_init(unsigned int stack_slot)
void ux_loc_layout_paging_init(unsigned int stack_slot)
void ux_loc_layout_pages_init(unsigned int stack_slot)