mui_u8g2.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243
  1. /*
  2. mui_u8g2.c
  3. Monochrome minimal user interface: Glue code between mui and u8g2.
  4. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  5. Copyright (c) 2021, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /*
  29. field function naming convention
  30. action
  31. draw_text: (rename from draw label)
  32. draw_str:
  33. btn_jmp button jump to: a button which jumps to a specific form
  34. btn_exit button leave: a button which leaves the form and places an exit code into a uint8 variable
  35. u8_value_0_9
  36. u8_chkbox
  37. u8_radio
  38. u8_opt_line edit value options in the same line
  39. u8_opt_parent edit value options parent
  40. u8_opt_child edit value options child
  41. field width (not for draw text/str)
  42. wm minimum width
  43. wa width can be provided via FDS argument
  44. w1 full display width
  45. w2 half display size (minus some pixel)
  46. w3 one/third of the dispay width (minus some pixel)
  47. edit mode (not for draw text/str, buttons and checkbox)
  48. mse select: select event will increment the value or activate the field (buttons)
  49. mud up/down: select will enter the up/down edit mode. Next/prev event will increment/decrement the value
  50. styles (not for draw text/str)
  51. unselected selected up/down edit postfix Use for
  52. plain invers invers + gap + frame pi input elements
  53. frame invers+frame frame fi buttons
  54. plain frame invers + frame pf input elements
  55. invers frame invers + frame if buttons
  56. mui_u8g2_[action]_[field_width]_[edit_mode]_[style]
  57. mui _label_u8g2 --> mui_u8g2_draw_text
  58. mui _goto_frame_button_invers_select_u8g2 --> mui_u8g2_btn_goto_wm_fi
  59. mui _goto_half_width_frame_button_invers_select_u8g2 --> mui_u8g2_btn_goto_w2_fi
  60. mui _goto_line_button_invers_select_u8g2 --> mui_u8g2_btn_goto_w1_fi
  61. mui _leave_menu_frame_button_invers_select_u8g2 --> mui_u8g2_btn_exit_wm_fi
  62. mui _input_uint8_invers_select_u8g2 --> mui_u8g2_u8_value_0_9_wm_mse_pi
  63. mui _single_line_option_invers_select_u8g2 --> mui_u8g2_u8_opt_line_wa_mse_pi
  64. mui _select_options_parent_invers_select_u8g2 --> mui_u8g2_u8_opt_parent_wa_mse_pi
  65. mui _select_options_child_invers_select_u8g2 --> mui_u8g2_u8_opt_child_wm_pi
  66. mui _checkbox_invers_select_u8g2 --> mui_u8g2_u8_chkbox_wm_pi
  67. mui _radio_invers_select_u8g2 --> mui_u8g2_u8_radio_wm_pi
  68. mui _input_char_invers_select_u8g2 --> mui_u8g2_u8_char_wm_mud_pi
  69. 2 Buttons
  70. Only use "mse", don't use "mud"
  71. Button Call Description
  72. 1 mui_SendSelect() Activate elements & change values
  73. 2 mui_NextField() Goto next field
  74. 3 Buttons
  75. Use "mse" or "mud"
  76. Button Call Description
  77. 1 mui_SendSelect() Activate elements / change values (mse) / enter "mud" mode (mud)
  78. 2 mui_NextField() Goto next field, increment value (mud)
  79. 3 mui_PrevField() Goto prev field, decrement value (mud)
  80. 4 Buttons
  81. Prefer "mse"
  82. Button Call Description
  83. 1 mui_SendValueIncrement() Activate elements / increment values (mse)
  84. 2 mui_SendValueDecrement() Activate elements / decrement values (mse)
  85. 3 mui_NextField() Goto next field
  86. 4 mui_PrevField() Goto prev field
  87. 5 Buttons
  88. Prefer "mse", use the MUIF_EXECUTE_ON_SELECT_BUTTON on forms to finish the form with the "form select" button 5
  89. Button Call Description
  90. 1 mui_SendValueIncrement() Activate elements / increment values (mse)
  91. 2 mui_SendValueDecrement() Activate elements / decrement values (mse)
  92. 3 mui_NextField() Goto next field
  93. 4 mui_PrevField() Goto prev field
  94. 5 mui_SendSelectWithExecuteOnSelectFieldSearch() Execute the MUIF_EXECUTE_ON_SELECT_BUTTON button or activate the current element if there is no EOS button
  95. rotary encoder, push&release
  96. Prefer "mud"
  97. Button Call Description
  98. encoder button mui_SendSelect() Activate elements / change values (mse) / enter "mud" mode (mud)
  99. encoder CW mui_NextField() Goto next field, increment value (mud)
  100. encoder CCW mui_PrevField() Goto prev field, decrement value (mud)
  101. rotary encoder, push&rotate
  102. Prefer "mse"
  103. Button Call Description
  104. encoder CW mui_SendValueIncrement() Activate elements / increment values (mse)
  105. encoder CCW mui_SendValueDecrement() Activate elements / decrement values (mse)
  106. encoder CW+button press mui_NextField() Goto next field
  107. encoder CCW+button press mui_PrevField() Goto prev field
  108. */
  109. #include "mui.h"
  110. #include "u8g2.h"
  111. #include "mui_u8g2.h"
  112. /*
  113. uint8_t mui_template(mui_t *ui, uint8_t msg)
  114. {
  115. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  116. //ui->dflags MUIF_DFLAG_IS_CURSOR_FOCUS MUIF_DFLAG_IS_TOUCH_FOCUS
  117. //muif_get_cflags(ui->uif) MUIF_CFLAG_IS_CURSOR_SELECTABLE
  118. //muif_get_data(ui->uif)
  119. switch(msg)
  120. {
  121. case MUIF_MSG_DRAW:
  122. break;
  123. case MUIF_MSG_FORM_START:
  124. break;
  125. case MUIF_MSG_FORM_END:
  126. break;
  127. case MUIF_MSG_CURSOR_ENTER:
  128. break;
  129. case MUIF_MSG_CURSOR_SELECT:
  130. break;
  131. case MUIF_MSG_CURSOR_LEAVE:
  132. break;
  133. case MUIF_MSG_VALUE_INCREMENT:
  134. break;
  135. case MUIF_MSG_VALUE_DECREMENT:
  136. break;
  137. case MUIF_MSG_TOUCH_DOWN:
  138. break;
  139. case MUIF_MSG_TOUCH_UP:
  140. break;
  141. }
  142. return 0;
  143. }
  144. */
  145. /*=========================================================================*/
  146. #define MUI_U8G2_V_PADDING 1
  147. /*=========================================================================*/
  148. /* extra u8g2 drawing functions */
  149. static void u8g2_DrawCheckbox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked) MUI_NOINLINE;
  150. static void u8g2_DrawCheckbox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked)
  151. {
  152. u8g2_DrawFrame(u8g2, x, y-w, w, w);
  153. if ( is_checked )
  154. {
  155. w-=4;
  156. u8g2_DrawBox(u8g2, x+2, y-w-2, w, w);
  157. }
  158. }
  159. static void u8g2_DrawValueMark(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w)
  160. {
  161. u8g2_DrawBox(u8g2, x, y-w, w, w);
  162. }
  163. /*=========================================================================*/
  164. /* helper function */
  165. u8g2_uint_t mui_get_x(mui_t *ui) MUI_NOINLINE;
  166. u8g2_uint_t mui_get_x(mui_t *ui)
  167. {
  168. if ( u8g2_GetDisplayWidth(mui_get_U8g2(ui)) >= 255 )
  169. return ui->x * 2;
  170. return ui->x;
  171. }
  172. u8g2_uint_t mui_get_y(mui_t *ui)
  173. {
  174. return ui->y;
  175. }
  176. u8g2_t *mui_get_U8g2(mui_t *ui)
  177. {
  178. return (u8g2_t *)(ui->graphics_data);
  179. }
  180. //void u8g2_DrawButtonUTF8(u8g2_t *u8g2, 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);
  181. void mui_u8g2_draw_button_utf(mui_t *ui, u8g2_uint_t flags, u8g2_uint_t width, u8g2_uint_t padding_h, u8g2_uint_t padding_v, const char *text)
  182. {
  183. if ( text==NULL)
  184. text = "";
  185. u8g2_DrawButtonUTF8(mui_get_U8g2(ui), mui_get_x(ui), mui_get_y(ui), flags, width, padding_h, padding_v, text);
  186. }
  187. u8g2_uint_t mui_u8g2_get_pi_flags(mui_t *ui)
  188. {
  189. u8g2_uint_t flags = 0;
  190. if ( mui_IsCursorFocus(ui) )
  191. {
  192. flags |= U8G2_BTN_INV;
  193. if ( ui->is_mud )
  194. {
  195. flags |= U8G2_BTN_XFRAME;
  196. }
  197. }
  198. return flags;
  199. }
  200. void mui_u8g2_draw_button_pi(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  201. {
  202. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  203. }
  204. u8g2_uint_t mui_u8g2_get_fi_flags(mui_t *ui)
  205. {
  206. u8g2_uint_t flags = 1;
  207. if ( mui_IsCursorFocus(ui) )
  208. {
  209. flags |= U8G2_BTN_INV;
  210. if ( ui->is_mud )
  211. {
  212. flags = 1; // undo INV
  213. }
  214. }
  215. return flags;
  216. }
  217. void mui_u8g2_draw_button_fi(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  218. {
  219. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_fi_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  220. }
  221. u8g2_uint_t mui_u8g2_get_pf_flags(mui_t *ui)
  222. {
  223. u8g2_uint_t flags = 0;
  224. if ( mui_IsCursorFocus(ui) )
  225. {
  226. flags |= 1;
  227. if ( ui->is_mud )
  228. {
  229. flags |= U8G2_BTN_INV;
  230. }
  231. }
  232. return flags;
  233. }
  234. void mui_u8g2_draw_button_pf(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  235. {
  236. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pf_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  237. }
  238. u8g2_uint_t mui_u8g2_get_if_flags(mui_t *ui)
  239. {
  240. u8g2_uint_t flags = 0;
  241. if ( mui_IsCursorFocus(ui) )
  242. {
  243. if ( ui->is_mud )
  244. {
  245. flags |= 1;
  246. flags |= U8G2_BTN_INV;
  247. }
  248. else
  249. {
  250. flags |= 1;
  251. }
  252. }
  253. else
  254. {
  255. flags |= U8G2_BTN_INV;
  256. }
  257. return flags;
  258. }
  259. void mui_u8g2_draw_button_if(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  260. {
  261. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_if_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  262. }
  263. static uint8_t mui_u8g2_handle_scroll_next_prev_events(mui_t *ui, uint8_t msg) MUI_NOINLINE;
  264. static uint8_t mui_u8g2_handle_scroll_next_prev_events(mui_t *ui, uint8_t msg)
  265. {
  266. uint8_t arg = ui->arg;
  267. switch(msg)
  268. {
  269. case MUIF_MSG_CURSOR_ENTER:
  270. if ( (arg > 0) && (ui->form_scroll_top + arg >= ui->form_scroll_total) )
  271. return 255;
  272. break;
  273. case MUIF_MSG_EVENT_NEXT:
  274. if ( arg+1 == ui->form_scroll_visible )
  275. {
  276. if ( ui->form_scroll_visible + ui->form_scroll_top < ui->form_scroll_total )
  277. {
  278. ui->form_scroll_top++;
  279. return 1;
  280. }
  281. else
  282. {
  283. ui->form_scroll_top = 0;
  284. }
  285. }
  286. break;
  287. case MUIF_MSG_EVENT_PREV:
  288. if ( arg == 0 )
  289. {
  290. if ( ui->form_scroll_top > 0 )
  291. {
  292. ui->form_scroll_top--;
  293. return 1;
  294. }
  295. else
  296. {
  297. if ( ui->form_scroll_total > ui->form_scroll_visible )
  298. {
  299. ui->form_scroll_top = ui->form_scroll_total - ui->form_scroll_visible;
  300. }
  301. else
  302. {
  303. ui->form_scroll_top = 0;
  304. }
  305. }
  306. }
  307. break;
  308. }
  309. return 0;
  310. }
  311. /*=========================================================================*/
  312. /* simplified style function */
  313. /*
  314. Used for MUIF_U8G2_FONT_STYLE(n,font)
  315. */
  316. uint8_t mui_u8g2_set_font_style_function(mui_t *ui, uint8_t msg)
  317. {
  318. if ( msg == MUIF_MSG_DRAW )
  319. {
  320. u8g2_SetFont(mui_get_U8g2(ui), (uint8_t *)muif_get_data(ui->uif));
  321. }
  322. return 0;
  323. }
  324. /*=========================================================================*/
  325. /* field functions */
  326. /*
  327. xy: yes, arg: no, text: yes
  328. */
  329. uint8_t mui_u8g2_draw_text(mui_t *ui, uint8_t msg)
  330. {
  331. switch(msg)
  332. {
  333. case MUIF_MSG_DRAW:
  334. u8g2_DrawUTF8(mui_get_U8g2(ui), mui_get_x(ui), mui_get_y(ui), ui->text);
  335. break;
  336. case MUIF_MSG_FORM_START:
  337. break;
  338. case MUIF_MSG_FORM_END:
  339. break;
  340. case MUIF_MSG_CURSOR_ENTER:
  341. break;
  342. case MUIF_MSG_CURSOR_SELECT:
  343. break;
  344. case MUIF_MSG_VALUE_INCREMENT:
  345. break;
  346. case MUIF_MSG_VALUE_DECREMENT:
  347. break;
  348. case MUIF_MSG_CURSOR_LEAVE:
  349. break;
  350. case MUIF_MSG_TOUCH_DOWN:
  351. break;
  352. case MUIF_MSG_TOUCH_UP:
  353. break;
  354. }
  355. return 0;
  356. }
  357. /*
  358. uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg)
  359. Description:
  360. A button with size equal to button text plus one pixel padding
  361. The button has a one pixel frame around the text.
  362. If the selected, then the form will change to the specified form number.
  363. Message Handling: DRAW, CURSOR_SELECT
  364. Style
  365. No Selection: Text + Frame
  366. Cursor Selection: Inverted text + Frame
  367. User interface field list (muif):
  368. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  369. data: not used
  370. Field definition string (fds):
  371. xy: Left position of the text (required)
  372. arg: Form numner (required)
  373. text: Button label
  374. */
  375. uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg)
  376. {
  377. switch(msg)
  378. {
  379. case MUIF_MSG_DRAW:
  380. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_fi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  381. break;
  382. case MUIF_MSG_FORM_START:
  383. break;
  384. case MUIF_MSG_FORM_END:
  385. break;
  386. case MUIF_MSG_CURSOR_ENTER:
  387. break;
  388. case MUIF_MSG_CURSOR_SELECT:
  389. case MUIF_MSG_VALUE_INCREMENT:
  390. case MUIF_MSG_VALUE_DECREMENT:
  391. //return mui_GotoForm(ui, ui->arg, 0);
  392. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  393. case MUIF_MSG_CURSOR_LEAVE:
  394. break;
  395. case MUIF_MSG_TOUCH_DOWN:
  396. break;
  397. case MUIF_MSG_TOUCH_UP:
  398. break;
  399. }
  400. return 0;
  401. }
  402. uint8_t mui_u8g2_btn_goto_wm_if(mui_t *ui, uint8_t msg)
  403. {
  404. switch(msg)
  405. {
  406. case MUIF_MSG_DRAW:
  407. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_if_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  408. break;
  409. case MUIF_MSG_FORM_START:
  410. break;
  411. case MUIF_MSG_FORM_END:
  412. break;
  413. case MUIF_MSG_CURSOR_ENTER:
  414. break;
  415. case MUIF_MSG_CURSOR_SELECT:
  416. case MUIF_MSG_VALUE_INCREMENT:
  417. case MUIF_MSG_VALUE_DECREMENT:
  418. //return mui_GotoForm(ui, ui->arg, 0);
  419. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  420. case MUIF_MSG_CURSOR_LEAVE:
  421. break;
  422. case MUIF_MSG_TOUCH_DOWN:
  423. break;
  424. case MUIF_MSG_TOUCH_UP:
  425. break;
  426. }
  427. return 0;
  428. }
  429. uint8_t mui_u8g2_btn_goto_w2_fi(mui_t *ui, uint8_t msg)
  430. {
  431. u8g2_t *u8g2 = mui_get_U8g2(ui);
  432. switch(msg)
  433. {
  434. case MUIF_MSG_DRAW:
  435. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER | mui_u8g2_get_fi_flags(ui), u8g2_GetDisplayWidth(u8g2)/2 - 10, 0, MUI_U8G2_V_PADDING, ui->text);
  436. break;
  437. case MUIF_MSG_FORM_START:
  438. break;
  439. case MUIF_MSG_FORM_END:
  440. break;
  441. case MUIF_MSG_CURSOR_ENTER:
  442. break;
  443. case MUIF_MSG_CURSOR_SELECT:
  444. case MUIF_MSG_VALUE_INCREMENT:
  445. case MUIF_MSG_VALUE_DECREMENT:
  446. //return mui_GotoForm(ui, ui->arg, 0);
  447. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  448. case MUIF_MSG_CURSOR_LEAVE:
  449. break;
  450. case MUIF_MSG_TOUCH_DOWN:
  451. break;
  452. case MUIF_MSG_TOUCH_UP:
  453. break;
  454. }
  455. return 0;
  456. }
  457. uint8_t mui_u8g2_btn_goto_w2_if(mui_t *ui, uint8_t msg)
  458. {
  459. u8g2_t *u8g2 = mui_get_U8g2(ui);
  460. switch(msg)
  461. {
  462. case MUIF_MSG_DRAW:
  463. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER | mui_u8g2_get_if_flags(ui), u8g2_GetDisplayWidth(u8g2)/2 - 10, 0, MUI_U8G2_V_PADDING, ui->text);
  464. break;
  465. case MUIF_MSG_FORM_START:
  466. break;
  467. case MUIF_MSG_FORM_END:
  468. break;
  469. case MUIF_MSG_CURSOR_ENTER:
  470. break;
  471. case MUIF_MSG_CURSOR_SELECT:
  472. case MUIF_MSG_VALUE_INCREMENT:
  473. case MUIF_MSG_VALUE_DECREMENT:
  474. //return mui_GotoForm(ui, ui->arg, 0);
  475. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  476. case MUIF_MSG_CURSOR_LEAVE:
  477. break;
  478. case MUIF_MSG_TOUCH_DOWN:
  479. break;
  480. case MUIF_MSG_TOUCH_UP:
  481. break;
  482. }
  483. return 0;
  484. }
  485. /*
  486. uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg)
  487. Description:
  488. A button with size equal to button text plus one pixel padding
  489. The button has a one pixel frame around the text.
  490. If selected, then the menu system will be closed.
  491. The arg value will be stored at the specified data location (if not NULL).
  492. The arg value can be used as an exit value of the button.
  493. Message Handling: DRAW, CURSOR_SELECT
  494. Style
  495. No Selection: Text + Frame
  496. Cursor Selection: Inverted text + Frame
  497. User interface field list (muif):
  498. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  499. data: Optionally points to uint8_t value which will receive the arg value of the field.
  500. Field definition string (fds):
  501. xy: Left position of the text (required)
  502. arg: Value which will be stored at *data (optional)
  503. text: Button label
  504. */
  505. uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg)
  506. {
  507. switch(msg)
  508. {
  509. case MUIF_MSG_DRAW:
  510. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_fi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  511. break;
  512. case MUIF_MSG_FORM_START:
  513. break;
  514. case MUIF_MSG_FORM_END:
  515. break;
  516. case MUIF_MSG_CURSOR_ENTER:
  517. break;
  518. case MUIF_MSG_CURSOR_SELECT:
  519. case MUIF_MSG_VALUE_INCREMENT:
  520. case MUIF_MSG_VALUE_DECREMENT:
  521. {
  522. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  523. if ( value != NULL )
  524. *value = ui->arg;
  525. }
  526. mui_SaveForm(ui); // store the current form and position so that the child can jump back
  527. mui_LeaveForm(ui);
  528. return 1;
  529. case MUIF_MSG_CURSOR_LEAVE:
  530. break;
  531. case MUIF_MSG_TOUCH_DOWN:
  532. break;
  533. case MUIF_MSG_TOUCH_UP:
  534. break;
  535. }
  536. return 0;
  537. }
  538. uint8_t mui_u8g2_btn_goto_w1_pi(mui_t *ui, uint8_t msg)
  539. {
  540. u8g2_t *u8g2 = mui_get_U8g2(ui);
  541. switch(msg)
  542. {
  543. case MUIF_MSG_DRAW:
  544. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) , ui->text);
  545. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) , MUI_U8G2_V_PADDING, ui->text);
  546. break;
  547. case MUIF_MSG_FORM_START:
  548. break;
  549. case MUIF_MSG_FORM_END:
  550. break;
  551. case MUIF_MSG_CURSOR_ENTER:
  552. break;
  553. case MUIF_MSG_CURSOR_SELECT:
  554. case MUIF_MSG_VALUE_INCREMENT:
  555. case MUIF_MSG_VALUE_DECREMENT:
  556. //return mui_GotoForm(ui, ui->arg, 0);
  557. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  558. case MUIF_MSG_CURSOR_LEAVE:
  559. break;
  560. case MUIF_MSG_TOUCH_DOWN:
  561. break;
  562. case MUIF_MSG_TOUCH_UP:
  563. break;
  564. }
  565. return 0;
  566. }
  567. uint8_t mui_u8g2_btn_goto_w1_fi(mui_t *ui, uint8_t msg)
  568. {
  569. u8g2_t *u8g2 = mui_get_U8g2(ui);
  570. switch(msg)
  571. {
  572. case MUIF_MSG_DRAW:
  573. mui_u8g2_draw_button_fi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui)-1 , ui->text);
  574. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) , MUI_U8G2_V_PADDING, ui->text);
  575. break;
  576. case MUIF_MSG_FORM_START:
  577. break;
  578. case MUIF_MSG_FORM_END:
  579. break;
  580. case MUIF_MSG_CURSOR_ENTER:
  581. break;
  582. case MUIF_MSG_CURSOR_SELECT:
  583. case MUIF_MSG_VALUE_INCREMENT:
  584. case MUIF_MSG_VALUE_DECREMENT:
  585. //return mui_GotoForm(ui, ui->arg, 0);
  586. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  587. case MUIF_MSG_CURSOR_LEAVE:
  588. break;
  589. case MUIF_MSG_TOUCH_DOWN:
  590. break;
  591. case MUIF_MSG_TOUCH_UP:
  592. break;
  593. }
  594. return 0;
  595. }
  596. /*===============================================================================*/
  597. static void mui_u8g2_u8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
  598. static void mui_u8g2_u8_vmm_draw_wm_pi(mui_t *ui)
  599. {
  600. u8g2_t *u8g2 = mui_get_U8g2(ui);
  601. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  602. char buf[4] = "999";
  603. char *s = buf;
  604. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  605. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  606. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  607. uint8_t cnt = 3;
  608. if ( *value > max )
  609. *value = max;
  610. if ( *value <= min )
  611. *value = min;
  612. if ( max < 100 )
  613. {
  614. s++;
  615. cnt--;
  616. }
  617. if ( max < 10 )
  618. {
  619. s++;
  620. cnt--;
  621. }
  622. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetStrWidth(u8g2, s)+1, 1, MUI_U8G2_V_PADDING, u8x8_u8toa(*value, cnt));
  623. mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u8toa(*value, cnt));
  624. }
  625. uint8_t mui_u8g2_u8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg)
  626. {
  627. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  628. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  629. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  630. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  631. switch(msg)
  632. {
  633. case MUIF_MSG_DRAW:
  634. mui_u8g2_u8_vmm_draw_wm_pi(ui);
  635. break;
  636. case MUIF_MSG_FORM_START:
  637. break;
  638. case MUIF_MSG_FORM_END:
  639. break;
  640. case MUIF_MSG_CURSOR_ENTER:
  641. break;
  642. case MUIF_MSG_CURSOR_SELECT:
  643. case MUIF_MSG_VALUE_INCREMENT:
  644. (*value)++;
  645. if ( *value > max ) *value = min;
  646. break;
  647. case MUIF_MSG_VALUE_DECREMENT:
  648. if ( *value > min ) (*value)--; else *value = max;
  649. break;
  650. case MUIF_MSG_CURSOR_LEAVE:
  651. break;
  652. case MUIF_MSG_TOUCH_DOWN:
  653. break;
  654. case MUIF_MSG_TOUCH_UP:
  655. break;
  656. }
  657. return 0;
  658. }
  659. uint8_t mui_u8g2_u8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg)
  660. {
  661. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  662. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  663. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  664. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  665. switch(msg)
  666. {
  667. case MUIF_MSG_DRAW:
  668. mui_u8g2_u8_vmm_draw_wm_pi(ui);
  669. break;
  670. case MUIF_MSG_FORM_START:
  671. break;
  672. case MUIF_MSG_FORM_END:
  673. break;
  674. case MUIF_MSG_CURSOR_ENTER:
  675. break;
  676. case MUIF_MSG_CURSOR_SELECT:
  677. case MUIF_MSG_VALUE_INCREMENT:
  678. case MUIF_MSG_VALUE_DECREMENT:
  679. /* toggle between normal mode and capture next/prev mode */
  680. ui->is_mud = !ui->is_mud;
  681. break;
  682. case MUIF_MSG_CURSOR_LEAVE:
  683. break;
  684. case MUIF_MSG_TOUCH_DOWN:
  685. break;
  686. case MUIF_MSG_TOUCH_UP:
  687. break;
  688. case MUIF_MSG_EVENT_NEXT:
  689. if ( ui->is_mud )
  690. {
  691. (*value)++;
  692. if ( *value > max )
  693. *value = min;
  694. return 1;
  695. }
  696. break;
  697. case MUIF_MSG_EVENT_PREV:
  698. if ( ui->is_mud )
  699. {
  700. if ( *value <= min )
  701. *value = max;
  702. else
  703. (*value)--;
  704. return 1;
  705. }
  706. break;
  707. }
  708. return 0;
  709. }
  710. static void mui_u8g2_u8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
  711. static void mui_u8g2_u8_vmm_draw_wm_pf(mui_t *ui)
  712. {
  713. u8g2_t *u8g2 = mui_get_U8g2(ui);
  714. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  715. char buf[4] = "999";
  716. char *s = buf;
  717. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  718. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  719. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  720. uint8_t cnt = 3;
  721. if ( *value > max )
  722. *value = max;
  723. if ( *value <= min )
  724. *value = min;
  725. if ( max < 100 )
  726. {
  727. s++;
  728. cnt--;
  729. }
  730. if ( max < 10 )
  731. {
  732. s++;
  733. cnt--;
  734. }
  735. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetStrWidth(u8g2, s)+1, 1, MUI_U8G2_V_PADDING, u8x8_u8toa(*value, cnt));
  736. mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u8toa(*value, cnt));
  737. }
  738. uint8_t mui_u8g2_u8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg)
  739. {
  740. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  741. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  742. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  743. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  744. switch(msg)
  745. {
  746. case MUIF_MSG_DRAW:
  747. mui_u8g2_u8_vmm_draw_wm_pf(ui);
  748. break;
  749. case MUIF_MSG_FORM_START:
  750. break;
  751. case MUIF_MSG_FORM_END:
  752. break;
  753. case MUIF_MSG_CURSOR_ENTER:
  754. break;
  755. case MUIF_MSG_CURSOR_SELECT:
  756. case MUIF_MSG_VALUE_INCREMENT:
  757. (*value)++;
  758. if ( *value > max ) *value = min;
  759. break;
  760. case MUIF_MSG_VALUE_DECREMENT:
  761. if ( *value > min ) (*value)--; else *value = max;
  762. break;
  763. case MUIF_MSG_CURSOR_LEAVE:
  764. break;
  765. case MUIF_MSG_TOUCH_DOWN:
  766. break;
  767. case MUIF_MSG_TOUCH_UP:
  768. break;
  769. }
  770. return 0;
  771. }
  772. uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg)
  773. {
  774. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  775. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  776. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  777. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  778. switch(msg)
  779. {
  780. case MUIF_MSG_DRAW:
  781. mui_u8g2_u8_vmm_draw_wm_pf(ui);
  782. break;
  783. case MUIF_MSG_FORM_START:
  784. break;
  785. case MUIF_MSG_FORM_END:
  786. break;
  787. case MUIF_MSG_CURSOR_ENTER:
  788. break;
  789. case MUIF_MSG_CURSOR_SELECT:
  790. case MUIF_MSG_VALUE_INCREMENT:
  791. case MUIF_MSG_VALUE_DECREMENT:
  792. /* toggle between normal mode and capture next/prev mode */
  793. ui->is_mud = !ui->is_mud;
  794. break;
  795. case MUIF_MSG_CURSOR_LEAVE:
  796. break;
  797. case MUIF_MSG_TOUCH_DOWN:
  798. break;
  799. case MUIF_MSG_TOUCH_UP:
  800. break;
  801. case MUIF_MSG_EVENT_NEXT:
  802. if ( ui->is_mud )
  803. {
  804. (*value)++;
  805. if ( *value > max )
  806. *value = min;
  807. return 1;
  808. }
  809. break;
  810. case MUIF_MSG_EVENT_PREV:
  811. if ( ui->is_mud )
  812. {
  813. if ( *value <= min )
  814. *value = max;
  815. else
  816. (*value)--;
  817. return 1;
  818. }
  819. break;
  820. }
  821. return 0;
  822. }
  823. /*===============================================================================*/
  824. static uint8_t mui_u8g2_u8_bar_mse_msg_handler(mui_t *ui, uint8_t msg) MUI_NOINLINE;
  825. static uint8_t mui_u8g2_u8_bar_mse_msg_handler(mui_t *ui, uint8_t msg)
  826. {
  827. mui_u8g2_u8_min_max_step_t *vmms= (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
  828. uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
  829. uint8_t min = mui_u8g2_u8mms_get_min(vmms);
  830. uint8_t max = mui_u8g2_u8mms_get_max(vmms);
  831. uint8_t step = mui_u8g2_u8mms_get_step(vmms);
  832. uint8_t flags = mui_u8g2_u8mms_get_flags(vmms);
  833. switch(msg)
  834. {
  835. case MUIF_MSG_DRAW:
  836. break;
  837. case MUIF_MSG_FORM_START:
  838. break;
  839. case MUIF_MSG_FORM_END:
  840. break;
  841. case MUIF_MSG_CURSOR_ENTER:
  842. break;
  843. case MUIF_MSG_CURSOR_SELECT:
  844. case MUIF_MSG_VALUE_INCREMENT:
  845. (*value)+=step;
  846. if ( *value > max )
  847. {
  848. if ( flags & MUI_MMS_NO_WRAP )
  849. *value = max;
  850. else
  851. *value = min;
  852. }
  853. break;
  854. case MUIF_MSG_VALUE_DECREMENT:
  855. if ( *value >= min+step )
  856. (*value)-=step;
  857. else
  858. {
  859. if ( flags & MUI_MMS_NO_WRAP )
  860. *value = min;
  861. else
  862. *value = max;
  863. }
  864. break;
  865. case MUIF_MSG_CURSOR_LEAVE:
  866. break;
  867. case MUIF_MSG_TOUCH_DOWN:
  868. break;
  869. case MUIF_MSG_TOUCH_UP:
  870. break;
  871. }
  872. return 0;
  873. }
  874. static uint8_t mui_u8g2_u8_bar_mud_msg_handler(mui_t *ui, uint8_t msg) MUI_NOINLINE;
  875. static uint8_t mui_u8g2_u8_bar_mud_msg_handler(mui_t *ui, uint8_t msg)
  876. {
  877. mui_u8g2_u8_min_max_step_t *vmms= (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
  878. uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
  879. uint8_t min = mui_u8g2_u8mms_get_min(vmms);
  880. uint8_t max = mui_u8g2_u8mms_get_max(vmms);
  881. uint8_t step = mui_u8g2_u8mms_get_step(vmms);
  882. uint8_t flags = mui_u8g2_u8mms_get_flags(vmms);
  883. switch(msg)
  884. {
  885. case MUIF_MSG_DRAW:
  886. break;
  887. case MUIF_MSG_FORM_START:
  888. break;
  889. case MUIF_MSG_FORM_END:
  890. break;
  891. case MUIF_MSG_CURSOR_ENTER:
  892. break;
  893. case MUIF_MSG_CURSOR_SELECT:
  894. case MUIF_MSG_VALUE_INCREMENT:
  895. case MUIF_MSG_VALUE_DECREMENT:
  896. /* toggle between normal mode and capture next/prev mode */
  897. ui->is_mud = !ui->is_mud;
  898. break;
  899. case MUIF_MSG_CURSOR_LEAVE:
  900. break;
  901. case MUIF_MSG_TOUCH_DOWN:
  902. break;
  903. case MUIF_MSG_TOUCH_UP:
  904. break;
  905. case MUIF_MSG_EVENT_NEXT:
  906. if ( ui->is_mud )
  907. {
  908. (*value)+=step;
  909. if ( *value > max )
  910. {
  911. if ( flags & MUI_MMS_NO_WRAP )
  912. *value = max;
  913. else
  914. *value = min;
  915. }
  916. return 1;
  917. }
  918. break;
  919. case MUIF_MSG_EVENT_PREV:
  920. if ( ui->is_mud )
  921. {
  922. if ( *value <= min || *value > max)
  923. {
  924. if ( flags & MUI_MMS_NO_WRAP )
  925. *value = min;
  926. else
  927. *value = max;
  928. }
  929. else
  930. (*value)-=step;
  931. return 1;
  932. }
  933. break;
  934. }
  935. return 0;
  936. }
  937. static void mui_u8g2_u8_bar_draw_wm(mui_t *ui, uint8_t flags, uint8_t is_fixed_width) MUI_NOINLINE;
  938. static void mui_u8g2_u8_bar_draw_wm(mui_t *ui, uint8_t flags, uint8_t is_fixed_width)
  939. {
  940. u8g2_t *u8g2 = mui_get_U8g2(ui);
  941. mui_u8g2_u8_min_max_step_t *vmms= (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
  942. char buf[4] = "999";
  943. char *s = buf;
  944. uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
  945. uint8_t min = mui_u8g2_u8mms_get_min(vmms);
  946. uint8_t max = mui_u8g2_u8mms_get_max(vmms);
  947. uint8_t scale = 0;
  948. //uint8_t step = mui_u8g2_u8mms_get_step(vmms);
  949. uint8_t mms_flags = mui_u8g2_u8mms_get_flags(vmms);
  950. uint8_t cnt = 3;
  951. uint8_t height = u8g2_GetAscent(u8g2);
  952. int8_t backup_descent;
  953. u8g2_uint_t x = mui_get_x(ui);
  954. u8g2_uint_t w = 0;
  955. u8g2_uint_t v; // the calculated pixel value
  956. if ( mms_flags & MUI_MMS_2X_BAR )
  957. scale |= 1;
  958. if ( mms_flags & MUI_MMS_4X_BAR )
  959. scale |= 2;
  960. if ( *value > max )
  961. *value = max;
  962. if ( *value <= min )
  963. *value = min;
  964. if ( max < 100 )
  965. {
  966. s++;
  967. cnt--;
  968. }
  969. if ( max < 10 )
  970. {
  971. s++;
  972. cnt--;
  973. }
  974. if ( is_fixed_width == 0 )
  975. {
  976. w += (max<<scale); // total width of the bar is derived from the max value
  977. v = (*value)<<scale; // pixel position for the current value
  978. }
  979. else
  980. {
  981. u8g2_uint_t width = mui_u8g2_u8mms_get_width(vmms);
  982. w += (width<<scale); // total width of bar is defined by the width argument
  983. v = ((u8g2_long_t)(*value) * (u8g2_long_t)(width<<scale)) / (u8g2_long_t)max; // u8g2_long_t is int32_t if 16 bit mode is enabled
  984. }
  985. w += 2; // add gap for the frame
  986. u8g2_DrawFrame( u8g2, x, mui_get_y(ui)-height, w, height);
  987. u8g2_DrawBox( u8g2, x+1, mui_get_y(ui)-height+1, v, height-2);
  988. if ( mms_flags & MUI_MMS_SHOW_VALUE )
  989. {
  990. w += 2;
  991. u8g2_DrawStr(u8g2, x+w, mui_get_y(ui), u8x8_u8toa(*value, cnt) );
  992. w += u8g2_GetStrWidth(u8g2, s);
  993. w += 1;
  994. }
  995. backup_descent = u8g2->font_ref_descent;
  996. u8g2->font_ref_descent = 0; /* hmm... that's a low level hack so that DrawButtonFrame ignores the descent value of the font */
  997. u8g2_DrawButtonFrame(u8g2, x, mui_get_y(ui), flags, w, 1, 1);
  998. u8g2->font_ref_descent = backup_descent;
  999. }
  1000. // #define MUIF_U8G2_U8_MIN_MAX_STEP(id, valptr, min, max, step, flags, muif)
  1001. uint8_t mui_u8g2_u8_bar_wm_mse_pi(mui_t *ui, uint8_t msg)
  1002. {
  1003. switch(msg)
  1004. {
  1005. case MUIF_MSG_DRAW:
  1006. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 0);
  1007. break;
  1008. default:
  1009. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1010. }
  1011. return 0;
  1012. }
  1013. uint8_t mui_u8g2_u8_bar_wm_mud_pi(mui_t *ui, uint8_t msg)
  1014. {
  1015. switch(msg)
  1016. {
  1017. case MUIF_MSG_DRAW:
  1018. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 0);
  1019. break;
  1020. default:
  1021. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1022. }
  1023. return 0;
  1024. }
  1025. uint8_t mui_u8g2_u8_bar_wm_mse_pf(mui_t *ui, uint8_t msg)
  1026. {
  1027. switch(msg)
  1028. {
  1029. case MUIF_MSG_DRAW:
  1030. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 0);
  1031. break;
  1032. default:
  1033. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1034. }
  1035. return 0;
  1036. }
  1037. uint8_t mui_u8g2_u8_bar_wm_mud_pf(mui_t *ui, uint8_t msg)
  1038. {
  1039. switch(msg)
  1040. {
  1041. case MUIF_MSG_DRAW:
  1042. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 0);
  1043. break;
  1044. default:
  1045. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1046. }
  1047. return 0;
  1048. }
  1049. // #define MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH(id, valptr, min, max, step, width, flags, muif)
  1050. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mse_pi(mui_t *ui, uint8_t msg)
  1051. {
  1052. switch(msg)
  1053. {
  1054. case MUIF_MSG_DRAW:
  1055. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 1);
  1056. break;
  1057. default:
  1058. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1059. }
  1060. return 0;
  1061. }
  1062. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mud_pi(mui_t *ui, uint8_t msg)
  1063. {
  1064. switch(msg)
  1065. {
  1066. case MUIF_MSG_DRAW:
  1067. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 1);
  1068. break;
  1069. default:
  1070. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1071. }
  1072. return 0;
  1073. }
  1074. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mse_pf(mui_t *ui, uint8_t msg)
  1075. {
  1076. switch(msg)
  1077. {
  1078. case MUIF_MSG_DRAW:
  1079. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 1);
  1080. break;
  1081. default:
  1082. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1083. }
  1084. return 0;
  1085. }
  1086. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mud_pf(mui_t *ui, uint8_t msg)
  1087. {
  1088. switch(msg)
  1089. {
  1090. case MUIF_MSG_DRAW:
  1091. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 1);
  1092. break;
  1093. default:
  1094. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1095. }
  1096. return 0;
  1097. }
  1098. /*===============================================================================*/
  1099. static uint8_t mui_is_valid_char(uint8_t c) MUI_NOINLINE;
  1100. uint8_t mui_is_valid_char(uint8_t c)
  1101. {
  1102. if ( c == 32 )
  1103. return 1;
  1104. if ( c >= 'A' && c <= 'Z' )
  1105. return 1;
  1106. if ( c >= 'a' && c <= 'z' )
  1107. return 1;
  1108. if ( c >= '0' && c <= '9' )
  1109. return 1;
  1110. return 0;
  1111. }
  1112. uint8_t mui_u8g2_u8_char_wm_mud_pi(mui_t *ui, uint8_t msg)
  1113. {
  1114. //ui->dflags MUIF_DFLAG_IS_CURSOR_FOCUS MUIF_DFLAG_IS_TOUCH_FOCUS
  1115. //mui_get_cflags(ui->uif) MUIF_CFLAG_IS_CURSOR_SELECTABLE
  1116. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1117. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1118. char buf[6];
  1119. switch(msg)
  1120. {
  1121. case MUIF_MSG_DRAW:
  1122. while( mui_is_valid_char(*value) == 0 )
  1123. (*value)++;
  1124. buf[0] = *value;
  1125. buf[1] = '\0';
  1126. mui_u8g2_draw_button_pi(ui, u8g2_GetMaxCharWidth(u8g2), 1, buf);
  1127. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetMaxCharWidth(u8g2), 1, MUI_U8G2_V_PADDING, buf);
  1128. //u8g2_DrawButtonUTF8(u8g2, mui_get_x(ui), mui_get_y(ui), mui_u8g2_get_pi_flags(ui), u8g2_GetMaxCharWidth(u8g2), 1, MUI_U8G2_V_PADDING, buf);
  1129. break;
  1130. case MUIF_MSG_FORM_START:
  1131. break;
  1132. case MUIF_MSG_FORM_END:
  1133. break;
  1134. case MUIF_MSG_CURSOR_ENTER:
  1135. break;
  1136. case MUIF_MSG_CURSOR_SELECT:
  1137. case MUIF_MSG_VALUE_INCREMENT:
  1138. case MUIF_MSG_VALUE_DECREMENT:
  1139. /* toggle between normal mode and capture next/prev mode */
  1140. ui->is_mud = !ui->is_mud;
  1141. break;
  1142. case MUIF_MSG_CURSOR_LEAVE:
  1143. break;
  1144. case MUIF_MSG_TOUCH_DOWN:
  1145. break;
  1146. case MUIF_MSG_TOUCH_UP:
  1147. break;
  1148. case MUIF_MSG_EVENT_NEXT:
  1149. if ( ui->is_mud )
  1150. {
  1151. do {
  1152. (*value)++;
  1153. } while( mui_is_valid_char(*value) == 0 );
  1154. return 1;
  1155. }
  1156. break;
  1157. case MUIF_MSG_EVENT_PREV:
  1158. if ( ui->is_mud )
  1159. {
  1160. do {
  1161. (*value)--;
  1162. } while( mui_is_valid_char(*value) == 0 );
  1163. return 1;
  1164. }
  1165. break;
  1166. }
  1167. return 0;
  1168. }
  1169. /*
  1170. uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg)
  1171. Description:
  1172. Select one of several options. First option has value 0.
  1173. Only one option is visible.
  1174. The visible option is automatically the selected option.
  1175. Message Handling: DRAW, SELECT
  1176. Style
  1177. No Selection: Text only
  1178. Cursor Selection: Inverted text
  1179. User interface field list (muif):
  1180. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  1181. data: uint8_t *, pointer to a uint8_t variable, which contains the selected option
  1182. Field definition string (fds):
  1183. xy: Left position of the text (required)
  1184. arg: total width of the selectable option (optional),
  1185. text: '|' separated list of options
  1186. */
  1187. uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg)
  1188. {
  1189. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1190. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1191. switch(msg)
  1192. {
  1193. case MUIF_MSG_DRAW:
  1194. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1195. {
  1196. *value = 0;
  1197. mui_fds_get_nth_token(ui, *value);
  1198. }
  1199. mui_u8g2_draw_button_pi(ui, ui->arg, 1, ui->text);
  1200. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, ui->text);
  1201. //u8g2_DrawButtonUTF8(u8g2, mui_get_x(ui), mui_get_y(ui), mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, ui->text);
  1202. break;
  1203. case MUIF_MSG_FORM_START:
  1204. break;
  1205. case MUIF_MSG_FORM_END:
  1206. break;
  1207. case MUIF_MSG_CURSOR_ENTER:
  1208. break;
  1209. case MUIF_MSG_CURSOR_SELECT:
  1210. case MUIF_MSG_VALUE_INCREMENT:
  1211. (*value)++;
  1212. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1213. *value = 0;
  1214. break;
  1215. case MUIF_MSG_VALUE_DECREMENT:
  1216. if ( *value > 0 )
  1217. (*value)--;
  1218. else
  1219. (*value) = mui_fds_get_token_cnt(ui)-1;
  1220. break;
  1221. case MUIF_MSG_CURSOR_LEAVE:
  1222. break;
  1223. case MUIF_MSG_TOUCH_DOWN:
  1224. break;
  1225. case MUIF_MSG_TOUCH_UP:
  1226. break;
  1227. }
  1228. return 0;
  1229. }
  1230. uint8_t mui_u8g2_u8_opt_line_wa_mse_pf(mui_t *ui, uint8_t msg)
  1231. {
  1232. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1233. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1234. switch(msg)
  1235. {
  1236. case MUIF_MSG_DRAW:
  1237. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1238. {
  1239. *value = 0;
  1240. mui_fds_get_nth_token(ui, *value);
  1241. }
  1242. mui_u8g2_draw_button_pf(ui, ui->arg, 1, ui->text);
  1243. break;
  1244. case MUIF_MSG_FORM_START:
  1245. break;
  1246. case MUIF_MSG_FORM_END:
  1247. break;
  1248. case MUIF_MSG_CURSOR_ENTER:
  1249. break;
  1250. case MUIF_MSG_CURSOR_SELECT:
  1251. case MUIF_MSG_VALUE_INCREMENT:
  1252. (*value)++;
  1253. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1254. *value = 0;
  1255. break;
  1256. case MUIF_MSG_VALUE_DECREMENT:
  1257. if ( *value > 0 )
  1258. (*value)--;
  1259. else
  1260. (*value) = mui_fds_get_token_cnt(ui)-1;
  1261. break;
  1262. case MUIF_MSG_CURSOR_LEAVE:
  1263. break;
  1264. case MUIF_MSG_TOUCH_DOWN:
  1265. break;
  1266. case MUIF_MSG_TOUCH_UP:
  1267. break;
  1268. }
  1269. return 0;
  1270. }
  1271. uint8_t mui_u8g2_u8_opt_line_wa_mud_pi(mui_t *ui, uint8_t msg)
  1272. {
  1273. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1274. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1275. switch(msg)
  1276. {
  1277. case MUIF_MSG_DRAW:
  1278. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1279. {
  1280. *value = 0;
  1281. mui_fds_get_nth_token(ui, *value);
  1282. }
  1283. mui_u8g2_draw_button_pi(ui, ui->arg, 1, ui->text);
  1284. break;
  1285. case MUIF_MSG_FORM_START:
  1286. break;
  1287. case MUIF_MSG_FORM_END:
  1288. break;
  1289. case MUIF_MSG_CURSOR_ENTER:
  1290. break;
  1291. case MUIF_MSG_CURSOR_SELECT:
  1292. case MUIF_MSG_VALUE_INCREMENT:
  1293. case MUIF_MSG_VALUE_DECREMENT:
  1294. /* toggle between normal mode and capture next/prev mode */
  1295. ui->is_mud = !ui->is_mud;
  1296. break;
  1297. case MUIF_MSG_CURSOR_LEAVE:
  1298. break;
  1299. case MUIF_MSG_TOUCH_DOWN:
  1300. break;
  1301. case MUIF_MSG_TOUCH_UP:
  1302. break;
  1303. case MUIF_MSG_EVENT_NEXT:
  1304. if ( ui->is_mud )
  1305. {
  1306. (*value)++;
  1307. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1308. *value = 0;
  1309. return 1;
  1310. }
  1311. break;
  1312. case MUIF_MSG_EVENT_PREV:
  1313. if ( ui->is_mud )
  1314. {
  1315. if ( *value == 0 )
  1316. *value = mui_fds_get_token_cnt(ui);
  1317. (*value)--;
  1318. return 1;
  1319. }
  1320. break;
  1321. }
  1322. return 0;
  1323. }
  1324. uint8_t mui_u8g2_u8_opt_line_wa_mud_pf(mui_t *ui, uint8_t msg)
  1325. {
  1326. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1327. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1328. switch(msg)
  1329. {
  1330. case MUIF_MSG_DRAW:
  1331. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1332. {
  1333. *value = 0;
  1334. mui_fds_get_nth_token(ui, *value);
  1335. }
  1336. mui_u8g2_draw_button_pf(ui, ui->arg, 1, ui->text);
  1337. break;
  1338. case MUIF_MSG_FORM_START:
  1339. break;
  1340. case MUIF_MSG_FORM_END:
  1341. break;
  1342. case MUIF_MSG_CURSOR_ENTER:
  1343. break;
  1344. case MUIF_MSG_CURSOR_SELECT:
  1345. case MUIF_MSG_VALUE_INCREMENT:
  1346. case MUIF_MSG_VALUE_DECREMENT:
  1347. /* toggle between normal mode and capture next/prev mode */
  1348. ui->is_mud = !ui->is_mud;
  1349. break;
  1350. case MUIF_MSG_CURSOR_LEAVE:
  1351. break;
  1352. case MUIF_MSG_TOUCH_DOWN:
  1353. break;
  1354. case MUIF_MSG_TOUCH_UP:
  1355. break;
  1356. case MUIF_MSG_EVENT_NEXT:
  1357. if ( ui->is_mud )
  1358. {
  1359. (*value)++;
  1360. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1361. *value = 0;
  1362. return 1;
  1363. }
  1364. break;
  1365. case MUIF_MSG_EVENT_PREV:
  1366. if ( ui->is_mud )
  1367. {
  1368. if ( *value == 0 )
  1369. *value = mui_fds_get_token_cnt(ui);
  1370. (*value)--;
  1371. return 1;
  1372. }
  1373. break;
  1374. }
  1375. return 0;
  1376. }
  1377. /*
  1378. uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg)
  1379. Description:
  1380. Checkbox with the values 0 (not selected) and 1 (selected).
  1381. Message Handling: DRAW, SELECT
  1382. Style
  1383. No Selection: Plain checkbox and text
  1384. Cursor Selection: Checkbox and text is inverted
  1385. User interface field list (muif):
  1386. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  1387. data: uint8_t *, pointer to a uint8_t variable, which contains the values 0 or 1
  1388. Field definition string (fds):
  1389. xy: Left position of the text (required)
  1390. arg: not used
  1391. text: Optional: Text will be printed after the checkbox with a small gap
  1392. */
  1393. uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg)
  1394. {
  1395. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1396. u8g2_uint_t flags = 0;
  1397. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1398. switch(msg)
  1399. {
  1400. case MUIF_MSG_DRAW:
  1401. if ( *value > 1 ) *value = 1;
  1402. if ( mui_IsCursorFocus(ui) )
  1403. {
  1404. flags |= U8G2_BTN_INV;
  1405. }
  1406. {
  1407. u8g2_uint_t w = 0;
  1408. u8g2_uint_t a = u8g2_GetAscent(u8g2);
  1409. if ( *value )
  1410. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 1);
  1411. else
  1412. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 0);
  1413. if ( ui->text[0] != '\0' )
  1414. {
  1415. w = u8g2_GetUTF8Width(u8g2, ui->text);
  1416. //u8g2_SetFontMode(u8g2, 1);
  1417. a += 2; /* add gap between the checkbox and the text area */
  1418. u8g2_DrawUTF8(u8g2, mui_get_x(ui)+a, mui_get_y(ui), ui->text);
  1419. }
  1420. u8g2_DrawButtonFrame(u8g2, mui_get_x(ui), mui_get_y(ui), flags, w+a, 1, MUI_U8G2_V_PADDING);
  1421. }
  1422. break;
  1423. case MUIF_MSG_FORM_START:
  1424. break;
  1425. case MUIF_MSG_FORM_END:
  1426. break;
  1427. case MUIF_MSG_CURSOR_ENTER:
  1428. break;
  1429. case MUIF_MSG_CURSOR_SELECT:
  1430. case MUIF_MSG_VALUE_INCREMENT:
  1431. case MUIF_MSG_VALUE_DECREMENT:
  1432. (*value)++;
  1433. if ( *value > 1 ) *value = 0;
  1434. break;
  1435. case MUIF_MSG_CURSOR_LEAVE:
  1436. break;
  1437. case MUIF_MSG_TOUCH_DOWN:
  1438. break;
  1439. case MUIF_MSG_TOUCH_UP:
  1440. break;
  1441. }
  1442. return 0;
  1443. }
  1444. /*
  1445. radio button style, arg is assigned as value
  1446. */
  1447. uint8_t mui_u8g2_u8_radio_wm_pi(mui_t *ui, uint8_t msg)
  1448. {
  1449. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1450. u8g2_uint_t flags = 0;
  1451. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1452. switch(msg)
  1453. {
  1454. case MUIF_MSG_DRAW:
  1455. if ( mui_IsCursorFocus(ui) )
  1456. {
  1457. flags |= U8G2_BTN_INV;
  1458. }
  1459. {
  1460. u8g2_uint_t w = 0;
  1461. u8g2_uint_t a = u8g2_GetAscent(u8g2);
  1462. if ( *value == ui->arg )
  1463. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 1);
  1464. else
  1465. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 0);
  1466. if ( ui->text[0] != '\0' )
  1467. {
  1468. w = u8g2_GetUTF8Width(u8g2, ui->text);
  1469. //u8g2_SetFontMode(u8g2, 1);
  1470. a += 2; /* add gap between the checkbox and the text area */
  1471. u8g2_DrawUTF8(u8g2, mui_get_x(ui)+a, mui_get_y(ui), ui->text);
  1472. }
  1473. u8g2_DrawButtonFrame(u8g2, mui_get_x(ui), mui_get_y(ui), flags, w+a, 1, MUI_U8G2_V_PADDING);
  1474. }
  1475. break;
  1476. case MUIF_MSG_FORM_START:
  1477. break;
  1478. case MUIF_MSG_FORM_END:
  1479. break;
  1480. case MUIF_MSG_CURSOR_ENTER:
  1481. break;
  1482. case MUIF_MSG_CURSOR_SELECT:
  1483. case MUIF_MSG_VALUE_INCREMENT:
  1484. case MUIF_MSG_VALUE_DECREMENT:
  1485. *value = ui->arg;
  1486. break;
  1487. case MUIF_MSG_CURSOR_LEAVE:
  1488. break;
  1489. case MUIF_MSG_TOUCH_DOWN:
  1490. break;
  1491. case MUIF_MSG_TOUCH_UP:
  1492. break;
  1493. }
  1494. return 0;
  1495. }
  1496. uint8_t mui_u8g2_u8_opt_parent_wm_pi(mui_t *ui, uint8_t msg)
  1497. {
  1498. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1499. switch(msg)
  1500. {
  1501. case MUIF_MSG_DRAW:
  1502. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1503. {
  1504. *value = 0;
  1505. mui_fds_get_nth_token(ui, *value);
  1506. }
  1507. mui_u8g2_draw_button_pi(ui, 0, 1, ui->text);
  1508. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  1509. break;
  1510. case MUIF_MSG_FORM_START:
  1511. break;
  1512. case MUIF_MSG_FORM_END:
  1513. break;
  1514. case MUIF_MSG_CURSOR_ENTER:
  1515. break;
  1516. case MUIF_MSG_CURSOR_SELECT:
  1517. case MUIF_MSG_VALUE_INCREMENT:
  1518. case MUIF_MSG_VALUE_DECREMENT:
  1519. mui_SaveForm(ui); // store the current form and position so that the child can jump back
  1520. mui_GotoForm(ui, ui->arg, *value); // assumes that the selectable values are at the beginning of the form definition
  1521. break;
  1522. case MUIF_MSG_CURSOR_LEAVE:
  1523. break;
  1524. case MUIF_MSG_TOUCH_DOWN:
  1525. break;
  1526. case MUIF_MSG_TOUCH_UP:
  1527. break;
  1528. }
  1529. return 0;
  1530. }
  1531. uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg)
  1532. {
  1533. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1534. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1535. switch(msg)
  1536. {
  1537. case MUIF_MSG_DRAW:
  1538. /* done by the calling function */
  1539. break;
  1540. case MUIF_MSG_FORM_START:
  1541. /* we can assume that the list starts at the top. It will be adjisted by cursor down events later */
  1542. /* ui->form_scroll_top = 0 and all other form_scroll values are set to 0 if a new form is entered in mui_EnterForm() */
  1543. if ( ui->form_scroll_visible <= arg )
  1544. ui->form_scroll_visible = arg+1;
  1545. if ( ui->form_scroll_total == 0 )
  1546. ui->form_scroll_total = mui_GetSelectableFieldOptionCnt(ui, ui->last_form_fds);
  1547. //printf("MUIF_MSG_FORM_START: arg=%d visible=%d top=%d total=%d\n", arg, ui->form_scroll_visible, ui->form_scroll_top, ui->form_scroll_total);
  1548. break;
  1549. case MUIF_MSG_FORM_END:
  1550. break;
  1551. case MUIF_MSG_CURSOR_ENTER:
  1552. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  1553. case MUIF_MSG_CURSOR_SELECT:
  1554. case MUIF_MSG_VALUE_INCREMENT:
  1555. case MUIF_MSG_VALUE_DECREMENT:
  1556. if ( value != NULL )
  1557. *value = ui->form_scroll_top + arg;
  1558. mui_RestoreForm(ui);
  1559. break;
  1560. case MUIF_MSG_CURSOR_LEAVE:
  1561. break;
  1562. case MUIF_MSG_TOUCH_DOWN:
  1563. break;
  1564. case MUIF_MSG_TOUCH_UP:
  1565. break;
  1566. case MUIF_MSG_EVENT_NEXT:
  1567. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  1568. case MUIF_MSG_EVENT_PREV:
  1569. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  1570. }
  1571. return 0;
  1572. }
  1573. uint8_t mui_u8g2_u8_opt_radio_child_wm_pi(mui_t *ui, uint8_t msg)
  1574. {
  1575. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1576. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1577. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1578. switch(msg)
  1579. {
  1580. case MUIF_MSG_DRAW:
  1581. {
  1582. u8g2_uint_t w = 0;
  1583. u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
  1584. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1585. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1586. uint8_t is_focus = mui_IsCursorFocus(ui);
  1587. if ( *value == arg + ui->form_scroll_top )
  1588. u8g2_DrawValueMark(u8g2, x, y, a);
  1589. if ( ui->text[0] == '\0' )
  1590. {
  1591. /* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
  1592. /* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
  1593. mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
  1594. }
  1595. if ( ui->text[0] != '\0' )
  1596. {
  1597. w = u8g2_GetUTF8Width(u8g2, ui->text);
  1598. //u8g2_SetFontMode(u8g2, 1);
  1599. a += 2; /* add gap between the checkbox and the text area */
  1600. u8g2_DrawUTF8(u8g2, x+a, y, ui->text);
  1601. }
  1602. if ( is_focus )
  1603. {
  1604. u8g2_DrawButtonFrame(u8g2, x, y, U8G2_BTN_INV, w+a, 1, MUI_U8G2_V_PADDING);
  1605. }
  1606. }
  1607. break;
  1608. default:
  1609. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  1610. }
  1611. return 0;
  1612. }
  1613. uint8_t mui_u8g2_u8_opt_radio_child_w1_pi(mui_t *ui, uint8_t msg)
  1614. {
  1615. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1616. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1617. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1618. switch(msg)
  1619. {
  1620. case MUIF_MSG_DRAW:
  1621. {
  1622. //u8g2_uint_t w = 0;
  1623. u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
  1624. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1625. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1626. uint8_t is_focus = mui_IsCursorFocus(ui);
  1627. if ( *value == arg + ui->form_scroll_top )
  1628. u8g2_DrawValueMark(u8g2, x, y, a);
  1629. if ( ui->text[0] == '\0' )
  1630. {
  1631. /* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
  1632. /* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
  1633. mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
  1634. }
  1635. if ( ui->text[0] != '\0' )
  1636. {
  1637. //w = u8g2_GetUTF8Width(u8g2, ui->text);
  1638. //u8g2_SetFontMode(u8g2, 1);
  1639. a += 2; /* add gap between the checkbox and the text area */
  1640. u8g2_DrawUTF8(u8g2, x+a, y, ui->text);
  1641. }
  1642. if ( is_focus )
  1643. {
  1644. u8g2_DrawButtonFrame(u8g2, 0, y, U8G2_BTN_INV, u8g2_GetDisplayWidth(u8g2), 0, MUI_U8G2_V_PADDING);
  1645. }
  1646. }
  1647. break;
  1648. default:
  1649. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  1650. }
  1651. return 0;
  1652. }
  1653. uint8_t mui_u8g2_u8_opt_child_wm_pi(mui_t *ui, uint8_t msg)
  1654. {
  1655. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1656. //uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1657. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1658. switch(msg)
  1659. {
  1660. case MUIF_MSG_DRAW:
  1661. {
  1662. //u8g2_uint_t w = 0;
  1663. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1664. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1665. uint8_t flags = mui_u8g2_get_pi_flags(ui);
  1666. //if ( mui_IsCursorFocus(ui) )
  1667. //{
  1668. // flags = U8G2_BTN_INV;
  1669. //}
  1670. if ( ui->text[0] == '\0' )
  1671. {
  1672. /* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
  1673. /* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
  1674. mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
  1675. }
  1676. if ( ui->text[0] != '\0' )
  1677. {
  1678. u8g2_DrawButtonUTF8(u8g2, x, y, flags, 0, 1, MUI_U8G2_V_PADDING, ui->text);
  1679. }
  1680. }
  1681. break;
  1682. default:
  1683. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  1684. }
  1685. return 0;
  1686. }
  1687. /*
  1688. an invisible field (which will not show anything). It should also not be selectable
  1689. it just provides the menu entries, see "mui_u8g2_u8_opt_child_mse_common" and friends
  1690. as a consequence it does not have width, input mode and style
  1691. MUIF: MUIF_RO()
  1692. FDS: MUI_DATA()
  1693. mui_u8g2_goto_parent --> mui_u8g2_goto_data
  1694. Used together with mui_u8g2_goto_form_w1_pi
  1695. */
  1696. uint8_t mui_u8g2_goto_data(mui_t *ui, uint8_t msg)
  1697. {
  1698. switch(msg)
  1699. {
  1700. case MUIF_MSG_DRAW:
  1701. break;
  1702. case MUIF_MSG_FORM_START:
  1703. // store the field (and the corresponding elements) in the last_form_fds variable.
  1704. // last_form_fds is later used to access the elements (see mui_u8g2_u8_opt_child_mse_common and friends)
  1705. ui->last_form_fds = ui->fds;
  1706. break;
  1707. case MUIF_MSG_FORM_END:
  1708. break;
  1709. case MUIF_MSG_CURSOR_ENTER:
  1710. break;
  1711. case MUIF_MSG_CURSOR_SELECT:
  1712. break;
  1713. case MUIF_MSG_CURSOR_LEAVE:
  1714. break;
  1715. case MUIF_MSG_TOUCH_DOWN:
  1716. break;
  1717. case MUIF_MSG_TOUCH_UP:
  1718. break;
  1719. }
  1720. return 0;
  1721. }
  1722. /*
  1723. mui_u8g2_goto_child_w1_mse_pi --> mui_u8g2_goto_form_w1_pi
  1724. */
  1725. uint8_t mui_u8g2_goto_form_w1_pi(mui_t *ui, uint8_t msg)
  1726. {
  1727. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1728. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1729. switch(msg)
  1730. {
  1731. case MUIF_MSG_DRAW:
  1732. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top) )
  1733. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui), ui->text+1);
  1734. break;
  1735. case MUIF_MSG_CURSOR_SELECT:
  1736. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
  1737. {
  1738. mui_SaveCursorPosition(ui, ui->arg + ui->form_scroll_top); // store the current cursor position, so that the user can jump back to the corresponding cursor position
  1739. return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
  1740. }
  1741. break;
  1742. default:
  1743. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  1744. }
  1745. return 0;
  1746. }
  1747. uint8_t mui_u8g2_goto_form_w1_pf(mui_t *ui, uint8_t msg)
  1748. {
  1749. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1750. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1751. switch(msg)
  1752. {
  1753. case MUIF_MSG_DRAW:
  1754. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top) )
  1755. mui_u8g2_draw_button_pf(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui)-1, ui->text+1);
  1756. break;
  1757. case MUIF_MSG_CURSOR_SELECT:
  1758. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
  1759. {
  1760. mui_SaveCursorPosition(ui, ui->arg + ui->form_scroll_top); // store the current cursor position, so that the user can jump back to the corresponding cursor position
  1761. return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
  1762. }
  1763. break;
  1764. default:
  1765. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  1766. }
  1767. return 0;
  1768. }
  1769. /*
  1770. data: mui_u8g2_list_t *
  1771. */
  1772. uint8_t mui_u8g2_u16_list_line_wa_mse_pi(mui_t *ui, uint8_t msg)
  1773. {
  1774. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1775. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  1776. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  1777. void *data = mui_u8g2_list_get_data_ptr(list);
  1778. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  1779. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  1780. switch(msg)
  1781. {
  1782. case MUIF_MSG_DRAW:
  1783. mui_u8g2_draw_button_pi(ui, ui->arg, 1, element_cb(data, *selection));
  1784. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, element_cb(data, *selection));
  1785. break;
  1786. case MUIF_MSG_FORM_START:
  1787. break;
  1788. case MUIF_MSG_FORM_END:
  1789. break;
  1790. case MUIF_MSG_CURSOR_ENTER:
  1791. break;
  1792. case MUIF_MSG_CURSOR_SELECT:
  1793. case MUIF_MSG_VALUE_INCREMENT:
  1794. (*selection)++;
  1795. if ( *selection >= count_cb(data) )
  1796. *selection = 0;
  1797. break;
  1798. case MUIF_MSG_VALUE_DECREMENT:
  1799. if ( *selection > 0 )
  1800. (*selection)--;
  1801. else
  1802. (*selection) = count_cb(data)-1;
  1803. break;
  1804. case MUIF_MSG_CURSOR_LEAVE:
  1805. break;
  1806. case MUIF_MSG_TOUCH_DOWN:
  1807. break;
  1808. case MUIF_MSG_TOUCH_UP:
  1809. break;
  1810. }
  1811. return 0;
  1812. }
  1813. uint8_t mui_u8g2_u16_list_line_wa_mud_pi(mui_t *ui, uint8_t msg)
  1814. {
  1815. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1816. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  1817. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  1818. void *data = mui_u8g2_list_get_data_ptr(list);
  1819. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  1820. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  1821. switch(msg)
  1822. {
  1823. case MUIF_MSG_DRAW:
  1824. mui_u8g2_draw_button_pi(ui, ui->arg, 1, element_cb(data, *selection));
  1825. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, element_cb(data, *selection));
  1826. break;
  1827. case MUIF_MSG_FORM_START:
  1828. break;
  1829. case MUIF_MSG_FORM_END:
  1830. break;
  1831. case MUIF_MSG_CURSOR_ENTER:
  1832. break;
  1833. case MUIF_MSG_CURSOR_SELECT:
  1834. case MUIF_MSG_VALUE_INCREMENT:
  1835. case MUIF_MSG_VALUE_DECREMENT:
  1836. /* toggle between normal mode and capture next/prev mode */
  1837. ui->is_mud = !ui->is_mud;
  1838. break;
  1839. case MUIF_MSG_CURSOR_LEAVE:
  1840. break;
  1841. case MUIF_MSG_TOUCH_DOWN:
  1842. break;
  1843. case MUIF_MSG_TOUCH_UP:
  1844. break;
  1845. case MUIF_MSG_EVENT_NEXT:
  1846. if ( ui->is_mud )
  1847. {
  1848. (*selection)++;
  1849. if ( *selection >= count_cb(data) )
  1850. *selection = 0;
  1851. return 1;
  1852. }
  1853. break;
  1854. case MUIF_MSG_EVENT_PREV:
  1855. if ( ui->is_mud )
  1856. {
  1857. if ( *selection == 0 )
  1858. *selection = count_cb(data);
  1859. (*selection)--;
  1860. return 1;
  1861. }
  1862. break;
  1863. }
  1864. return 0;
  1865. }
  1866. /*
  1867. MUIF: MUIF_U8G2_U16_LIST
  1868. FDS: MUI_XYA, arg=form id
  1869. data: mui_u8g2_list_t *
  1870. */
  1871. uint8_t mui_u8g2_u16_list_parent_wm_pi(mui_t *ui, uint8_t msg)
  1872. {
  1873. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1874. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  1875. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  1876. void *data = mui_u8g2_list_get_data_ptr(list);
  1877. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  1878. //mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  1879. switch(msg)
  1880. {
  1881. case MUIF_MSG_DRAW:
  1882. mui_u8g2_draw_button_pi(ui, 0, 1, element_cb(data, *selection));
  1883. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, element_cb(data, *selection));
  1884. break;
  1885. case MUIF_MSG_FORM_START:
  1886. break;
  1887. case MUIF_MSG_FORM_END:
  1888. break;
  1889. case MUIF_MSG_CURSOR_ENTER:
  1890. break;
  1891. case MUIF_MSG_CURSOR_SELECT:
  1892. case MUIF_MSG_VALUE_INCREMENT:
  1893. case MUIF_MSG_VALUE_DECREMENT:
  1894. mui_SaveForm(ui); // store the current form and position so that the child can jump back
  1895. mui_GotoForm(ui, ui->arg, *selection); // assumes that the selectable values are at the beginning of the form definition
  1896. break;
  1897. case MUIF_MSG_CURSOR_LEAVE:
  1898. break;
  1899. case MUIF_MSG_TOUCH_DOWN:
  1900. break;
  1901. case MUIF_MSG_TOUCH_UP:
  1902. break;
  1903. }
  1904. return 0;
  1905. }
  1906. static uint8_t mui_u8g2_u16_list_child_mse_common(mui_t *ui, uint8_t msg)
  1907. {
  1908. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  1909. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  1910. void *data = mui_u8g2_list_get_data_ptr(list);
  1911. //mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  1912. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  1913. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  1914. switch(msg)
  1915. {
  1916. case MUIF_MSG_DRAW:
  1917. /* done by the calling function */
  1918. break;
  1919. case MUIF_MSG_FORM_START:
  1920. /* we can assume that the list starts at the top. It will be adjisted by cursor down events later */
  1921. ui->form_scroll_top = 0;
  1922. if ( ui->form_scroll_visible <= arg )
  1923. ui->form_scroll_visible = arg+1;
  1924. if ( ui->form_scroll_total == 0 )
  1925. ui->form_scroll_total = count_cb(data);
  1926. break;
  1927. case MUIF_MSG_FORM_END:
  1928. break;
  1929. case MUIF_MSG_CURSOR_ENTER:
  1930. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  1931. case MUIF_MSG_CURSOR_SELECT:
  1932. case MUIF_MSG_VALUE_INCREMENT:
  1933. case MUIF_MSG_VALUE_DECREMENT:
  1934. if ( selection != NULL )
  1935. *selection = ui->form_scroll_top + arg;
  1936. mui_RestoreForm(ui);
  1937. break;
  1938. case MUIF_MSG_CURSOR_LEAVE:
  1939. break;
  1940. case MUIF_MSG_TOUCH_DOWN:
  1941. break;
  1942. case MUIF_MSG_TOUCH_UP:
  1943. break;
  1944. case MUIF_MSG_EVENT_NEXT:
  1945. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  1946. case MUIF_MSG_EVENT_PREV:
  1947. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  1948. }
  1949. return 0;
  1950. }
  1951. uint8_t mui_u8g2_u16_list_child_w1_pi(mui_t *ui, uint8_t msg)
  1952. {
  1953. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1954. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  1955. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  1956. void *data = mui_u8g2_list_get_data_ptr(list);
  1957. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  1958. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  1959. uint16_t pos = ui->arg; // remember the arg value, because it might be overwritten
  1960. switch(msg)
  1961. {
  1962. case MUIF_MSG_DRAW:
  1963. {
  1964. //u8g2_uint_t w = 0;
  1965. u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
  1966. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1967. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  1968. uint8_t is_focus = mui_IsCursorFocus(ui);
  1969. pos += ui->form_scroll_top;
  1970. if ( *selection == pos )
  1971. u8g2_DrawValueMark(u8g2, x, y, a);
  1972. //u8g2_SetFontMode(u8g2, 1);
  1973. a += 2; /* add gap between the checkbox and the text area */
  1974. if ( pos < count_cb(data) )
  1975. u8g2_DrawUTF8(u8g2, x+a, y, element_cb(data, pos));
  1976. if ( is_focus )
  1977. {
  1978. u8g2_DrawButtonFrame(u8g2, 0, y, U8G2_BTN_INV, u8g2_GetDisplayWidth(u8g2), 0, MUI_U8G2_V_PADDING);
  1979. }
  1980. }
  1981. break;
  1982. default:
  1983. return mui_u8g2_u16_list_child_mse_common(ui, msg);
  1984. }
  1985. return 0;
  1986. }
  1987. uint8_t mui_u8g2_u16_list_goto_w1_pi(mui_t *ui, uint8_t msg)
  1988. {
  1989. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1990. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  1991. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  1992. void *data = mui_u8g2_list_get_data_ptr(list);
  1993. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  1994. //mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  1995. uint16_t pos = ui->arg; // remember the arg value, because it might be overwritten
  1996. pos += ui->form_scroll_top;
  1997. switch(msg)
  1998. {
  1999. case MUIF_MSG_DRAW:
  2000. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui), element_cb(data, pos)+1);
  2001. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui), MUI_U8G2_V_PADDING, element_cb(data, pos)+1);
  2002. break;
  2003. case MUIF_MSG_CURSOR_SELECT:
  2004. case MUIF_MSG_VALUE_INCREMENT:
  2005. case MUIF_MSG_VALUE_DECREMENT:
  2006. if ( selection != NULL )
  2007. *selection = pos;
  2008. mui_SaveCursorPosition(ui, pos >= 255 ? 0 : pos); // store the current cursor position, so that the user can jump back to the corresponding cursor position
  2009. mui_GotoFormAutoCursorPosition(ui, (uint8_t)element_cb(data, pos)[0]);
  2010. break;
  2011. default:
  2012. return mui_u8g2_u16_list_child_mse_common(ui, msg);
  2013. }
  2014. return 0;
  2015. }