Prusa MINI Firmware overview
window_menu.c File Reference
#include "window_menu.h"
#include "gui.h"

Macros

#define WIO_MIN   0
 
#define WIO_MAX   1
 
#define WIO_STEP   2
 
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
 

Functions

void window_menu_inc (window_menu_t *window, int dif)
 
void window_menu_dec (window_menu_t *window, int dif)
 
void window_menu_item_spin (window_menu_t *window, int dif)
 
void window_menu_item_spin_fl (window_menu_t *window, int dif)
 
void window_menu_item_switch (window_menu_t *window)
 
void window_menu_item_select (window_menu_t *window, int dif)
 
void window_menu_items (window_menu_t *pwindow_menu, uint16_t index, window_menu_item_t **ppitem, void *data)
 
void window_menu_init (window_menu_t *window)
 
void window_menu_done (window_menu_t *window)
 
void window_menu_calculate_spin (WI_SPIN_t *item, char *value)
 
void _window_menu_draw_value (window_menu_t *window, const char *value, rect_ui16_t *p_rc, color_t color_text_option, color_t color_back)
 
void window_menu_draw (window_menu_t *window)
 
void window_menu_event (window_menu_t *window, uint8_t event, void *param)
 

Variables

osThreadId displayTaskHandle
 
window_menu_item_t undefined = { "No menu_items fce!", 0, WI_LABEL | WI_DISABLED }
 
const window_class_menu_t window_class_menu
 

Macro Definition Documentation

◆ WIO_MIN

#define WIO_MIN   0

◆ WIO_MAX

#define WIO_MAX   1

◆ WIO_STEP

#define WIO_STEP   2

◆ MIN

#define MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

◆ MAX

#define MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Function Documentation

◆ window_menu_inc()

void window_menu_inc ( window_menu_t window,
int  dif 
)
281  {
282  switch (window->mode) {
283  case WI_SPIN:
284  window_menu_item_spin(window, dif);
285  break;
286  case WI_SPIN_FL:
287  window_menu_item_spin_fl(window, dif);
288  break;
289  case WI_SELECT:
290  window_menu_item_select(window, dif);
291  break;
292  default: {
293  // WI_LABEL
294  //all items can be in label mode
295  int item_height = window->font->h + window->padding.top + window->padding.bottom;
296  int visible_count = window->win.rect.h / item_height;
297  int old = window->index;
298  window->index += dif;
299  if (window->index < 0)
300  window->index = 0;
301  if (window->index >= window->count)
302  window->index = window->count - 1;
303 
304  if (window->index < window->top_index)
305  window->top_index = window->index;
306  if (window->index >= (window->top_index + visible_count))
307  window->top_index = window->index - visible_count + 1;
308 
309  if (window->index != old) // optimalization do not redraw when no change - still on end
310  _window_invalidate((window_t *)window);
311  }
312  }
313 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_menu_dec()

void window_menu_dec ( window_menu_t window,
int  dif 
)
315  {
316  window_menu_inc(window, -dif);
317 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_menu_item_spin()

void window_menu_item_spin ( window_menu_t window,
int  dif 
)
208  {
209  window_menu_item_t *item;
210  window->menu_items(window, window->index, &item, window->data);
211 
212  const int32_t *range = item->wi_spin.range;
213  int32_t old = item->wi_spin.value;
214 
215  if (dif > 0) {
216  item->wi_spin.value = MIN(item->wi_spin.value + dif * range[WIO_STEP], range[WIO_MAX]);
217  } else {
218  item->wi_spin.value = MAX(item->wi_spin.value + dif * range[WIO_STEP], range[WIO_MIN]);
219  }
220 
221  if (old != item->wi_spin.value)
222  _window_invalidate((window_t *)window);
223 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_menu_item_spin_fl()

void window_menu_item_spin_fl ( window_menu_t window,
int  dif 
)
225  {
226  window_menu_item_t *item;
227  window->menu_items(window, window->index, &item, window->data);
228 
229  const float *range = item->wi_spin_fl.range;
230  float old = item->wi_spin_fl.value;
231 
232  if (dif > 0) {
233  item->wi_spin_fl.value = MIN(item->wi_spin_fl.value + (float)dif * range[WIO_STEP], range[WIO_MAX]);
234  } else {
235  item->wi_spin_fl.value = MAX(item->wi_spin_fl.value + (float)dif * range[WIO_STEP], range[WIO_MIN]);
236  }
237 
238  if (old != item->wi_spin_fl.value)
239  _window_invalidate((window_t *)window);
240 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_menu_item_switch()

void window_menu_item_switch ( window_menu_t window)
242  {
243  window_menu_item_t *item;
244  window->menu_items(window, window->index, &item, window->data);
245 
246  const char **strings = item->wi_switch_select.strings;
247  size_t size = 0;
248  while (strings[size] != NULL) {
249  size++;
250  }
251  item->wi_switch_select.index++;
252  if (item->wi_switch_select.index >= size) {
253  item->wi_switch_select.index = 0;
254  }
255 }
Here is the caller graph for this function:

◆ window_menu_item_select()

void window_menu_item_select ( window_menu_t window,
int  dif 
)
257  {
258  window_menu_item_t *item;
259  window->menu_items(window, window->index, &item, window->data);
260 
261  const char **strings = item->wi_switch_select.strings;
262  size_t size = 0;
263  while (strings[size] != NULL) {
264  size++;
265  }
266 
267  if (dif > 0) {
268  item->wi_switch_select.index++;
269  if (item->wi_switch_select.index >= size) {
270  item->wi_switch_select.index = 0;
271  }
272  } else {
273  item->wi_switch_select.index--;
274  if (item->wi_switch_select.index < 0) {
275  item->wi_switch_select.index = size - 1;
276  }
277  }
278  _window_invalidate((window_t *)window);
279 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_menu_items()

void window_menu_items ( window_menu_t pwindow_menu,
uint16_t  index,
window_menu_item_t **  ppitem,
void data 
)
24  {
25  *ppitem = &undefined;
26 }
Here is the caller graph for this function:

◆ window_menu_init()

void window_menu_init ( window_menu_t window)
28  {
32  window->font = gui_defaults.font;
33  window->padding = gui_defaults.padding;
34  window->icon_rect = rect_ui16(0, 0, 16, 16);
36  window->count = 0;
37  window->index = 0;
38  window->top_index = 0;
39  window->mode = 0;
40  window->menu_items = window_menu_items;
41  window->data = NULL;
42  window->win.flg |= WINDOW_FLG_ENABLED;
43 }
Here is the call graph for this function:

◆ window_menu_done()

void window_menu_done ( window_menu_t window)
45  {
46 }

◆ window_menu_calculate_spin()

void window_menu_calculate_spin ( WI_SPIN_t item,
char *  value 
)
48  {
49  const char *format;
50 
51  if (item->range[WIO_STEP] < 10)
52  format = "%.3f";
53  else if (item->range[WIO_STEP] < 100)
54  format = "%.2f";
55  else if (item->range[WIO_STEP] < 1000)
56  format = "%.1f";
57  else
58  format = "%.f";
59  sprintf(value, format, item->value * 0.001);
60 }
Here is the caller graph for this function:

◆ _window_menu_draw_value()

void _window_menu_draw_value ( window_menu_t window,
const char *  value,
rect_ui16_t p_rc,
color_t  color_text_option,
color_t  color_back 
)
63  {
64  rect_ui16_t vrc = {
65  p_rc->x + p_rc->w, p_rc->y, window->font->w * strlen(value) + window->padding.left + window->padding.right, p_rc->h
66  };
67  vrc.x -= vrc.w;
68  p_rc->w -= vrc.w;
69 
70  render_text_align(vrc, value, window->font,
71  color_back, color_text_option, window->padding, window->alignment);
72 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ window_menu_draw()

void window_menu_draw ( window_menu_t window)
74  {
76  return;
77  }
78 
79  int item_height = window->font->h + window->padding.top + window->padding.bottom;
80  rect_ui16_t rc_win = window->win.rect;
81 
82  int visible_count = rc_win.h / item_height;
83  int i;
84  for (i = 0; i < visible_count && i < window->count; i++) {
85  int idx = i + window->top_index;
86  window_menu_item_t *item;
87  window->menu_items(window, idx, &item, window->data);
88 
89  color_t color_text = window->color_text;
90  color_t color_back = window->color_back;
91  uint8_t swap = 0;
92 
93  rect_ui16_t rc = { rc_win.x, rc_win.y + i * item_height,
94  rc_win.w, item_height };
95  padding_ui8_t padding = window->padding;
96 
97  if (rect_in_rect_ui16(rc, rc_win)) {
98  if (item->type & WI_DISABLED) {
99  color_text = window->color_disabled;
100  }
101 
102  if ((window->win.flg & WINDOW_FLG_FOCUSED) && (window->index == idx)) {
103  color_t swp = color_text;
104  color_text = color_back;
105  color_back = swp;
106  swap = ROPFN_SWAPBW;
107  }
108 
109  color_t color_option = color_text;
110  if (window->mode && swap) {
111  color_option = COLOR_ORANGE;
112  }
113 
114  switch (item->type & 0xff) //& 0xff == remove flags
115  {
116  case WI_SPIN:
117  case WI_SPIN_FL: {
118  char value[20] = { '\0' };
119  if (item->type & WI_SPIN_FL)
120  sprintf(value, item->wi_spin_fl.prt_format, (double)item->wi_spin_fl.value);
121  else
122  window_menu_calculate_spin(&(item->wi_spin), value);
123 
124  _window_menu_draw_value(window, value, &rc, color_option, color_back);
125  } break;
126  case WI_SWITCH:
127  if (swap)
128  color_option = COLOR_ORANGE;
129  case WI_SELECT: {
130  const char *value = ((const char **)item->wi_switch_select.strings)[item->wi_switch_select.index];
131 
132  _window_menu_draw_value(window, value, &rc, color_option, color_back);
133  } break;
134  }
135 
136  if (item->id_icon) {
137  rect_ui16_t irc = { rc.x, rc.y,
138  window->icon_rect.w, window->icon_rect.h };
139  rc.x += irc.w;
140  rc.w -= irc.w;
141  render_icon_align(irc, item->id_icon,
142  window->color_back, RENDER_FLG(ALIGN_CENTER, swap));
143  } else {
144  padding.left += window->icon_rect.w;
145  }
146 
147  // render
148  render_text_align(rc, item->label, window->font,
149  color_back, color_text,
150  padding, window->alignment);
151  }
152  }
153  rc_win.h = rc_win.h - (i * item_height);
154 
155  if (rc_win.h) {
156  rc_win.y += i * item_height;
157  display->fill_rect(rc_win, window->color_back);
158  }
159 }
Here is the call graph for this function:

◆ window_menu_event()

void window_menu_event ( window_menu_t window,
uint8_t  event,
void param 
)
161  {
162  window->src_event = event;
163  window->src_param = param;
164  switch (event) {
165  case WINDOW_EVENT_BTN_DN:
166  if (window->mode != WI_LABEL) {
167  window->mode = WI_LABEL;
169  } else {
170  window_menu_item_t *item;
171  window->menu_items(window, window->index, &item, window->data);
172 
173  //mask all flags but WI_DISABLED
174  if (!(item->type & WI_DISABLED)) {
175  //"& 0xff" == mask all flags off
176  //switch does not set type, i is acting like label i suppose
177  if ((item->type & 0xff) == WI_SWITCH) {
178  window_menu_item_switch(window);
179  } else {
180  window->mode = item->type & 0xff;
181  }
182  } else {
184  return;
185  }
187  }
188  _window_invalidate((window_t *)window);
189  break;
190  case WINDOW_EVENT_ENC_DN:
191  window_menu_dec(window, (int)param);
192  if (window->mode != WI_LABEL) {
194  }
195  break;
196  case WINDOW_EVENT_ENC_UP:
197  window_menu_inc(window, (int)param);
198  if (window->mode != WI_LABEL) {
200  }
201  break;
202  case WINDOW_EVENT_CAPT_1:
203  //TODO: change flag to checked
204  break;
205  }
206 }
Here is the call graph for this function:

Variable Documentation

◆ displayTaskHandle

osThreadId displayTaskHandle

◆ undefined

window_menu_item_t undefined = { "No menu_items fce!", 0, WI_LABEL | WI_DISABLED }

◆ window_class_menu

RENDER_FLG
#define RENDER_FLG(a, r)
Definition: display_helper.h:10
window_draw_t
void() window_draw_t(void *window)
Definition: window.h:57
WINDOW_EVENT_CAPT_1
#define WINDOW_EVENT_CAPT_1
Definition: window.h:45
WI_SPIN_FL_t::range
const float * range
Definition: window_menu.h:46
WI_SWITCH_SELECT_t::strings
const char ** strings
Definition: window_menu.h:55
_window_menu_t::alignment
uint8_t alignment
Definition: window_menu.h:91
_rect_ui16_t::y
uint16_t y
Definition: guitypes.h:71
_font_t::h
uint8_t h
Definition: guitypes.h:78
_rect_ui16_t::w
uint16_t w
Definition: guitypes.h:72
_padding_ui8_t::bottom
uint8_t bottom
Definition: guitypes.h:90
window_menu_item_select
void window_menu_item_select(window_menu_t *window, int dif)
Definition: window_menu.c:257
_gui_defaults_t::color_text
color_t color_text
Definition: guitypes.h:108
_padding_ui8_t::top
uint8_t top
Definition: guitypes.h:88
_padding_ui8_t::right
uint8_t right
Definition: guitypes.h:89
_window_menu_t::font
font_t * font
Definition: window_menu.h:88
WINDOW_EVENT_ENC_UP
#define WINDOW_EVENT_ENC_UP
Definition: window.h:41
ALIGN_CENTER
#define ALIGN_CENTER
Definition: guitypes.h:19
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
_gui_defaults_t::font
font_t * font
Definition: guitypes.h:110
window_menu_item_spin
void window_menu_item_spin(window_menu_t *window, int dif)
Definition: window_menu.c:208
i
uint8_t i
Definition: screen_test_graph.c:72
WINDOW_FLG_VISIBLE
#define WINDOW_FLG_VISIBLE
Definition: window.h:24
_window_menu_t::data
void * data
Definition: window_menu.h:97
rect_in_rect_ui16
static int rect_in_rect_ui16(rect_ui16_t rc, rect_ui16_t rc1)
Definition: guitypes.h:173
_gui_defaults_t::color_disabled
color_t color_disabled
Definition: guitypes.h:109
WI_SPIN
Definition: window_menu.h:15
WINDOW_EVENT_CHANGE
#define WINDOW_EVENT_CHANGE
Definition: window.h:47
NULL
#define NULL
Definition: usbd_def.h:53
window_menu_init
void window_menu_init(window_menu_t *window)
Definition: window_menu.c:28
MAX
#define MAX(a, b)
Definition: window_menu.c:10
WI_SPIN_t::range
const int32_t * range
Definition: window_menu.h:38
_display_t::fill_rect
display_fill_rect_t * fill_rect
Definition: display.h:33
WIO_MAX
#define WIO_MAX
Definition: window_menu.c:6
_window_menu_t::icon_rect
rect_ui16_t icon_rect
Definition: window_menu.h:90
_padding_ui8_t::left
uint8_t left
Definition: guitypes.h:87
_gui_defaults_t::padding
padding_ui8_t padding
Definition: guitypes.h:112
_window_menu_t::color_text
color_t color_text
Definition: window_menu.h:86
window_menu_done
void window_menu_done(window_menu_t *window)
Definition: window_menu.c:45
_window_menu_item_t::wi_spin_fl
WI_SPIN_FL_t wi_spin_fl
Definition: window_menu.h:69
window_menu_item_spin_fl
void window_menu_item_spin_fl(window_menu_t *window, int dif)
Definition: window_menu.c:225
window_done_t
void() window_done_t(void *window)
Definition: window.h:56
window_menu_items
void window_menu_items(window_menu_t *pwindow_menu, uint16_t index, window_menu_item_t **ppitem, void *data)
Definition: window_menu.c:23
COLOR_ORANGE
#define COLOR_ORANGE
Definition: guitypes.h:57
WI_DISABLED
Definition: window_menu.h:20
_window_t
Definition: window.h:76
window_menu_t
struct _window_menu_t window_menu_t
Definition: window_menu.h:8
undefined
window_menu_item_t undefined
Definition: window_menu.c:21
WI_SWITCH
Definition: window_menu.h:16
window_menu_draw
void window_menu_draw(window_menu_t *window)
Definition: window_menu.c:74
_gui_defaults_t::color_back
color_t color_back
Definition: guitypes.h:107
WINDOW_CLS_MENU
#define WINDOW_CLS_MENU
Definition: window.h:18
_font_t::w
uint8_t w
Definition: guitypes.h:77
WI_SPIN_t::value
int32_t value
Definition: window_menu.h:37
WI_SPIN_FL_t::value
float value
Definition: window_menu.h:44
_window_menu_t::mode
uint8_t mode
Definition: window_menu.h:95
_window_menu_t::padding
padding_ui8_t padding
Definition: window_menu.h:89
_padding_ui8_t
Definition: guitypes.h:86
ROPFN_SWAPBW
#define ROPFN_SWAPBW
Definition: guitypes.h:32
_window_menu_t::src_event
uint8_t src_event
Definition: window_menu.h:98
WI_SPIN_FL_t::prt_format
const char * prt_format
Definition: window_menu.h:45
WI_SPIN_FL
Definition: window_menu.h:18
WINDOW_EVENT_CHANGING
#define WINDOW_EVENT_CHANGING
Definition: window.h:48
_window_menu_item_t::label
char label[23]
Definition: window_menu.h:59
_window_menu_t::menu_items
window_menu_items_t * menu_items
Definition: window_menu.h:96
window_event_t
void() window_event_t(void *window, uint8_t event, void *param)
Definition: window.h:58
_rect_ui16_t
Definition: guitypes.h:69
WI_LABEL
Definition: window_menu.h:14
render_text_align
void render_text_align(rect_ui16_t rc, const char *text, font_t *font, color_t clr0, color_t clr1, padding_ui8_t padding, uint16_t flags)
Definition: display_helper.c:6
_window_menu_item_t
Definition: window_menu.h:58
uint8_t
const uint8_t[]
Definition: 404_html.c:3
window_menu_inc
void window_menu_inc(window_menu_t *window, int dif)
Definition: window_menu.c:281
display
display_t * display
Definition: display.c:6
_rect_ui16_t::h
uint16_t h
Definition: guitypes.h:73
_window_t::rect
rect_ui16_t rect
Definition: window.h:101
_window_menu_t::color_back
color_t color_back
Definition: window_menu.h:85
_window_menu_t::color_disabled
color_t color_disabled
Definition: window_menu.h:87
WIO_STEP
#define WIO_STEP
Definition: window_menu.c:7
_window_menu_item_t::type
uint16_t type
Definition: window_menu.h:65
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
WINDOW_FLG_FOCUSED
#define WINDOW_FLG_FOCUSED
Definition: window.h:27
_window_menu_t::index
int index
Definition: window_menu.h:93
MIN
#define MIN(a, b)
Definition: window_menu.c:9
window_menu_dec
void window_menu_dec(window_menu_t *window, int dif)
Definition: window_menu.c:315
_window_menu_t::src_param
void * src_param
Definition: window_menu.h:99
WI_SELECT
Definition: window_menu.h:17
_rect_ui16_t::x
uint16_t x
Definition: guitypes.h:70
WI_SWITCH_SELECT_t::index
int32_t index
Definition: window_menu.h:54
color_t
uint32_t color_t
Definition: guitypes.h:62
window_init_t
void() window_init_t(void *window)
Definition: window.h:55
gui_defaults
gui_defaults_t gui_defaults
Definition: gui.c:20
render_icon_align
void render_icon_align(rect_ui16_t rc, uint16_t id_res, color_t clr0, uint16_t flags)
Definition: display_helper.c:55
WINDOW_EVENT_BTN_DN
#define WINDOW_EVENT_BTN_DN
Definition: window.h:38
_window_menu_item_t::id_icon
uint16_t id_icon
Definition: window_menu.h:60
WIO_MIN
#define WIO_MIN
Definition: window_menu.c:5
_window_menu_t::top_index
int top_index
Definition: window_menu.h:94
_window_menu_item_t::wi_switch_select
WI_SWITCH_SELECT_t wi_switch_select
Definition: window_menu.h:70
_gui_defaults_t::alignment
uint8_t alignment
Definition: guitypes.h:113
_window_menu_draw_value
void _window_menu_draw_value(window_menu_t *window, const char *value, rect_ui16_t *p_rc, color_t color_text_option, color_t color_back)
Definition: window_menu.c:62
window_menu_calculate_spin
void window_menu_calculate_spin(WI_SPIN_t *item, char *value)
Definition: window_menu.c:48
_window_t::flg
uint32_t flg
Definition: window.h:81
screen_dispatch_event
void screen_dispatch_event(window_t *window, uint8_t event, void *param)
Definition: screen.c:103
_window_menu_t::win
window_t win
Definition: window_menu.h:84
WINDOW_FLG_INVALID
#define WINDOW_FLG_INVALID
Definition: window.h:26
WINDOW_FLG_ENABLED
#define WINDOW_FLG_ENABLED
Definition: window.h:25
window_menu_event
void window_menu_event(window_menu_t *window, uint8_t event, void *param)
Definition: window_menu.c:161
_window_invalidate
static void _window_invalidate(window_t *window)
Definition: window.h:257
_window_menu_item_t::wi_spin
WI_SPIN_t wi_spin
Definition: window_menu.h:68
WINDOW_EVENT_ENC_DN
#define WINDOW_EVENT_ENC_DN
Definition: window.h:40
_window_menu_t::count
int count
Definition: window_menu.h:92
size
static png_bytep size_t size
Definition: pngwrite.c:2170
window_menu_item_switch
void window_menu_item_switch(window_menu_t *window)
Definition: window_menu.c:242