mui_u8g2.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916
  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_uint_t mui_get_arg(mui_t *ui)
  177. {
  178. return ui->arg;
  179. }
  180. char *mui_get_text(mui_t *ui)
  181. {
  182. return ui->text;
  183. }
  184. u8g2_t *mui_get_U8g2(mui_t *ui)
  185. {
  186. return (u8g2_t *)(ui->graphics_data);
  187. }
  188. //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);
  189. 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)
  190. {
  191. if ( text==NULL)
  192. text = "";
  193. u8g2_DrawButtonUTF8(mui_get_U8g2(ui), mui_get_x(ui), mui_get_y(ui), flags, width, padding_h, padding_v, text);
  194. }
  195. u8g2_uint_t mui_u8g2_get_pi_flags(mui_t *ui)
  196. {
  197. u8g2_uint_t flags = 0;
  198. if ( mui_IsCursorFocus(ui) )
  199. {
  200. flags |= U8G2_BTN_INV;
  201. if ( ui->is_mud )
  202. {
  203. flags |= U8G2_BTN_XFRAME;
  204. }
  205. }
  206. return flags;
  207. }
  208. void mui_u8g2_draw_button_pi(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  209. {
  210. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  211. }
  212. u8g2_uint_t mui_u8g2_get_fi_flags(mui_t *ui)
  213. {
  214. u8g2_uint_t flags = 1;
  215. if ( mui_IsCursorFocus(ui) )
  216. {
  217. flags |= U8G2_BTN_INV;
  218. if ( ui->is_mud )
  219. {
  220. flags = 1; // undo INV
  221. }
  222. }
  223. return flags;
  224. }
  225. void mui_u8g2_draw_button_fi(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  226. {
  227. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_fi_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  228. }
  229. u8g2_uint_t mui_u8g2_get_pf_flags(mui_t *ui)
  230. {
  231. u8g2_uint_t flags = 0;
  232. if ( mui_IsCursorFocus(ui) )
  233. {
  234. flags |= 1;
  235. if ( ui->is_mud )
  236. {
  237. flags |= U8G2_BTN_INV;
  238. }
  239. }
  240. return flags;
  241. }
  242. void mui_u8g2_draw_button_pf(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  243. {
  244. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pf_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  245. }
  246. u8g2_uint_t mui_u8g2_get_if_flags(mui_t *ui)
  247. {
  248. u8g2_uint_t flags = 0;
  249. if ( mui_IsCursorFocus(ui) )
  250. {
  251. if ( ui->is_mud )
  252. {
  253. flags |= 1;
  254. flags |= U8G2_BTN_INV;
  255. }
  256. else
  257. {
  258. flags |= 1;
  259. }
  260. }
  261. else
  262. {
  263. flags |= U8G2_BTN_INV;
  264. }
  265. return flags;
  266. }
  267. void mui_u8g2_draw_button_if(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text)
  268. {
  269. mui_u8g2_draw_button_utf(ui, mui_u8g2_get_if_flags(ui), width, padding_h , MUI_U8G2_V_PADDING, text);
  270. }
  271. static uint8_t mui_u8g2_handle_scroll_next_prev_events(mui_t *ui, uint8_t msg) MUI_NOINLINE;
  272. static uint8_t mui_u8g2_handle_scroll_next_prev_events(mui_t *ui, uint8_t msg)
  273. {
  274. uint8_t arg = ui->arg;
  275. switch(msg)
  276. {
  277. case MUIF_MSG_CURSOR_ENTER:
  278. if ( (arg > 0) && (ui->form_scroll_top + arg >= ui->form_scroll_total) )
  279. return 255;
  280. break;
  281. case MUIF_MSG_EVENT_NEXT:
  282. if ( arg+1 == ui->form_scroll_visible )
  283. {
  284. if ( ui->form_scroll_visible + ui->form_scroll_top < ui->form_scroll_total )
  285. {
  286. ui->form_scroll_top++;
  287. return 1;
  288. }
  289. else
  290. {
  291. ui->form_scroll_top = 0;
  292. }
  293. }
  294. break;
  295. case MUIF_MSG_EVENT_PREV:
  296. if ( arg == 0 )
  297. {
  298. if ( ui->form_scroll_top > 0 )
  299. {
  300. ui->form_scroll_top--;
  301. return 1;
  302. }
  303. else
  304. {
  305. if ( ui->form_scroll_total > ui->form_scroll_visible )
  306. {
  307. ui->form_scroll_top = ui->form_scroll_total - ui->form_scroll_visible;
  308. }
  309. else
  310. {
  311. ui->form_scroll_top = 0;
  312. }
  313. }
  314. }
  315. break;
  316. }
  317. return 0;
  318. }
  319. /*=========================================================================*/
  320. /* simplified style function */
  321. /*
  322. Used for MUIF_U8G2_FONT_STYLE(n,font)
  323. */
  324. uint8_t mui_u8g2_set_font_style_function(mui_t *ui, uint8_t msg)
  325. {
  326. if ( msg == MUIF_MSG_DRAW )
  327. {
  328. u8g2_SetFont(mui_get_U8g2(ui), (uint8_t *)muif_get_data(ui->uif));
  329. }
  330. return 0;
  331. }
  332. /*=========================================================================*/
  333. /* field functions */
  334. uint8_t mui_hline(mui_t *ui, uint8_t msg)
  335. {
  336. u8g2_t *u8g2 = mui_get_U8g2(ui);
  337. switch(msg)
  338. {
  339. case MUIF_MSG_DRAW:
  340. u8g2_DrawHLine(u8g2, 0, mui_get_y(ui), u8g2_GetDisplayWidth(u8g2));
  341. break;
  342. }
  343. return 0;
  344. }
  345. /*
  346. xy: yes, arg: no, text: yes
  347. */
  348. uint8_t mui_u8g2_draw_text(mui_t *ui, uint8_t msg)
  349. {
  350. switch(msg)
  351. {
  352. case MUIF_MSG_DRAW:
  353. u8g2_DrawUTF8(mui_get_U8g2(ui), mui_get_x(ui), mui_get_y(ui), ui->text);
  354. break;
  355. case MUIF_MSG_FORM_START:
  356. break;
  357. case MUIF_MSG_FORM_END:
  358. break;
  359. case MUIF_MSG_CURSOR_ENTER:
  360. break;
  361. case MUIF_MSG_CURSOR_SELECT:
  362. break;
  363. case MUIF_MSG_VALUE_INCREMENT:
  364. break;
  365. case MUIF_MSG_VALUE_DECREMENT:
  366. break;
  367. case MUIF_MSG_CURSOR_LEAVE:
  368. break;
  369. case MUIF_MSG_TOUCH_DOWN:
  370. break;
  371. case MUIF_MSG_TOUCH_UP:
  372. break;
  373. }
  374. return 0;
  375. }
  376. /*
  377. uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg)
  378. Description:
  379. A button with size equal to button text plus one pixel padding
  380. The button has a one pixel frame around the text.
  381. If the selected, then the form will change to the specified form number.
  382. Message Handling: DRAW, CURSOR_SELECT
  383. Style
  384. No Selection: Text + Frame
  385. Cursor Selection: Inverted text + Frame
  386. User interface field list (muif):
  387. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  388. data: not used
  389. Field definition string (fds):
  390. xy: Left position of the text (required)
  391. arg: Form numner (required)
  392. text: Button label
  393. */
  394. uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg)
  395. {
  396. switch(msg)
  397. {
  398. case MUIF_MSG_DRAW:
  399. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_fi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  400. break;
  401. case MUIF_MSG_FORM_START:
  402. break;
  403. case MUIF_MSG_FORM_END:
  404. break;
  405. case MUIF_MSG_CURSOR_ENTER:
  406. break;
  407. case MUIF_MSG_CURSOR_SELECT:
  408. case MUIF_MSG_VALUE_INCREMENT:
  409. case MUIF_MSG_VALUE_DECREMENT:
  410. //return mui_GotoForm(ui, ui->arg, 0);
  411. mui_SaveForm(ui);
  412. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  413. case MUIF_MSG_CURSOR_LEAVE:
  414. break;
  415. case MUIF_MSG_TOUCH_DOWN:
  416. break;
  417. case MUIF_MSG_TOUCH_UP:
  418. break;
  419. }
  420. return 0;
  421. }
  422. uint8_t mui_u8g2_btn_goto_wm_if(mui_t *ui, uint8_t msg)
  423. {
  424. switch(msg)
  425. {
  426. case MUIF_MSG_DRAW:
  427. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_if_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  428. break;
  429. case MUIF_MSG_FORM_START:
  430. break;
  431. case MUIF_MSG_FORM_END:
  432. break;
  433. case MUIF_MSG_CURSOR_ENTER:
  434. break;
  435. case MUIF_MSG_CURSOR_SELECT:
  436. case MUIF_MSG_VALUE_INCREMENT:
  437. case MUIF_MSG_VALUE_DECREMENT:
  438. //return mui_GotoForm(ui, ui->arg, 0);
  439. mui_SaveForm(ui);
  440. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  441. case MUIF_MSG_CURSOR_LEAVE:
  442. break;
  443. case MUIF_MSG_TOUCH_DOWN:
  444. break;
  445. case MUIF_MSG_TOUCH_UP:
  446. break;
  447. }
  448. return 0;
  449. }
  450. uint8_t mui_u8g2_btn_goto_w2_fi(mui_t *ui, uint8_t msg)
  451. {
  452. u8g2_t *u8g2 = mui_get_U8g2(ui);
  453. switch(msg)
  454. {
  455. case MUIF_MSG_DRAW:
  456. 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);
  457. break;
  458. case MUIF_MSG_FORM_START:
  459. break;
  460. case MUIF_MSG_FORM_END:
  461. break;
  462. case MUIF_MSG_CURSOR_ENTER:
  463. break;
  464. case MUIF_MSG_CURSOR_SELECT:
  465. case MUIF_MSG_VALUE_INCREMENT:
  466. case MUIF_MSG_VALUE_DECREMENT:
  467. //return mui_GotoForm(ui, ui->arg, 0);
  468. mui_SaveForm(ui);
  469. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  470. case MUIF_MSG_CURSOR_LEAVE:
  471. break;
  472. case MUIF_MSG_TOUCH_DOWN:
  473. break;
  474. case MUIF_MSG_TOUCH_UP:
  475. break;
  476. }
  477. return 0;
  478. }
  479. uint8_t mui_u8g2_btn_goto_w2_if(mui_t *ui, uint8_t msg)
  480. {
  481. u8g2_t *u8g2 = mui_get_U8g2(ui);
  482. switch(msg)
  483. {
  484. case MUIF_MSG_DRAW:
  485. 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);
  486. break;
  487. case MUIF_MSG_FORM_START:
  488. break;
  489. case MUIF_MSG_FORM_END:
  490. break;
  491. case MUIF_MSG_CURSOR_ENTER:
  492. break;
  493. case MUIF_MSG_CURSOR_SELECT:
  494. case MUIF_MSG_VALUE_INCREMENT:
  495. case MUIF_MSG_VALUE_DECREMENT:
  496. //return mui_GotoForm(ui, ui->arg, 0);
  497. mui_SaveForm(ui);
  498. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  499. case MUIF_MSG_CURSOR_LEAVE:
  500. break;
  501. case MUIF_MSG_TOUCH_DOWN:
  502. break;
  503. case MUIF_MSG_TOUCH_UP:
  504. break;
  505. }
  506. return 0;
  507. }
  508. uint8_t mui_u8g2_btn_goto_w1_pi(mui_t *ui, uint8_t msg)
  509. {
  510. u8g2_t *u8g2 = mui_get_U8g2(ui);
  511. switch(msg)
  512. {
  513. case MUIF_MSG_DRAW:
  514. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) , ui->text);
  515. //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);
  516. break;
  517. case MUIF_MSG_FORM_START:
  518. break;
  519. case MUIF_MSG_FORM_END:
  520. break;
  521. case MUIF_MSG_CURSOR_ENTER:
  522. break;
  523. case MUIF_MSG_CURSOR_SELECT:
  524. case MUIF_MSG_VALUE_INCREMENT:
  525. case MUIF_MSG_VALUE_DECREMENT:
  526. //return mui_GotoForm(ui, ui->arg, 0);
  527. mui_SaveForm(ui);
  528. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  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_fi(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_fi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui)-1 , 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. mui_SaveForm(ui);
  558. return mui_GotoFormAutoCursorPosition(ui, ui->arg);
  559. case MUIF_MSG_CURSOR_LEAVE:
  560. break;
  561. case MUIF_MSG_TOUCH_DOWN:
  562. break;
  563. case MUIF_MSG_TOUCH_UP:
  564. break;
  565. }
  566. return 0;
  567. }
  568. /*
  569. Back buttons are used to jump back to a previously stored form/cursor position
  570. */
  571. uint8_t mui_u8g2_btn_back_wm_fi(mui_t *ui, uint8_t msg)
  572. {
  573. switch(msg)
  574. {
  575. case MUIF_MSG_DRAW:
  576. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_fi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  577. break;
  578. case MUIF_MSG_FORM_START:
  579. break;
  580. case MUIF_MSG_FORM_END:
  581. break;
  582. case MUIF_MSG_CURSOR_ENTER:
  583. break;
  584. case MUIF_MSG_CURSOR_SELECT:
  585. case MUIF_MSG_VALUE_INCREMENT:
  586. case MUIF_MSG_VALUE_DECREMENT:
  587. return mui_RestoreForm(ui);
  588. case MUIF_MSG_CURSOR_LEAVE:
  589. break;
  590. case MUIF_MSG_TOUCH_DOWN:
  591. break;
  592. case MUIF_MSG_TOUCH_UP:
  593. break;
  594. }
  595. return 0;
  596. }
  597. uint8_t mui_u8g2_btn_back_wm_if(mui_t *ui, uint8_t msg)
  598. {
  599. switch(msg)
  600. {
  601. case MUIF_MSG_DRAW:
  602. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_if_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  603. break;
  604. case MUIF_MSG_FORM_START:
  605. break;
  606. case MUIF_MSG_FORM_END:
  607. break;
  608. case MUIF_MSG_CURSOR_ENTER:
  609. break;
  610. case MUIF_MSG_CURSOR_SELECT:
  611. case MUIF_MSG_VALUE_INCREMENT:
  612. case MUIF_MSG_VALUE_DECREMENT:
  613. return mui_RestoreForm(ui);
  614. case MUIF_MSG_CURSOR_LEAVE:
  615. break;
  616. case MUIF_MSG_TOUCH_DOWN:
  617. break;
  618. case MUIF_MSG_TOUCH_UP:
  619. break;
  620. }
  621. return 0;
  622. }
  623. uint8_t mui_u8g2_btn_back_w2_fi(mui_t *ui, uint8_t msg)
  624. {
  625. u8g2_t *u8g2 = mui_get_U8g2(ui);
  626. switch(msg)
  627. {
  628. case MUIF_MSG_DRAW:
  629. 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);
  630. break;
  631. case MUIF_MSG_FORM_START:
  632. break;
  633. case MUIF_MSG_FORM_END:
  634. break;
  635. case MUIF_MSG_CURSOR_ENTER:
  636. break;
  637. case MUIF_MSG_CURSOR_SELECT:
  638. case MUIF_MSG_VALUE_INCREMENT:
  639. case MUIF_MSG_VALUE_DECREMENT:
  640. return mui_RestoreForm(ui);
  641. case MUIF_MSG_CURSOR_LEAVE:
  642. break;
  643. case MUIF_MSG_TOUCH_DOWN:
  644. break;
  645. case MUIF_MSG_TOUCH_UP:
  646. break;
  647. }
  648. return 0;
  649. }
  650. uint8_t mui_u8g2_btn_back_w2_if(mui_t *ui, uint8_t msg)
  651. {
  652. u8g2_t *u8g2 = mui_get_U8g2(ui);
  653. switch(msg)
  654. {
  655. case MUIF_MSG_DRAW:
  656. 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);
  657. break;
  658. case MUIF_MSG_FORM_START:
  659. break;
  660. case MUIF_MSG_FORM_END:
  661. break;
  662. case MUIF_MSG_CURSOR_ENTER:
  663. break;
  664. case MUIF_MSG_CURSOR_SELECT:
  665. case MUIF_MSG_VALUE_INCREMENT:
  666. case MUIF_MSG_VALUE_DECREMENT:
  667. return mui_RestoreForm(ui);
  668. case MUIF_MSG_CURSOR_LEAVE:
  669. break;
  670. case MUIF_MSG_TOUCH_DOWN:
  671. break;
  672. case MUIF_MSG_TOUCH_UP:
  673. break;
  674. }
  675. return 0;
  676. }
  677. uint8_t mui_u8g2_btn_back_w1_pi(mui_t *ui, uint8_t msg)
  678. {
  679. u8g2_t *u8g2 = mui_get_U8g2(ui);
  680. switch(msg)
  681. {
  682. case MUIF_MSG_DRAW:
  683. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) , ui->text);
  684. //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);
  685. break;
  686. case MUIF_MSG_FORM_START:
  687. break;
  688. case MUIF_MSG_FORM_END:
  689. break;
  690. case MUIF_MSG_CURSOR_ENTER:
  691. break;
  692. case MUIF_MSG_CURSOR_SELECT:
  693. case MUIF_MSG_VALUE_INCREMENT:
  694. case MUIF_MSG_VALUE_DECREMENT:
  695. return mui_RestoreForm(ui);
  696. case MUIF_MSG_CURSOR_LEAVE:
  697. break;
  698. case MUIF_MSG_TOUCH_DOWN:
  699. break;
  700. case MUIF_MSG_TOUCH_UP:
  701. break;
  702. }
  703. return 0;
  704. }
  705. uint8_t mui_u8g2_btn_back_w1_fi(mui_t *ui, uint8_t msg)
  706. {
  707. u8g2_t *u8g2 = mui_get_U8g2(ui);
  708. switch(msg)
  709. {
  710. case MUIF_MSG_DRAW:
  711. mui_u8g2_draw_button_fi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui)-1 , ui->text);
  712. //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);
  713. break;
  714. case MUIF_MSG_FORM_START:
  715. break;
  716. case MUIF_MSG_FORM_END:
  717. break;
  718. case MUIF_MSG_CURSOR_ENTER:
  719. break;
  720. case MUIF_MSG_CURSOR_SELECT:
  721. case MUIF_MSG_VALUE_INCREMENT:
  722. case MUIF_MSG_VALUE_DECREMENT:
  723. return mui_RestoreForm(ui);
  724. case MUIF_MSG_CURSOR_LEAVE:
  725. break;
  726. case MUIF_MSG_TOUCH_DOWN:
  727. break;
  728. case MUIF_MSG_TOUCH_UP:
  729. break;
  730. }
  731. return 0;
  732. }
  733. /*
  734. uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg)
  735. Description:
  736. A button with size equal to button text plus one pixel padding
  737. The button has a one pixel frame around the text.
  738. If selected, then the menu system will be closed.
  739. The arg value will be stored at the specified data location (if not NULL).
  740. The arg value can be used as an exit value of the button.
  741. Message Handling: DRAW, CURSOR_SELECT
  742. Style
  743. No Selection: Text + Frame
  744. Cursor Selection: Inverted text + Frame
  745. User interface field list (muif):
  746. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  747. data: Optionally points to uint8_t value which will receive the arg value of the field.
  748. Field definition string (fds):
  749. xy: Left position of the text (required)
  750. arg: Value which will be stored at *data (optional)
  751. text: Button label
  752. */
  753. uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg)
  754. {
  755. switch(msg)
  756. {
  757. case MUIF_MSG_DRAW:
  758. mui_u8g2_draw_button_utf(ui, U8G2_BTN_HCENTER |mui_u8g2_get_fi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  759. break;
  760. case MUIF_MSG_FORM_START:
  761. break;
  762. case MUIF_MSG_FORM_END:
  763. break;
  764. case MUIF_MSG_CURSOR_ENTER:
  765. break;
  766. case MUIF_MSG_CURSOR_SELECT:
  767. case MUIF_MSG_VALUE_INCREMENT:
  768. case MUIF_MSG_VALUE_DECREMENT:
  769. {
  770. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  771. if ( value != NULL )
  772. *value = ui->arg;
  773. }
  774. mui_SaveForm(ui); // store the current form and position so that the child can jump back
  775. mui_LeaveForm(ui);
  776. return 1;
  777. case MUIF_MSG_CURSOR_LEAVE:
  778. break;
  779. case MUIF_MSG_TOUCH_DOWN:
  780. break;
  781. case MUIF_MSG_TOUCH_UP:
  782. break;
  783. }
  784. return 0;
  785. }
  786. /*===============================================================================*/
  787. /* u8 min max */
  788. static void mui_u8g2_u8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
  789. static void mui_u8g2_u8_vmm_draw_wm_pi(mui_t *ui)
  790. {
  791. u8g2_t *u8g2 = mui_get_U8g2(ui);
  792. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  793. char buf[4] = "999";
  794. char *s = buf;
  795. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  796. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  797. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  798. uint8_t cnt = 3;
  799. if ( *value > max )
  800. *value = max;
  801. if ( *value <= min )
  802. *value = min;
  803. if ( max < 100 )
  804. {
  805. s++;
  806. cnt--;
  807. }
  808. if ( max < 10 )
  809. {
  810. s++;
  811. cnt--;
  812. }
  813. mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u8toa(*value, cnt));
  814. }
  815. uint8_t mui_u8g2_u8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg)
  816. {
  817. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  818. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  819. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  820. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  821. switch(msg)
  822. {
  823. case MUIF_MSG_DRAW:
  824. mui_u8g2_u8_vmm_draw_wm_pi(ui);
  825. break;
  826. case MUIF_MSG_FORM_START:
  827. break;
  828. case MUIF_MSG_FORM_END:
  829. break;
  830. case MUIF_MSG_CURSOR_ENTER:
  831. break;
  832. case MUIF_MSG_CURSOR_SELECT:
  833. case MUIF_MSG_VALUE_INCREMENT:
  834. (*value)++;
  835. if ( *value > max ) *value = min;
  836. break;
  837. case MUIF_MSG_VALUE_DECREMENT:
  838. if ( *value > min ) (*value)--; else *value = max;
  839. break;
  840. case MUIF_MSG_CURSOR_LEAVE:
  841. break;
  842. case MUIF_MSG_TOUCH_DOWN:
  843. break;
  844. case MUIF_MSG_TOUCH_UP:
  845. break;
  846. }
  847. return 0;
  848. }
  849. uint8_t mui_u8g2_u8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg)
  850. {
  851. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  852. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  853. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  854. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  855. switch(msg)
  856. {
  857. case MUIF_MSG_DRAW:
  858. mui_u8g2_u8_vmm_draw_wm_pi(ui);
  859. break;
  860. case MUIF_MSG_FORM_START:
  861. break;
  862. case MUIF_MSG_FORM_END:
  863. break;
  864. case MUIF_MSG_CURSOR_ENTER:
  865. break;
  866. case MUIF_MSG_CURSOR_SELECT:
  867. case MUIF_MSG_VALUE_INCREMENT:
  868. case MUIF_MSG_VALUE_DECREMENT:
  869. /* toggle between normal mode and capture next/prev mode */
  870. ui->is_mud = !ui->is_mud;
  871. break;
  872. case MUIF_MSG_CURSOR_LEAVE:
  873. break;
  874. case MUIF_MSG_TOUCH_DOWN:
  875. break;
  876. case MUIF_MSG_TOUCH_UP:
  877. break;
  878. case MUIF_MSG_EVENT_NEXT:
  879. if ( ui->is_mud )
  880. {
  881. (*value)++;
  882. if ( *value > max )
  883. *value = min;
  884. return 1;
  885. }
  886. break;
  887. case MUIF_MSG_EVENT_PREV:
  888. if ( ui->is_mud )
  889. {
  890. if ( *value <= min )
  891. *value = max;
  892. else
  893. (*value)--;
  894. return 1;
  895. }
  896. break;
  897. }
  898. return 0;
  899. }
  900. static void mui_u8g2_u8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
  901. static void mui_u8g2_u8_vmm_draw_wm_pf(mui_t *ui)
  902. {
  903. u8g2_t *u8g2 = mui_get_U8g2(ui);
  904. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  905. char buf[4] = "999";
  906. char *s = buf;
  907. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  908. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  909. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  910. uint8_t cnt = 3;
  911. if ( *value > max )
  912. *value = max;
  913. if ( *value <= min )
  914. *value = min;
  915. if ( max < 100 )
  916. {
  917. s++;
  918. cnt--;
  919. }
  920. if ( max < 10 )
  921. {
  922. s++;
  923. cnt--;
  924. }
  925. //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));
  926. mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u8toa(*value, cnt));
  927. }
  928. uint8_t mui_u8g2_u8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg)
  929. {
  930. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  931. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  932. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  933. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  934. switch(msg)
  935. {
  936. case MUIF_MSG_DRAW:
  937. mui_u8g2_u8_vmm_draw_wm_pf(ui);
  938. break;
  939. case MUIF_MSG_FORM_START:
  940. break;
  941. case MUIF_MSG_FORM_END:
  942. break;
  943. case MUIF_MSG_CURSOR_ENTER:
  944. break;
  945. case MUIF_MSG_CURSOR_SELECT:
  946. case MUIF_MSG_VALUE_INCREMENT:
  947. (*value)++;
  948. if ( *value > max ) *value = min;
  949. break;
  950. case MUIF_MSG_VALUE_DECREMENT:
  951. if ( *value > min ) (*value)--; else *value = max;
  952. break;
  953. case MUIF_MSG_CURSOR_LEAVE:
  954. break;
  955. case MUIF_MSG_TOUCH_DOWN:
  956. break;
  957. case MUIF_MSG_TOUCH_UP:
  958. break;
  959. }
  960. return 0;
  961. }
  962. uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg)
  963. {
  964. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  965. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  966. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  967. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  968. switch(msg)
  969. {
  970. case MUIF_MSG_DRAW:
  971. mui_u8g2_u8_vmm_draw_wm_pf(ui);
  972. break;
  973. case MUIF_MSG_FORM_START:
  974. break;
  975. case MUIF_MSG_FORM_END:
  976. break;
  977. case MUIF_MSG_CURSOR_ENTER:
  978. break;
  979. case MUIF_MSG_CURSOR_SELECT:
  980. case MUIF_MSG_VALUE_INCREMENT:
  981. case MUIF_MSG_VALUE_DECREMENT:
  982. /* toggle between normal mode and capture next/prev mode */
  983. ui->is_mud = !ui->is_mud;
  984. break;
  985. case MUIF_MSG_CURSOR_LEAVE:
  986. break;
  987. case MUIF_MSG_TOUCH_DOWN:
  988. break;
  989. case MUIF_MSG_TOUCH_UP:
  990. break;
  991. case MUIF_MSG_EVENT_NEXT:
  992. if ( ui->is_mud )
  993. {
  994. (*value)++;
  995. if ( *value > max )
  996. *value = min;
  997. return 1;
  998. }
  999. break;
  1000. case MUIF_MSG_EVENT_PREV:
  1001. if ( ui->is_mud )
  1002. {
  1003. if ( *value <= min )
  1004. *value = max;
  1005. else
  1006. (*value)--;
  1007. return 1;
  1008. }
  1009. break;
  1010. }
  1011. return 0;
  1012. }
  1013. /*===============================================================================*/
  1014. /* s8 min max */
  1015. static void mui_u8g2_s8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
  1016. static void mui_u8g2_s8_vmm_draw_wm_pi(mui_t *ui)
  1017. {
  1018. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1019. mui_u8g2_s8_min_max_t *vmm= (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
  1020. char buf[6] = "+999";
  1021. int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
  1022. int8_t min = mui_u8g2_s8mm_get_min(vmm);
  1023. int8_t max = mui_u8g2_s8mm_get_max(vmm);
  1024. uint8_t cnt = 1; // number of digits
  1025. if ( *value > max )
  1026. *value = max;
  1027. if ( *value <= min )
  1028. *value = min;
  1029. if ( max >= 10 || max <= -10 || min >= 10 || min <= -10 )
  1030. cnt = 2;
  1031. if ( max >= 100 || max <= -100 || min >= 100 || min <= -100 )
  1032. cnt = 3;
  1033. buf[cnt+1] = '\0';
  1034. mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, buf)+1, 1, u8x8_s8toa(*value, cnt));
  1035. }
  1036. uint8_t mui_u8g2_s8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg)
  1037. {
  1038. mui_u8g2_s8_min_max_t *vmm= (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
  1039. int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
  1040. int8_t min = mui_u8g2_s8mm_get_min(vmm);
  1041. int8_t max = mui_u8g2_s8mm_get_max(vmm);
  1042. switch(msg)
  1043. {
  1044. case MUIF_MSG_DRAW:
  1045. mui_u8g2_s8_vmm_draw_wm_pi(ui);
  1046. break;
  1047. case MUIF_MSG_FORM_START:
  1048. break;
  1049. case MUIF_MSG_FORM_END:
  1050. break;
  1051. case MUIF_MSG_CURSOR_ENTER:
  1052. break;
  1053. case MUIF_MSG_CURSOR_SELECT:
  1054. case MUIF_MSG_VALUE_INCREMENT:
  1055. (*value)++;
  1056. if ( *value > max ) *value = min;
  1057. break;
  1058. case MUIF_MSG_VALUE_DECREMENT:
  1059. if ( *value > min ) (*value)--; else *value = max;
  1060. break;
  1061. case MUIF_MSG_CURSOR_LEAVE:
  1062. break;
  1063. case MUIF_MSG_TOUCH_DOWN:
  1064. break;
  1065. case MUIF_MSG_TOUCH_UP:
  1066. break;
  1067. }
  1068. return 0;
  1069. }
  1070. uint8_t mui_u8g2_s8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg)
  1071. {
  1072. mui_u8g2_s8_min_max_t *vmm= (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
  1073. int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
  1074. int8_t min = mui_u8g2_s8mm_get_min(vmm);
  1075. int8_t max = mui_u8g2_s8mm_get_max(vmm);
  1076. switch(msg)
  1077. {
  1078. case MUIF_MSG_DRAW:
  1079. mui_u8g2_s8_vmm_draw_wm_pi(ui);
  1080. break;
  1081. case MUIF_MSG_FORM_START:
  1082. break;
  1083. case MUIF_MSG_FORM_END:
  1084. break;
  1085. case MUIF_MSG_CURSOR_ENTER:
  1086. break;
  1087. case MUIF_MSG_CURSOR_SELECT:
  1088. case MUIF_MSG_VALUE_INCREMENT:
  1089. case MUIF_MSG_VALUE_DECREMENT:
  1090. /* toggle between normal mode and capture next/prev mode */
  1091. ui->is_mud = !ui->is_mud;
  1092. break;
  1093. case MUIF_MSG_CURSOR_LEAVE:
  1094. break;
  1095. case MUIF_MSG_TOUCH_DOWN:
  1096. break;
  1097. case MUIF_MSG_TOUCH_UP:
  1098. break;
  1099. case MUIF_MSG_EVENT_NEXT:
  1100. if ( ui->is_mud )
  1101. {
  1102. (*value)++;
  1103. if ( *value > max )
  1104. *value = min;
  1105. return 1;
  1106. }
  1107. break;
  1108. case MUIF_MSG_EVENT_PREV:
  1109. if ( ui->is_mud )
  1110. {
  1111. if ( *value <= min )
  1112. *value = max;
  1113. else
  1114. (*value)--;
  1115. return 1;
  1116. }
  1117. break;
  1118. }
  1119. return 0;
  1120. }
  1121. static void mui_u8g2_s8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
  1122. static void mui_u8g2_s8_vmm_draw_wm_pf(mui_t *ui)
  1123. {
  1124. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1125. mui_u8g2_s8_min_max_t *vmm= (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
  1126. char buf[4] = "999";
  1127. // char *s = buf;
  1128. int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
  1129. int8_t min = mui_u8g2_s8mm_get_min(vmm);
  1130. int8_t max = mui_u8g2_s8mm_get_max(vmm);
  1131. uint8_t cnt = 1; // number of digits
  1132. if ( *value > max )
  1133. *value = max;
  1134. if ( *value <= min )
  1135. *value = min;
  1136. if ( max >= 10 || max <= -10 || min >= 10 || min <= -10 )
  1137. cnt = 2;
  1138. if ( max >= 100 || max <= -100 || min >= 100 || min <= -100 )
  1139. cnt = 3;
  1140. buf[cnt+1] = '\0';
  1141. mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, buf)+1, 1, u8x8_s8toa(*value, cnt));
  1142. }
  1143. uint8_t mui_u8g2_s8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg)
  1144. {
  1145. mui_u8g2_s8_min_max_t *vmm= (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
  1146. int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
  1147. int8_t min = mui_u8g2_s8mm_get_min(vmm);
  1148. int8_t max = mui_u8g2_s8mm_get_max(vmm);
  1149. switch(msg)
  1150. {
  1151. case MUIF_MSG_DRAW:
  1152. mui_u8g2_s8_vmm_draw_wm_pf(ui);
  1153. break;
  1154. case MUIF_MSG_FORM_START:
  1155. break;
  1156. case MUIF_MSG_FORM_END:
  1157. break;
  1158. case MUIF_MSG_CURSOR_ENTER:
  1159. break;
  1160. case MUIF_MSG_CURSOR_SELECT:
  1161. case MUIF_MSG_VALUE_INCREMENT:
  1162. (*value)++;
  1163. if ( *value > max ) *value = min;
  1164. break;
  1165. case MUIF_MSG_VALUE_DECREMENT:
  1166. if ( *value > min ) (*value)--; else *value = max;
  1167. break;
  1168. case MUIF_MSG_CURSOR_LEAVE:
  1169. break;
  1170. case MUIF_MSG_TOUCH_DOWN:
  1171. break;
  1172. case MUIF_MSG_TOUCH_UP:
  1173. break;
  1174. }
  1175. return 0;
  1176. }
  1177. uint8_t mui_u8g2_s8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg)
  1178. {
  1179. mui_u8g2_s8_min_max_t *vmm= (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
  1180. int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
  1181. int8_t min = mui_u8g2_s8mm_get_min(vmm);
  1182. int8_t max = mui_u8g2_s8mm_get_max(vmm);
  1183. switch(msg)
  1184. {
  1185. case MUIF_MSG_DRAW:
  1186. mui_u8g2_s8_vmm_draw_wm_pf(ui);
  1187. break;
  1188. case MUIF_MSG_FORM_START:
  1189. break;
  1190. case MUIF_MSG_FORM_END:
  1191. break;
  1192. case MUIF_MSG_CURSOR_ENTER:
  1193. break;
  1194. case MUIF_MSG_CURSOR_SELECT:
  1195. case MUIF_MSG_VALUE_INCREMENT:
  1196. case MUIF_MSG_VALUE_DECREMENT:
  1197. /* toggle between normal mode and capture next/prev mode */
  1198. ui->is_mud = !ui->is_mud;
  1199. break;
  1200. case MUIF_MSG_CURSOR_LEAVE:
  1201. break;
  1202. case MUIF_MSG_TOUCH_DOWN:
  1203. break;
  1204. case MUIF_MSG_TOUCH_UP:
  1205. break;
  1206. case MUIF_MSG_EVENT_NEXT:
  1207. if ( ui->is_mud )
  1208. {
  1209. (*value)++;
  1210. if ( *value > max )
  1211. *value = min;
  1212. return 1;
  1213. }
  1214. break;
  1215. case MUIF_MSG_EVENT_PREV:
  1216. if ( ui->is_mud )
  1217. {
  1218. if ( *value <= min )
  1219. *value = max;
  1220. else
  1221. (*value)--;
  1222. return 1;
  1223. }
  1224. break;
  1225. }
  1226. return 0;
  1227. }
  1228. /*===============================================================================*/
  1229. /* x8 min max */
  1230. static void mui_u8g2_x8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
  1231. static void mui_u8g2_x8_vmm_draw_wm_pi(mui_t *ui)
  1232. {
  1233. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1234. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  1235. char buf[3] = "FF";
  1236. char *s = buf;
  1237. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  1238. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  1239. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  1240. uint8_t cnt = 2;
  1241. if ( *value > max )
  1242. *value = max;
  1243. if ( *value <= min )
  1244. *value = min;
  1245. if ( max < 16 )
  1246. {
  1247. s++;
  1248. cnt--;
  1249. }
  1250. mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u8tox(*value, cnt));
  1251. }
  1252. uint8_t mui_x8g2_x8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg)
  1253. {
  1254. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  1255. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  1256. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  1257. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  1258. switch(msg)
  1259. {
  1260. case MUIF_MSG_DRAW:
  1261. mui_u8g2_x8_vmm_draw_wm_pi(ui);
  1262. break;
  1263. case MUIF_MSG_FORM_START:
  1264. break;
  1265. case MUIF_MSG_FORM_END:
  1266. break;
  1267. case MUIF_MSG_CURSOR_ENTER:
  1268. break;
  1269. case MUIF_MSG_CURSOR_SELECT:
  1270. case MUIF_MSG_VALUE_INCREMENT:
  1271. (*value)++;
  1272. if ( *value > max ) *value = min;
  1273. break;
  1274. case MUIF_MSG_VALUE_DECREMENT:
  1275. if ( *value > min ) (*value)--; else *value = max;
  1276. break;
  1277. case MUIF_MSG_CURSOR_LEAVE:
  1278. break;
  1279. case MUIF_MSG_TOUCH_DOWN:
  1280. break;
  1281. case MUIF_MSG_TOUCH_UP:
  1282. break;
  1283. }
  1284. return 0;
  1285. }
  1286. uint8_t mui_u8g2_x8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg)
  1287. {
  1288. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  1289. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  1290. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  1291. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  1292. switch(msg)
  1293. {
  1294. case MUIF_MSG_DRAW:
  1295. mui_u8g2_x8_vmm_draw_wm_pi(ui);
  1296. break;
  1297. case MUIF_MSG_FORM_START:
  1298. break;
  1299. case MUIF_MSG_FORM_END:
  1300. break;
  1301. case MUIF_MSG_CURSOR_ENTER:
  1302. break;
  1303. case MUIF_MSG_CURSOR_SELECT:
  1304. case MUIF_MSG_VALUE_INCREMENT:
  1305. case MUIF_MSG_VALUE_DECREMENT:
  1306. /* toggle between normal mode and capture next/prev mode */
  1307. ui->is_mud = !ui->is_mud;
  1308. break;
  1309. case MUIF_MSG_CURSOR_LEAVE:
  1310. break;
  1311. case MUIF_MSG_TOUCH_DOWN:
  1312. break;
  1313. case MUIF_MSG_TOUCH_UP:
  1314. break;
  1315. case MUIF_MSG_EVENT_NEXT:
  1316. if ( ui->is_mud )
  1317. {
  1318. (*value)++;
  1319. if ( *value > max )
  1320. *value = min;
  1321. return 1;
  1322. }
  1323. break;
  1324. case MUIF_MSG_EVENT_PREV:
  1325. if ( ui->is_mud )
  1326. {
  1327. if ( *value <= min )
  1328. *value = max;
  1329. else
  1330. (*value)--;
  1331. return 1;
  1332. }
  1333. break;
  1334. }
  1335. return 0;
  1336. }
  1337. static void mui_u8g2_x8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
  1338. static void mui_u8g2_x8_vmm_draw_wm_pf(mui_t *ui)
  1339. {
  1340. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1341. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  1342. char buf[3] = "FF";
  1343. char *s = buf;
  1344. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  1345. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  1346. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  1347. uint8_t cnt = 2;
  1348. if ( *value > max )
  1349. *value = max;
  1350. if ( *value <= min )
  1351. *value = min;
  1352. if ( max < 16 )
  1353. {
  1354. s++;
  1355. cnt--;
  1356. }
  1357. mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, s)+1, 1, u8x8_u8tox(*value, cnt));
  1358. }
  1359. uint8_t mui_u8g2_x8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg)
  1360. {
  1361. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  1362. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  1363. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  1364. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  1365. switch(msg)
  1366. {
  1367. case MUIF_MSG_DRAW:
  1368. mui_u8g2_x8_vmm_draw_wm_pf(ui);
  1369. break;
  1370. case MUIF_MSG_FORM_START:
  1371. break;
  1372. case MUIF_MSG_FORM_END:
  1373. break;
  1374. case MUIF_MSG_CURSOR_ENTER:
  1375. break;
  1376. case MUIF_MSG_CURSOR_SELECT:
  1377. case MUIF_MSG_VALUE_INCREMENT:
  1378. (*value)++;
  1379. if ( *value > max ) *value = min;
  1380. break;
  1381. case MUIF_MSG_VALUE_DECREMENT:
  1382. if ( *value > min ) (*value)--; else *value = max;
  1383. break;
  1384. case MUIF_MSG_CURSOR_LEAVE:
  1385. break;
  1386. case MUIF_MSG_TOUCH_DOWN:
  1387. break;
  1388. case MUIF_MSG_TOUCH_UP:
  1389. break;
  1390. }
  1391. return 0;
  1392. }
  1393. uint8_t mui_u8g2_x8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg)
  1394. {
  1395. mui_u8g2_u8_min_max_t *vmm= (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
  1396. uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
  1397. uint8_t min = mui_u8g2_u8mm_get_min(vmm);
  1398. uint8_t max = mui_u8g2_u8mm_get_max(vmm);
  1399. switch(msg)
  1400. {
  1401. case MUIF_MSG_DRAW:
  1402. mui_u8g2_x8_vmm_draw_wm_pf(ui);
  1403. break;
  1404. case MUIF_MSG_FORM_START:
  1405. break;
  1406. case MUIF_MSG_FORM_END:
  1407. break;
  1408. case MUIF_MSG_CURSOR_ENTER:
  1409. break;
  1410. case MUIF_MSG_CURSOR_SELECT:
  1411. case MUIF_MSG_VALUE_INCREMENT:
  1412. case MUIF_MSG_VALUE_DECREMENT:
  1413. /* toggle between normal mode and capture next/prev mode */
  1414. ui->is_mud = !ui->is_mud;
  1415. break;
  1416. case MUIF_MSG_CURSOR_LEAVE:
  1417. break;
  1418. case MUIF_MSG_TOUCH_DOWN:
  1419. break;
  1420. case MUIF_MSG_TOUCH_UP:
  1421. break;
  1422. case MUIF_MSG_EVENT_NEXT:
  1423. if ( ui->is_mud )
  1424. {
  1425. (*value)++;
  1426. if ( *value > max )
  1427. *value = min;
  1428. return 1;
  1429. }
  1430. break;
  1431. case MUIF_MSG_EVENT_PREV:
  1432. if ( ui->is_mud )
  1433. {
  1434. if ( *value <= min )
  1435. *value = max;
  1436. else
  1437. (*value)--;
  1438. return 1;
  1439. }
  1440. break;
  1441. }
  1442. return 0;
  1443. }
  1444. /*===============================================================================*/
  1445. /* u8 bar graph */
  1446. static uint8_t mui_u8g2_u8_bar_mse_msg_handler(mui_t *ui, uint8_t msg) MUI_NOINLINE;
  1447. static uint8_t mui_u8g2_u8_bar_mse_msg_handler(mui_t *ui, uint8_t msg)
  1448. {
  1449. mui_u8g2_u8_min_max_step_t *vmms= (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
  1450. uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
  1451. uint8_t min = mui_u8g2_u8mms_get_min(vmms);
  1452. uint8_t max = mui_u8g2_u8mms_get_max(vmms);
  1453. uint8_t step = mui_u8g2_u8mms_get_step(vmms);
  1454. uint8_t flags = mui_u8g2_u8mms_get_flags(vmms);
  1455. switch(msg)
  1456. {
  1457. case MUIF_MSG_DRAW:
  1458. break;
  1459. case MUIF_MSG_FORM_START:
  1460. break;
  1461. case MUIF_MSG_FORM_END:
  1462. break;
  1463. case MUIF_MSG_CURSOR_ENTER:
  1464. break;
  1465. case MUIF_MSG_CURSOR_SELECT:
  1466. case MUIF_MSG_VALUE_INCREMENT:
  1467. (*value)+=step;
  1468. if ( *value > max )
  1469. {
  1470. if ( flags & MUI_MMS_NO_WRAP )
  1471. *value = max;
  1472. else
  1473. *value = min;
  1474. }
  1475. break;
  1476. case MUIF_MSG_VALUE_DECREMENT:
  1477. if ( *value >= min+step )
  1478. (*value)-=step;
  1479. else
  1480. {
  1481. if ( flags & MUI_MMS_NO_WRAP )
  1482. *value = min;
  1483. else
  1484. *value = max;
  1485. }
  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. static uint8_t mui_u8g2_u8_bar_mud_msg_handler(mui_t *ui, uint8_t msg) MUI_NOINLINE;
  1497. static uint8_t mui_u8g2_u8_bar_mud_msg_handler(mui_t *ui, uint8_t msg)
  1498. {
  1499. mui_u8g2_u8_min_max_step_t *vmms= (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
  1500. uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
  1501. uint8_t min = mui_u8g2_u8mms_get_min(vmms);
  1502. uint8_t max = mui_u8g2_u8mms_get_max(vmms);
  1503. uint8_t step = mui_u8g2_u8mms_get_step(vmms);
  1504. uint8_t flags = mui_u8g2_u8mms_get_flags(vmms);
  1505. switch(msg)
  1506. {
  1507. case MUIF_MSG_DRAW:
  1508. break;
  1509. case MUIF_MSG_FORM_START:
  1510. break;
  1511. case MUIF_MSG_FORM_END:
  1512. break;
  1513. case MUIF_MSG_CURSOR_ENTER:
  1514. break;
  1515. case MUIF_MSG_CURSOR_SELECT:
  1516. case MUIF_MSG_VALUE_INCREMENT:
  1517. case MUIF_MSG_VALUE_DECREMENT:
  1518. /* toggle between normal mode and capture next/prev mode */
  1519. ui->is_mud = !ui->is_mud;
  1520. break;
  1521. case MUIF_MSG_CURSOR_LEAVE:
  1522. break;
  1523. case MUIF_MSG_TOUCH_DOWN:
  1524. break;
  1525. case MUIF_MSG_TOUCH_UP:
  1526. break;
  1527. case MUIF_MSG_EVENT_NEXT:
  1528. if ( ui->is_mud )
  1529. {
  1530. (*value)+=step;
  1531. if ( *value > max )
  1532. {
  1533. if ( flags & MUI_MMS_NO_WRAP )
  1534. *value = max;
  1535. else
  1536. *value = min;
  1537. }
  1538. return 1;
  1539. }
  1540. break;
  1541. case MUIF_MSG_EVENT_PREV:
  1542. if ( ui->is_mud )
  1543. {
  1544. if ( *value <= min || *value > max)
  1545. {
  1546. if ( flags & MUI_MMS_NO_WRAP )
  1547. *value = min;
  1548. else
  1549. *value = max;
  1550. }
  1551. else
  1552. (*value)-=step;
  1553. return 1;
  1554. }
  1555. break;
  1556. }
  1557. return 0;
  1558. }
  1559. static void mui_u8g2_u8_bar_draw_wm(mui_t *ui, uint8_t flags, uint8_t is_fixed_width) MUI_NOINLINE;
  1560. static void mui_u8g2_u8_bar_draw_wm(mui_t *ui, uint8_t flags, uint8_t is_fixed_width)
  1561. {
  1562. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1563. mui_u8g2_u8_min_max_step_t *vmms= (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
  1564. char buf[4] = "999";
  1565. char *s = buf;
  1566. uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
  1567. uint8_t min = mui_u8g2_u8mms_get_min(vmms);
  1568. uint8_t max = mui_u8g2_u8mms_get_max(vmms);
  1569. uint8_t scale = 0;
  1570. //uint8_t step = mui_u8g2_u8mms_get_step(vmms);
  1571. uint8_t mms_flags = mui_u8g2_u8mms_get_flags(vmms);
  1572. uint8_t cnt = 3;
  1573. uint8_t height = u8g2_GetAscent(u8g2);
  1574. int8_t backup_descent;
  1575. u8g2_uint_t x = mui_get_x(ui);
  1576. u8g2_uint_t w = 0;
  1577. u8g2_uint_t v; // the calculated pixel value
  1578. if ( mms_flags & MUI_MMS_2X_BAR )
  1579. scale |= 1;
  1580. if ( mms_flags & MUI_MMS_4X_BAR )
  1581. scale |= 2;
  1582. if ( *value > max )
  1583. *value = max;
  1584. if ( *value <= min )
  1585. *value = min;
  1586. if ( max < 100 )
  1587. {
  1588. s++;
  1589. cnt--;
  1590. }
  1591. if ( max < 10 )
  1592. {
  1593. s++;
  1594. cnt--;
  1595. }
  1596. if ( is_fixed_width == 0 )
  1597. {
  1598. w += (max<<scale); // total width of the bar is derived from the max value
  1599. v = (*value)<<scale; // pixel position for the current value
  1600. }
  1601. else
  1602. {
  1603. u8g2_uint_t width = mui_u8g2_u8mms_get_width(vmms);
  1604. w += (width<<scale); // total width of bar is defined by the width argument
  1605. 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
  1606. }
  1607. w += 2; // add gap for the frame
  1608. u8g2_DrawFrame( u8g2, x, mui_get_y(ui)-height, w, height);
  1609. u8g2_DrawBox( u8g2, x+1, mui_get_y(ui)-height+1, v, height-2);
  1610. if ( mms_flags & MUI_MMS_SHOW_VALUE )
  1611. {
  1612. w += 2;
  1613. u8g2_DrawStr(u8g2, x+w, mui_get_y(ui), u8x8_u8toa(*value, cnt) );
  1614. w += u8g2_GetStrWidth(u8g2, s);
  1615. w += 1;
  1616. }
  1617. backup_descent = u8g2->font_ref_descent;
  1618. u8g2->font_ref_descent = 0; /* hmm... that's a low level hack so that DrawButtonFrame ignores the descent value of the font */
  1619. u8g2_DrawButtonFrame(u8g2, x, mui_get_y(ui), flags, w, 1, 1);
  1620. u8g2->font_ref_descent = backup_descent;
  1621. }
  1622. // #define MUIF_U8G2_U8_MIN_MAX_STEP(id, valptr, min, max, step, flags, muif)
  1623. uint8_t mui_u8g2_u8_bar_wm_mse_pi(mui_t *ui, uint8_t msg)
  1624. {
  1625. switch(msg)
  1626. {
  1627. case MUIF_MSG_DRAW:
  1628. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 0);
  1629. break;
  1630. default:
  1631. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1632. }
  1633. return 0;
  1634. }
  1635. uint8_t mui_u8g2_u8_bar_wm_mud_pi(mui_t *ui, uint8_t msg)
  1636. {
  1637. switch(msg)
  1638. {
  1639. case MUIF_MSG_DRAW:
  1640. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 0);
  1641. break;
  1642. default:
  1643. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1644. }
  1645. return 0;
  1646. }
  1647. uint8_t mui_u8g2_u8_bar_wm_mse_pf(mui_t *ui, uint8_t msg)
  1648. {
  1649. switch(msg)
  1650. {
  1651. case MUIF_MSG_DRAW:
  1652. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 0);
  1653. break;
  1654. default:
  1655. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1656. }
  1657. return 0;
  1658. }
  1659. uint8_t mui_u8g2_u8_bar_wm_mud_pf(mui_t *ui, uint8_t msg)
  1660. {
  1661. switch(msg)
  1662. {
  1663. case MUIF_MSG_DRAW:
  1664. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 0);
  1665. break;
  1666. default:
  1667. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1668. }
  1669. return 0;
  1670. }
  1671. // #define MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH(id, valptr, min, max, step, width, flags, muif)
  1672. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mse_pi(mui_t *ui, uint8_t msg)
  1673. {
  1674. switch(msg)
  1675. {
  1676. case MUIF_MSG_DRAW:
  1677. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 1);
  1678. break;
  1679. default:
  1680. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1681. }
  1682. return 0;
  1683. }
  1684. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mud_pi(mui_t *ui, uint8_t msg)
  1685. {
  1686. switch(msg)
  1687. {
  1688. case MUIF_MSG_DRAW:
  1689. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 1);
  1690. break;
  1691. default:
  1692. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1693. }
  1694. return 0;
  1695. }
  1696. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mse_pf(mui_t *ui, uint8_t msg)
  1697. {
  1698. switch(msg)
  1699. {
  1700. case MUIF_MSG_DRAW:
  1701. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 1);
  1702. break;
  1703. default:
  1704. return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
  1705. }
  1706. return 0;
  1707. }
  1708. uint8_t mui_u8g2_u8_fixed_width_bar_wm_mud_pf(mui_t *ui, uint8_t msg)
  1709. {
  1710. switch(msg)
  1711. {
  1712. case MUIF_MSG_DRAW:
  1713. mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 1);
  1714. break;
  1715. default:
  1716. return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
  1717. }
  1718. return 0;
  1719. }
  1720. /*===============================================================================*/
  1721. static uint8_t mui_is_valid_char(uint8_t c) MUI_NOINLINE;
  1722. uint8_t mui_is_valid_char(uint8_t c)
  1723. {
  1724. if ( c == 32 )
  1725. return 1;
  1726. if ( c >= 'A' && c <= 'Z' )
  1727. return 1;
  1728. if ( c >= 'a' && c <= 'z' )
  1729. return 1;
  1730. if ( c >= '0' && c <= '9' )
  1731. return 1;
  1732. return 0;
  1733. }
  1734. uint8_t mui_u8g2_u8_char_wm_mud_pi(mui_t *ui, uint8_t msg)
  1735. {
  1736. //ui->dflags MUIF_DFLAG_IS_CURSOR_FOCUS MUIF_DFLAG_IS_TOUCH_FOCUS
  1737. //mui_get_cflags(ui->uif) MUIF_CFLAG_IS_CURSOR_SELECTABLE
  1738. u8g2_t *u8g2 = mui_get_U8g2(ui);
  1739. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1740. char buf[6];
  1741. switch(msg)
  1742. {
  1743. case MUIF_MSG_DRAW:
  1744. while( mui_is_valid_char(*value) == 0 )
  1745. (*value)++;
  1746. buf[0] = *value;
  1747. buf[1] = '\0';
  1748. mui_u8g2_draw_button_pi(ui, u8g2_GetMaxCharWidth(u8g2), 1, buf);
  1749. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), u8g2_GetMaxCharWidth(u8g2), 1, MUI_U8G2_V_PADDING, buf);
  1750. //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);
  1751. break;
  1752. case MUIF_MSG_FORM_START:
  1753. break;
  1754. case MUIF_MSG_FORM_END:
  1755. break;
  1756. case MUIF_MSG_CURSOR_ENTER:
  1757. break;
  1758. case MUIF_MSG_CURSOR_SELECT:
  1759. case MUIF_MSG_VALUE_INCREMENT:
  1760. case MUIF_MSG_VALUE_DECREMENT:
  1761. /* toggle between normal mode and capture next/prev mode */
  1762. ui->is_mud = !ui->is_mud;
  1763. break;
  1764. case MUIF_MSG_CURSOR_LEAVE:
  1765. break;
  1766. case MUIF_MSG_TOUCH_DOWN:
  1767. break;
  1768. case MUIF_MSG_TOUCH_UP:
  1769. break;
  1770. case MUIF_MSG_EVENT_NEXT:
  1771. if ( ui->is_mud )
  1772. {
  1773. do {
  1774. (*value)++;
  1775. } while( mui_is_valid_char(*value) == 0 );
  1776. return 1;
  1777. }
  1778. break;
  1779. case MUIF_MSG_EVENT_PREV:
  1780. if ( ui->is_mud )
  1781. {
  1782. do {
  1783. (*value)--;
  1784. } while( mui_is_valid_char(*value) == 0 );
  1785. return 1;
  1786. }
  1787. break;
  1788. }
  1789. return 0;
  1790. }
  1791. /*
  1792. uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg)
  1793. Description:
  1794. Select one of several options. First option has value 0.
  1795. Only one option is visible.
  1796. The visible option is automatically the selected option.
  1797. Message Handling: DRAW, SELECT
  1798. Style
  1799. No Selection: Text only
  1800. Cursor Selection: Inverted text
  1801. User interface field list (muif):
  1802. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  1803. data: uint8_t *, pointer to a uint8_t variable, which contains the selected option
  1804. Field definition string (fds):
  1805. xy: Left position of the text (required)
  1806. arg: total width of the selectable option (optional),
  1807. text: '|' separated list of options
  1808. */
  1809. uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg)
  1810. {
  1811. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1812. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1813. switch(msg)
  1814. {
  1815. case MUIF_MSG_DRAW:
  1816. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1817. {
  1818. *value = 0;
  1819. mui_fds_get_nth_token(ui, *value);
  1820. }
  1821. mui_u8g2_draw_button_pi(ui, ui->arg, 1, ui->text);
  1822. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, ui->text);
  1823. //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);
  1824. break;
  1825. case MUIF_MSG_FORM_START:
  1826. break;
  1827. case MUIF_MSG_FORM_END:
  1828. break;
  1829. case MUIF_MSG_CURSOR_ENTER:
  1830. break;
  1831. case MUIF_MSG_CURSOR_SELECT:
  1832. case MUIF_MSG_VALUE_INCREMENT:
  1833. (*value)++;
  1834. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1835. *value = 0;
  1836. break;
  1837. case MUIF_MSG_VALUE_DECREMENT:
  1838. if ( *value > 0 )
  1839. (*value)--;
  1840. else
  1841. (*value) = mui_fds_get_token_cnt(ui)-1;
  1842. break;
  1843. case MUIF_MSG_CURSOR_LEAVE:
  1844. break;
  1845. case MUIF_MSG_TOUCH_DOWN:
  1846. break;
  1847. case MUIF_MSG_TOUCH_UP:
  1848. break;
  1849. }
  1850. return 0;
  1851. }
  1852. uint8_t mui_u8g2_u8_opt_line_wa_mse_pf(mui_t *ui, uint8_t msg)
  1853. {
  1854. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1855. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1856. switch(msg)
  1857. {
  1858. case MUIF_MSG_DRAW:
  1859. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1860. {
  1861. *value = 0;
  1862. mui_fds_get_nth_token(ui, *value);
  1863. }
  1864. mui_u8g2_draw_button_pf(ui, ui->arg, 1, ui->text);
  1865. break;
  1866. case MUIF_MSG_FORM_START:
  1867. break;
  1868. case MUIF_MSG_FORM_END:
  1869. break;
  1870. case MUIF_MSG_CURSOR_ENTER:
  1871. break;
  1872. case MUIF_MSG_CURSOR_SELECT:
  1873. case MUIF_MSG_VALUE_INCREMENT:
  1874. (*value)++;
  1875. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1876. *value = 0;
  1877. break;
  1878. case MUIF_MSG_VALUE_DECREMENT:
  1879. if ( *value > 0 )
  1880. (*value)--;
  1881. else
  1882. (*value) = mui_fds_get_token_cnt(ui)-1;
  1883. break;
  1884. case MUIF_MSG_CURSOR_LEAVE:
  1885. break;
  1886. case MUIF_MSG_TOUCH_DOWN:
  1887. break;
  1888. case MUIF_MSG_TOUCH_UP:
  1889. break;
  1890. }
  1891. return 0;
  1892. }
  1893. uint8_t mui_u8g2_u8_opt_line_wa_mud_pi(mui_t *ui, uint8_t msg)
  1894. {
  1895. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1896. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1897. switch(msg)
  1898. {
  1899. case MUIF_MSG_DRAW:
  1900. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1901. {
  1902. *value = 0;
  1903. mui_fds_get_nth_token(ui, *value);
  1904. }
  1905. mui_u8g2_draw_button_pi(ui, ui->arg, 1, ui->text);
  1906. break;
  1907. case MUIF_MSG_FORM_START:
  1908. break;
  1909. case MUIF_MSG_FORM_END:
  1910. break;
  1911. case MUIF_MSG_CURSOR_ENTER:
  1912. break;
  1913. case MUIF_MSG_CURSOR_SELECT:
  1914. case MUIF_MSG_VALUE_INCREMENT:
  1915. case MUIF_MSG_VALUE_DECREMENT:
  1916. /* toggle between normal mode and capture next/prev mode */
  1917. ui->is_mud = !ui->is_mud;
  1918. break;
  1919. case MUIF_MSG_CURSOR_LEAVE:
  1920. break;
  1921. case MUIF_MSG_TOUCH_DOWN:
  1922. break;
  1923. case MUIF_MSG_TOUCH_UP:
  1924. break;
  1925. case MUIF_MSG_EVENT_NEXT:
  1926. if ( ui->is_mud )
  1927. {
  1928. (*value)++;
  1929. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1930. *value = 0;
  1931. return 1;
  1932. }
  1933. break;
  1934. case MUIF_MSG_EVENT_PREV:
  1935. if ( ui->is_mud )
  1936. {
  1937. if ( *value == 0 )
  1938. *value = mui_fds_get_token_cnt(ui);
  1939. (*value)--;
  1940. return 1;
  1941. }
  1942. break;
  1943. }
  1944. return 0;
  1945. }
  1946. uint8_t mui_u8g2_u8_opt_line_wa_mud_pf(mui_t *ui, uint8_t msg)
  1947. {
  1948. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  1949. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  1950. switch(msg)
  1951. {
  1952. case MUIF_MSG_DRAW:
  1953. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1954. {
  1955. *value = 0;
  1956. mui_fds_get_nth_token(ui, *value);
  1957. }
  1958. mui_u8g2_draw_button_pf(ui, ui->arg, 1, ui->text);
  1959. break;
  1960. case MUIF_MSG_FORM_START:
  1961. break;
  1962. case MUIF_MSG_FORM_END:
  1963. break;
  1964. case MUIF_MSG_CURSOR_ENTER:
  1965. break;
  1966. case MUIF_MSG_CURSOR_SELECT:
  1967. case MUIF_MSG_VALUE_INCREMENT:
  1968. case MUIF_MSG_VALUE_DECREMENT:
  1969. /* toggle between normal mode and capture next/prev mode */
  1970. ui->is_mud = !ui->is_mud;
  1971. break;
  1972. case MUIF_MSG_CURSOR_LEAVE:
  1973. break;
  1974. case MUIF_MSG_TOUCH_DOWN:
  1975. break;
  1976. case MUIF_MSG_TOUCH_UP:
  1977. break;
  1978. case MUIF_MSG_EVENT_NEXT:
  1979. if ( ui->is_mud )
  1980. {
  1981. (*value)++;
  1982. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  1983. *value = 0;
  1984. return 1;
  1985. }
  1986. break;
  1987. case MUIF_MSG_EVENT_PREV:
  1988. if ( ui->is_mud )
  1989. {
  1990. if ( *value == 0 )
  1991. *value = mui_fds_get_token_cnt(ui);
  1992. (*value)--;
  1993. return 1;
  1994. }
  1995. break;
  1996. }
  1997. return 0;
  1998. }
  1999. /*
  2000. uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg)
  2001. Description:
  2002. Checkbox with the values 0 (not selected) and 1 (selected).
  2003. Message Handling: DRAW, SELECT
  2004. Style
  2005. No Selection: Plain checkbox and text
  2006. Cursor Selection: Checkbox and text is inverted
  2007. User interface field list (muif):
  2008. flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
  2009. data: uint8_t *, pointer to a uint8_t variable, which contains the values 0 or 1
  2010. Field definition string (fds):
  2011. xy: Left position of the text (required)
  2012. arg: not used
  2013. text: Optional: Text will be printed after the checkbox with a small gap
  2014. */
  2015. uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg)
  2016. {
  2017. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2018. u8g2_uint_t flags = 0;
  2019. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2020. switch(msg)
  2021. {
  2022. case MUIF_MSG_DRAW:
  2023. if ( *value > 1 ) *value = 1;
  2024. if ( mui_IsCursorFocus(ui) )
  2025. {
  2026. flags |= U8G2_BTN_INV;
  2027. }
  2028. {
  2029. u8g2_uint_t w = 0;
  2030. u8g2_uint_t a = u8g2_GetAscent(u8g2);
  2031. if ( *value )
  2032. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 1);
  2033. else
  2034. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 0);
  2035. if ( ui->text[0] != '\0' )
  2036. {
  2037. w = u8g2_GetUTF8Width(u8g2, ui->text);
  2038. //u8g2_SetFontMode(u8g2, 1);
  2039. a += 2; /* add gap between the checkbox and the text area */
  2040. u8g2_DrawUTF8(u8g2, mui_get_x(ui)+a, mui_get_y(ui), ui->text);
  2041. }
  2042. u8g2_DrawButtonFrame(u8g2, mui_get_x(ui), mui_get_y(ui), flags, w+a, 1, MUI_U8G2_V_PADDING);
  2043. }
  2044. break;
  2045. case MUIF_MSG_FORM_START:
  2046. break;
  2047. case MUIF_MSG_FORM_END:
  2048. break;
  2049. case MUIF_MSG_CURSOR_ENTER:
  2050. break;
  2051. case MUIF_MSG_CURSOR_SELECT:
  2052. case MUIF_MSG_VALUE_INCREMENT:
  2053. case MUIF_MSG_VALUE_DECREMENT:
  2054. (*value)++;
  2055. if ( *value > 1 ) *value = 0;
  2056. break;
  2057. case MUIF_MSG_CURSOR_LEAVE:
  2058. break;
  2059. case MUIF_MSG_TOUCH_DOWN:
  2060. break;
  2061. case MUIF_MSG_TOUCH_UP:
  2062. break;
  2063. }
  2064. return 0;
  2065. }
  2066. /*
  2067. radio button style, arg is assigned as value
  2068. */
  2069. uint8_t mui_u8g2_u8_radio_wm_pi(mui_t *ui, uint8_t msg)
  2070. {
  2071. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2072. u8g2_uint_t flags = 0;
  2073. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2074. switch(msg)
  2075. {
  2076. case MUIF_MSG_DRAW:
  2077. if ( mui_IsCursorFocus(ui) )
  2078. {
  2079. flags |= U8G2_BTN_INV;
  2080. }
  2081. {
  2082. u8g2_uint_t w = 0;
  2083. u8g2_uint_t a = u8g2_GetAscent(u8g2);
  2084. if ( *value == ui->arg )
  2085. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 1);
  2086. else
  2087. u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 0);
  2088. if ( ui->text[0] != '\0' )
  2089. {
  2090. w = u8g2_GetUTF8Width(u8g2, ui->text);
  2091. //u8g2_SetFontMode(u8g2, 1);
  2092. a += 2; /* add gap between the checkbox and the text area */
  2093. u8g2_DrawUTF8(u8g2, mui_get_x(ui)+a, mui_get_y(ui), ui->text);
  2094. }
  2095. u8g2_DrawButtonFrame(u8g2, mui_get_x(ui), mui_get_y(ui), flags, w+a, 1, MUI_U8G2_V_PADDING);
  2096. }
  2097. break;
  2098. case MUIF_MSG_FORM_START:
  2099. break;
  2100. case MUIF_MSG_FORM_END:
  2101. break;
  2102. case MUIF_MSG_CURSOR_ENTER:
  2103. break;
  2104. case MUIF_MSG_CURSOR_SELECT:
  2105. case MUIF_MSG_VALUE_INCREMENT:
  2106. case MUIF_MSG_VALUE_DECREMENT:
  2107. *value = ui->arg;
  2108. break;
  2109. case MUIF_MSG_CURSOR_LEAVE:
  2110. break;
  2111. case MUIF_MSG_TOUCH_DOWN:
  2112. break;
  2113. case MUIF_MSG_TOUCH_UP:
  2114. break;
  2115. }
  2116. return 0;
  2117. }
  2118. uint8_t mui_u8g2_u8_opt_parent_wm_pi(mui_t *ui, uint8_t msg)
  2119. {
  2120. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2121. switch(msg)
  2122. {
  2123. case MUIF_MSG_DRAW:
  2124. if ( mui_fds_get_nth_token(ui, *value) == 0 )
  2125. {
  2126. *value = 0;
  2127. mui_fds_get_nth_token(ui, *value);
  2128. }
  2129. mui_u8g2_draw_button_pi(ui, 0, 1, ui->text);
  2130. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), 0, 1, MUI_U8G2_V_PADDING, ui->text);
  2131. break;
  2132. case MUIF_MSG_FORM_START:
  2133. break;
  2134. case MUIF_MSG_FORM_END:
  2135. break;
  2136. case MUIF_MSG_CURSOR_ENTER:
  2137. break;
  2138. case MUIF_MSG_CURSOR_SELECT:
  2139. case MUIF_MSG_VALUE_INCREMENT:
  2140. case MUIF_MSG_VALUE_DECREMENT:
  2141. mui_SaveForm(ui); // store the current form and position so that the child can jump back
  2142. mui_GotoForm(ui, ui->arg, *value); // assumes that the selectable values are at the beginning of the form definition
  2143. break;
  2144. case MUIF_MSG_CURSOR_LEAVE:
  2145. break;
  2146. case MUIF_MSG_TOUCH_DOWN:
  2147. break;
  2148. case MUIF_MSG_TOUCH_UP:
  2149. break;
  2150. }
  2151. return 0;
  2152. }
  2153. static uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg)
  2154. {
  2155. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2156. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2157. switch(msg)
  2158. {
  2159. case MUIF_MSG_DRAW:
  2160. /* done by the calling function */
  2161. break;
  2162. case MUIF_MSG_FORM_START:
  2163. /* we can assume that the list starts at the top. It will be adjisted by cursor down events later */
  2164. /* ui->form_scroll_top = 0 and all other form_scroll values are set to 0 if a new form is entered in mui_EnterForm() */
  2165. if ( ui->form_scroll_visible <= arg )
  2166. ui->form_scroll_visible = arg+1;
  2167. if ( ui->form_scroll_total == 0 )
  2168. ui->form_scroll_total = mui_GetSelectableFieldOptionCnt(ui, ui->last_form_fds);
  2169. //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);
  2170. break;
  2171. case MUIF_MSG_FORM_END:
  2172. break;
  2173. case MUIF_MSG_CURSOR_ENTER:
  2174. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  2175. case MUIF_MSG_CURSOR_SELECT:
  2176. case MUIF_MSG_VALUE_INCREMENT:
  2177. case MUIF_MSG_VALUE_DECREMENT:
  2178. if ( value != NULL )
  2179. *value = ui->form_scroll_top + arg;
  2180. mui_RestoreForm(ui);
  2181. break;
  2182. case MUIF_MSG_CURSOR_LEAVE:
  2183. break;
  2184. case MUIF_MSG_TOUCH_DOWN:
  2185. break;
  2186. case MUIF_MSG_TOUCH_UP:
  2187. break;
  2188. case MUIF_MSG_EVENT_NEXT:
  2189. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  2190. case MUIF_MSG_EVENT_PREV:
  2191. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  2192. }
  2193. return 0;
  2194. }
  2195. uint8_t mui_u8g2_u8_opt_radio_child_wm_pi(mui_t *ui, uint8_t msg)
  2196. {
  2197. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2198. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2199. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2200. switch(msg)
  2201. {
  2202. case MUIF_MSG_DRAW:
  2203. {
  2204. u8g2_uint_t w = 0;
  2205. u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
  2206. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2207. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2208. uint8_t is_focus = mui_IsCursorFocus(ui);
  2209. if ( *value == arg + ui->form_scroll_top )
  2210. u8g2_DrawValueMark(u8g2, x, y, a);
  2211. if ( ui->text[0] == '\0' )
  2212. {
  2213. /* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
  2214. /* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
  2215. mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
  2216. }
  2217. if ( ui->text[0] != '\0' )
  2218. {
  2219. w = u8g2_GetUTF8Width(u8g2, ui->text);
  2220. //u8g2_SetFontMode(u8g2, 1);
  2221. a += 2; /* add gap between the checkbox and the text area */
  2222. u8g2_DrawUTF8(u8g2, x+a, y, ui->text);
  2223. }
  2224. if ( is_focus )
  2225. {
  2226. u8g2_DrawButtonFrame(u8g2, x, y, U8G2_BTN_INV, w+a, 1, MUI_U8G2_V_PADDING);
  2227. }
  2228. }
  2229. break;
  2230. default:
  2231. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  2232. }
  2233. return 0;
  2234. }
  2235. uint8_t mui_u8g2_u8_opt_radio_child_w1_pi(mui_t *ui, uint8_t msg)
  2236. {
  2237. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2238. uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2239. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2240. switch(msg)
  2241. {
  2242. case MUIF_MSG_DRAW:
  2243. {
  2244. //u8g2_uint_t w = 0;
  2245. u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
  2246. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2247. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2248. uint8_t is_focus = mui_IsCursorFocus(ui);
  2249. if ( *value == arg + ui->form_scroll_top )
  2250. u8g2_DrawValueMark(u8g2, x, y, a);
  2251. if ( ui->text[0] == '\0' )
  2252. {
  2253. /* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
  2254. /* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
  2255. mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
  2256. }
  2257. if ( ui->text[0] != '\0' )
  2258. {
  2259. //w = u8g2_GetUTF8Width(u8g2, ui->text);
  2260. //u8g2_SetFontMode(u8g2, 1);
  2261. a += 2; /* add gap between the checkbox and the text area */
  2262. u8g2_DrawUTF8(u8g2, x+a, y, ui->text);
  2263. }
  2264. if ( is_focus )
  2265. {
  2266. u8g2_DrawButtonFrame(u8g2, 0, y, U8G2_BTN_INV, u8g2_GetDisplayWidth(u8g2), 0, MUI_U8G2_V_PADDING);
  2267. }
  2268. }
  2269. break;
  2270. default:
  2271. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  2272. }
  2273. return 0;
  2274. }
  2275. uint8_t mui_u8g2_u8_opt_child_wm_pi(mui_t *ui, uint8_t msg)
  2276. {
  2277. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2278. //uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
  2279. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2280. switch(msg)
  2281. {
  2282. case MUIF_MSG_DRAW:
  2283. {
  2284. //u8g2_uint_t w = 0;
  2285. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2286. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2287. uint8_t flags = mui_u8g2_get_pi_flags(ui);
  2288. //if ( mui_IsCursorFocus(ui) )
  2289. //{
  2290. // flags = U8G2_BTN_INV;
  2291. //}
  2292. if ( ui->text[0] == '\0' )
  2293. {
  2294. /* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
  2295. /* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
  2296. mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
  2297. }
  2298. if ( ui->text[0] != '\0' )
  2299. {
  2300. u8g2_DrawButtonUTF8(u8g2, x, y, flags, 0, 1, MUI_U8G2_V_PADDING, ui->text);
  2301. }
  2302. }
  2303. break;
  2304. default:
  2305. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  2306. }
  2307. return 0;
  2308. }
  2309. /*
  2310. an invisible field (which will not show anything). It should also not be selectable
  2311. it just provides the menu entries, see "mui_u8g2_u8_opt_child_mse_common" and friends
  2312. as a consequence it does not have width, input mode and style
  2313. MUIF: MUIF_RO()
  2314. FDS: MUI_DATA()
  2315. mui_u8g2_goto_parent --> mui_u8g2_goto_data
  2316. Used together with mui_u8g2_goto_form_w1_pi
  2317. */
  2318. uint8_t mui_u8g2_goto_data(mui_t *ui, uint8_t msg)
  2319. {
  2320. switch(msg)
  2321. {
  2322. case MUIF_MSG_DRAW:
  2323. break;
  2324. case MUIF_MSG_FORM_START:
  2325. // store the field (and the corresponding elements) in the last_form_fds variable.
  2326. // last_form_fds is later used to access the elements (see mui_u8g2_u8_opt_child_mse_common and friends)
  2327. ui->last_form_fds = ui->fds;
  2328. break;
  2329. case MUIF_MSG_FORM_END:
  2330. break;
  2331. case MUIF_MSG_CURSOR_ENTER:
  2332. break;
  2333. case MUIF_MSG_CURSOR_SELECT:
  2334. break;
  2335. case MUIF_MSG_CURSOR_LEAVE:
  2336. break;
  2337. case MUIF_MSG_TOUCH_DOWN:
  2338. break;
  2339. case MUIF_MSG_TOUCH_UP:
  2340. break;
  2341. }
  2342. return 0;
  2343. }
  2344. /*
  2345. mui_u8g2_goto_child_w1_mse_pi --> mui_u8g2_goto_form_w1_pi
  2346. */
  2347. uint8_t mui_u8g2_goto_form_w1_pi(mui_t *ui, uint8_t msg)
  2348. {
  2349. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2350. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2351. switch(msg)
  2352. {
  2353. case MUIF_MSG_DRAW:
  2354. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top) )
  2355. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui), ui->text+1);
  2356. break;
  2357. case MUIF_MSG_CURSOR_SELECT:
  2358. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
  2359. {
  2360. mui_SaveFormWithCursorPosition(ui, ui->arg + ui->form_scroll_top);
  2361. 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
  2362. return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
  2363. }
  2364. break;
  2365. default:
  2366. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  2367. }
  2368. return 0;
  2369. }
  2370. uint8_t mui_u8g2_goto_form_w1_pf(mui_t *ui, uint8_t msg)
  2371. {
  2372. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2373. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2374. switch(msg)
  2375. {
  2376. case MUIF_MSG_DRAW:
  2377. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top) )
  2378. mui_u8g2_draw_button_pf(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui)-1, ui->text+1);
  2379. break;
  2380. case MUIF_MSG_CURSOR_SELECT:
  2381. if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
  2382. {
  2383. mui_SaveFormWithCursorPosition(ui, ui->arg + ui->form_scroll_top);
  2384. 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
  2385. return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
  2386. }
  2387. break;
  2388. default:
  2389. return mui_u8g2_u8_opt_child_mse_common(ui, msg);
  2390. }
  2391. return 0;
  2392. }
  2393. /*
  2394. data: mui_u8g2_list_t *
  2395. */
  2396. uint8_t mui_u8g2_u16_list_line_wa_mse_pi(mui_t *ui, uint8_t msg)
  2397. {
  2398. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  2399. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  2400. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  2401. void *data = mui_u8g2_list_get_data_ptr(list);
  2402. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  2403. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  2404. switch(msg)
  2405. {
  2406. case MUIF_MSG_DRAW:
  2407. mui_u8g2_draw_button_pi(ui, ui->arg, 1, element_cb(data, *selection));
  2408. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, element_cb(data, *selection));
  2409. break;
  2410. case MUIF_MSG_FORM_START:
  2411. break;
  2412. case MUIF_MSG_FORM_END:
  2413. break;
  2414. case MUIF_MSG_CURSOR_ENTER:
  2415. break;
  2416. case MUIF_MSG_CURSOR_SELECT:
  2417. case MUIF_MSG_VALUE_INCREMENT:
  2418. (*selection)++;
  2419. if ( *selection >= count_cb(data) )
  2420. *selection = 0;
  2421. break;
  2422. case MUIF_MSG_VALUE_DECREMENT:
  2423. if ( *selection > 0 )
  2424. (*selection)--;
  2425. else
  2426. (*selection) = count_cb(data)-1;
  2427. break;
  2428. case MUIF_MSG_CURSOR_LEAVE:
  2429. break;
  2430. case MUIF_MSG_TOUCH_DOWN:
  2431. break;
  2432. case MUIF_MSG_TOUCH_UP:
  2433. break;
  2434. }
  2435. return 0;
  2436. }
  2437. uint8_t mui_u8g2_u16_list_line_wa_mud_pi(mui_t *ui, uint8_t msg)
  2438. {
  2439. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  2440. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  2441. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  2442. void *data = mui_u8g2_list_get_data_ptr(list);
  2443. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  2444. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  2445. switch(msg)
  2446. {
  2447. case MUIF_MSG_DRAW:
  2448. mui_u8g2_draw_button_pi(ui, ui->arg, 1, element_cb(data, *selection));
  2449. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, element_cb(data, *selection));
  2450. break;
  2451. case MUIF_MSG_FORM_START:
  2452. break;
  2453. case MUIF_MSG_FORM_END:
  2454. break;
  2455. case MUIF_MSG_CURSOR_ENTER:
  2456. break;
  2457. case MUIF_MSG_CURSOR_SELECT:
  2458. case MUIF_MSG_VALUE_INCREMENT:
  2459. case MUIF_MSG_VALUE_DECREMENT:
  2460. /* toggle between normal mode and capture next/prev mode */
  2461. ui->is_mud = !ui->is_mud;
  2462. break;
  2463. case MUIF_MSG_CURSOR_LEAVE:
  2464. break;
  2465. case MUIF_MSG_TOUCH_DOWN:
  2466. break;
  2467. case MUIF_MSG_TOUCH_UP:
  2468. break;
  2469. case MUIF_MSG_EVENT_NEXT:
  2470. if ( ui->is_mud )
  2471. {
  2472. (*selection)++;
  2473. if ( *selection >= count_cb(data) )
  2474. *selection = 0;
  2475. return 1;
  2476. }
  2477. break;
  2478. case MUIF_MSG_EVENT_PREV:
  2479. if ( ui->is_mud )
  2480. {
  2481. if ( *selection == 0 )
  2482. *selection = count_cb(data);
  2483. (*selection)--;
  2484. return 1;
  2485. }
  2486. break;
  2487. }
  2488. return 0;
  2489. }
  2490. /*
  2491. MUIF: MUIF_U8G2_U16_LIST
  2492. FDS: MUI_XYA, arg=form id
  2493. data: mui_u8g2_list_t *
  2494. */
  2495. uint8_t mui_u8g2_u16_list_parent_wm_pi(mui_t *ui, uint8_t msg)
  2496. {
  2497. //u8g2_t *u8g2 = mui_get_U8g2(ui);
  2498. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  2499. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  2500. void *data = mui_u8g2_list_get_data_ptr(list);
  2501. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  2502. //mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  2503. switch(msg)
  2504. {
  2505. case MUIF_MSG_DRAW:
  2506. mui_u8g2_draw_button_pi(ui, 0, 1, element_cb(data, *selection));
  2507. //mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, element_cb(data, *selection));
  2508. break;
  2509. case MUIF_MSG_FORM_START:
  2510. break;
  2511. case MUIF_MSG_FORM_END:
  2512. break;
  2513. case MUIF_MSG_CURSOR_ENTER:
  2514. break;
  2515. case MUIF_MSG_CURSOR_SELECT:
  2516. case MUIF_MSG_VALUE_INCREMENT:
  2517. case MUIF_MSG_VALUE_DECREMENT:
  2518. mui_SaveForm(ui); // store the current form and position so that the child can jump back
  2519. mui_GotoForm(ui, ui->arg, *selection); // assumes that the selectable values are at the beginning of the form definition
  2520. break;
  2521. case MUIF_MSG_CURSOR_LEAVE:
  2522. break;
  2523. case MUIF_MSG_TOUCH_DOWN:
  2524. break;
  2525. case MUIF_MSG_TOUCH_UP:
  2526. break;
  2527. }
  2528. return 0;
  2529. }
  2530. static uint8_t mui_u8g2_u16_list_child_mse_common(mui_t *ui, uint8_t msg)
  2531. {
  2532. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  2533. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  2534. void *data = mui_u8g2_list_get_data_ptr(list);
  2535. //mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  2536. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  2537. uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
  2538. switch(msg)
  2539. {
  2540. case MUIF_MSG_DRAW:
  2541. /* done by the calling function */
  2542. break;
  2543. case MUIF_MSG_FORM_START:
  2544. /* we can assume that the list starts at the top. It will be adjisted by cursor down events later */
  2545. ui->form_scroll_top = 0;
  2546. if ( ui->form_scroll_visible <= arg )
  2547. ui->form_scroll_visible = arg+1;
  2548. if ( ui->form_scroll_total == 0 )
  2549. ui->form_scroll_total = count_cb(data);
  2550. break;
  2551. case MUIF_MSG_FORM_END:
  2552. break;
  2553. case MUIF_MSG_CURSOR_ENTER:
  2554. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  2555. case MUIF_MSG_CURSOR_SELECT:
  2556. case MUIF_MSG_VALUE_INCREMENT:
  2557. case MUIF_MSG_VALUE_DECREMENT:
  2558. if ( selection != NULL )
  2559. *selection = ui->form_scroll_top + arg;
  2560. mui_RestoreForm(ui);
  2561. break;
  2562. case MUIF_MSG_CURSOR_LEAVE:
  2563. break;
  2564. case MUIF_MSG_TOUCH_DOWN:
  2565. break;
  2566. case MUIF_MSG_TOUCH_UP:
  2567. break;
  2568. case MUIF_MSG_EVENT_NEXT:
  2569. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  2570. case MUIF_MSG_EVENT_PREV:
  2571. return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
  2572. }
  2573. return 0;
  2574. }
  2575. uint8_t mui_u8g2_u16_list_child_w1_pi(mui_t *ui, uint8_t msg)
  2576. {
  2577. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2578. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  2579. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  2580. void *data = mui_u8g2_list_get_data_ptr(list);
  2581. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  2582. mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  2583. uint16_t pos = ui->arg; // remember the arg value, because it might be overwritten
  2584. switch(msg)
  2585. {
  2586. case MUIF_MSG_DRAW:
  2587. {
  2588. //u8g2_uint_t w = 0;
  2589. u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
  2590. u8g2_uint_t x = mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2591. u8g2_uint_t y = mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called, then field vars are overwritten, so get the value
  2592. uint8_t is_focus = mui_IsCursorFocus(ui);
  2593. pos += ui->form_scroll_top;
  2594. if ( *selection == pos )
  2595. u8g2_DrawValueMark(u8g2, x, y, a);
  2596. //u8g2_SetFontMode(u8g2, 1);
  2597. a += 2; /* add gap between the checkbox and the text area */
  2598. if ( pos < count_cb(data) )
  2599. u8g2_DrawUTF8(u8g2, x+a, y, element_cb(data, pos));
  2600. if ( is_focus )
  2601. {
  2602. u8g2_DrawButtonFrame(u8g2, 0, y, U8G2_BTN_INV, u8g2_GetDisplayWidth(u8g2), 0, MUI_U8G2_V_PADDING);
  2603. }
  2604. }
  2605. break;
  2606. default:
  2607. return mui_u8g2_u16_list_child_mse_common(ui, msg);
  2608. }
  2609. return 0;
  2610. }
  2611. uint8_t mui_u8g2_u16_list_goto_w1_pi(mui_t *ui, uint8_t msg)
  2612. {
  2613. u8g2_t *u8g2 = mui_get_U8g2(ui);
  2614. mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
  2615. uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
  2616. void *data = mui_u8g2_list_get_data_ptr(list);
  2617. mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
  2618. //mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
  2619. uint16_t pos = ui->arg; // remember the arg value, because it might be overwritten
  2620. pos += ui->form_scroll_top;
  2621. switch(msg)
  2622. {
  2623. case MUIF_MSG_DRAW:
  2624. mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui), element_cb(data, pos)+1);
  2625. //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);
  2626. break;
  2627. case MUIF_MSG_CURSOR_SELECT:
  2628. case MUIF_MSG_VALUE_INCREMENT:
  2629. case MUIF_MSG_VALUE_DECREMENT:
  2630. if ( selection != NULL )
  2631. *selection = pos;
  2632. mui_SaveFormWithCursorPosition(ui, pos >= 255 ? 0 : pos);
  2633. mui_SaveCursorPosition(ui, pos >= 255 ? 0 : pos); // store the current cursor position, so that the user can jump back to the corresponding cursor position
  2634. mui_GotoFormAutoCursorPosition(ui, (uint8_t)element_cb(data, pos)[0]);
  2635. break;
  2636. default:
  2637. return mui_u8g2_u16_list_child_mse_common(ui, msg);
  2638. }
  2639. return 0;
  2640. }