Modular and extensible UI framework and ui elements. #3424
Replies: 36 comments
-
Posted at 2016-09-18 by @allObjects 2 of n posts To provide a first glimps into the components, here some code facts:
The numbers for the slider ui element have not exactly settled yet, but are around the double of a plain button... considering the capabilities, still a very small foot print... ...and this is the actual code: Tip for best display of code sections without line wrapping : change browser window to the sweet spot where no line wrapping happens.
The To understand touch screen related lines 45..47, take a look at recent Touchscreen conversation. Lines 49..50 and 52..53 are cross development environment related and were a quick (and dirty) compromise to keep the emulating modules application independent... These lines do not belong into Espruino, and that's why they are conditioned and do therefore no harm... As in above paragraph, emulation shows... but really marginal... and with some smart thinking - or (with some not so beloved) conventions - emulation can become completely transparent. The code shows how the Espruino code is prefixed in order to run in cross development. Below few javascript lines are the only required entries to precede the Espruino code to run it in an plain html document in a Web browser:
As obvious, a plain Lines 3..5 show this loader that adds javascript on the go, as you see in lines
I was surprised how well the UI behaves regarding speed - even though the communication with the display is serial... Text (drawString()) still drags its feet - understandably - but all other things are extremely snappy, such as visual touch feedback. I guess it is thanks to @jumjum who recently made some speed enhancement when using the Graphics objects - the 'inner' implementing of the LCD displays... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by Pinnchus Have you posted the module somewhere accessible? Thanks, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by @allObjects ...got a bit stuck in doc and work... will show in public in a bit... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by @allObjects @user54159 , check your forum messages... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by Pinnchus @allObjects Thanks!!!! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects uiReadMe.txt Hi, The modular and extensible ui framework for Espruino from allObjects - is now ready for use 'as is' (finishing touches still ongoing). 6 folders - _sbx (an espruino sandbox ready to be used), _ecomponents, uidev, edev, uidoc and uixsrcmaterial - and this post as text in ui.zip file fort download below. Unzip them into any directory. Make _sbx the sandbox folder in Espruino Web IDE. Upload the (example) projects to run them on your Espruino board. Not the right hardware (yet) at hand? or: Not much time either for a sneak peek? - No problem: Look at and play around with the very same examples in your Browser... To run / develop the same modules and projects in emulation / cross development mode in Browser: open .html files - uiExample.html - in uidev folder and click link all. uxscrmaterial folder contains many useful examples and older, simpler versions of the ui, most of them still working. Some of them will migrate over time into the actual modules and projects folders. Goal is to harden the modules, grow the example pool, add examples for various hardware, also hardware without touch screen support, and make it all available on the Espruino site - as modules and as tutorial(s). best js hacks - @allObjects Attached: shot showing zip file content, ui_20190927.zip (zipped ui folder w/ all you need for ui). - ui_20191119.zip - newer version (still in work)Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- ui_ ------------------------- 20190927 - intro *** modular and extensible (graphical) ui framework - regular version. The framework consists of a bases module which provides the infrastructure
An out of box extension provides utility and convenience functions and Creating and integrating custom ui elements and extensions as needed All ui elements handled by ui framework have roughly 12 (13) common
Only the 1st 9 of the 12 (13) properties are really mandatory. Same Details about the ui element specific properties for construction and The ui communicates input (and other) events through callbacks. The
Attached shot: ui start up w/ all ui element types and keyboard (in emulation).Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- ui_ ------------------------- 20190919 - intro *** ui framework - base module - intro The --- Implementation approach The --- Memory / Variable usage Below some (ballpark) figures on various usage, categorized as U
Minification setting in Espruino Web IDE: Esprima (offline) for both code *** Basic Application of ui base and - as example - use of uiBtn (Button) element Get ui base and ui elements and build ui - like a DOM - by ui definitions in --- Require ui components Get ui base and ui elements to the extent as needed into the system,
----- Define UI and add elements Definition of UI(s) - creation of 'DOM'(s) - best happen (with Espruino)
--- Define application stuff The application acts on ui events that are communicated thru callbacks.
--- Do devices stuff Device stuff happens on upload - once - and defines the display and the The If the touch screen has a controller, use its module - like
--- Define the onInit() function Function
--- Start the code after uploadis After uploading the code, enter
*** Description of (graphical) ui base module and touch controller interface --- Functions / methods of ui base module The
--- **UI (touch) event object (passed in callbacks)**is The touch event object
Touch event flags
Re-focusing happens when having touched down, dragged out of the element In preferred callback, a typical untouch - touch down on a ui element and
Untouching after moving / dragging out of the bounding box of the touched
In the preferred callback fired on ontouch only - touch started with The alternative callback fires on every kind of touch event and demands --- Colors and Color Definitions ui base module includes a default color converter that supports 3-bit
The default color converter accepts for c a value from 0..7 for the basic The color converter is is invoked by ui's color setting method --- Enhanced Color Converter With the enhanced color converter as below, colors can be specified in
The n custom colors of the custom color palette are stored in the same
For [r,g,b] specification, Espruino Graphics modules accepts for each Normalized color specification value is mapped to actual color based on The n custom colors of the custom color palette are stored in the same --- Custom ui elements and extensions In order to not collide with future development of the ui components --- More... The unminified sources and examples have in-line documentation - same --- ui - base code into which elements and custom code are mixed in
Attached shot: Button b1 and then button b2 'tapped'.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- uiBtn ------------------------- 20190927 *** ui button module The ui button module extends ui base with button ui element. Implementation note: vs3 overlaps/is duplicates of uiExt module and --- Enable ui base with uiBtn and create a button with callback on untouch:
--- Create - specify - plain buttons
Creates, adds to ui, conditionally displays and returns an active(2), Colors are bit-coded with 3-bit color-depth according ui.clrs=[...] setup. Callback cb is called on untouch with
For ui base, color, label, and callback details see (also) ui base module. For detailed ui setup, including color depth and custom colors, connecting No board or display with touch screen yet? No Problem: Open --- Some more details A button with border and fill colors equal to display background uiBtn can be changed within callback: for example in example above, the
The same callback shared by multiple uiBtns can produce button specific Note: The preferred touch event to invoke the callback is on untouch,
To use the (experimental) alternative callback called on all touch events, Using a synchronous implementation for callback on touch down may delay If the button has to change to give additional visual feedback to the user To prevent additional touch down events on the button to prevent Example of a button with both untouch and touchdown event callback:
If you use both callbacks and put 'the (heavy) work' of the touch down --- btn ui element constructor arguments (a[]) and runtime data structure (e[]) are:
Attached shot: uiBtn - button - example (in emulation) - touching down on b1, dragging over b2 and back to b1 and then untouch b1 = tapping b1.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- uiChk ------------------------- 20190927 *** ui checkbox module The ui checkbox module extends ui base with checkbox ui element. Implementation note: vs2 overlaps/is duplicates of uiExt module and --- Enable ui base with uiChk and create a checkbox with callback on untouch:
--- Create - specify - check box
Creates, adds to ui, conditionally displays and returns an active(2), Colors are bit-coded with 3-bit color-depth according ui.clrs=[...] setup. For ui base, color, label, and callback details see (also) ui base module. Callback cb is called on untouch with
For detailed ui setup, including color depth and custom colors, connecting No board or display with touch screen yet? No Problem: Open For helpful details to use the ui base and ui element APIs, take a look --- chk ui element constructor arguments (a[]) and runtime data structure (e[]) are:
Attached shot: Check box c1 and then check box c2 'tapped'.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- uiExt ------------------------- 20190927 The ui extension is currently required by:
--- Brief documentation of the methods / functions available For your application
Full list in alphabetic order:
--- ext - ui extension properties - variables and methods - mixed into ui base
Attached shot: shows the browser developer / debug view with the browser console log, to which the ui framework is logging to by injected functions.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- uiRad ------------------------- 201909227 *** ui radio button module The Note: It requires the uiExt - ui extension module - to be loaded first. --- Enable ui base with uiRad element functions: Note: requires uiExt(ension) module (see uiExt.js module)
--- Create - specify - radio buttons
Crates and add to ui three active(2), visible(1) =(3) radio buttons at Colors are bit-coded with 3-bit color-depth according ui.clrs=[...] setup. Callback cb is called on untouch with
For detailed ui setup, including color depth and custom colors, connecting No board or display with touch screen yet? No Problem: Open For helpful details to use the ui base and ui element APIs, take a look --- rad ui element constructor arguments (a[]) and runtime data structure (e[]) are:
Attached shot: Tabbed thru uiRad - radio buttons.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- uiSli ------------------------- 20190927 *** ui slider module ui slider module extends ui base with slider ui element. --- Enable ui base with uiSli and create a slider with callback on untouch:
--- Create - specify - a slider
Creates, adds to ui, conditionally displays and returns and stores in Custom formatter has dual purpose:
Because rendering - drawing strings on a display - can be slow, rendering Colors are bit-coded with 3-bit color-depth according ui.clrs=[...] setup. Since slider has two (2) areas to fill - left and right side of slider -
Since slider has drag aspects callback and should also be able to deliver Callback is called with
For detailed ui setup, including color depth and custom colors, connecting No board or display with touch screen yet? No Problem: Open For helpful details to use the ui base and ui element APIs, take a look --- sli ui element constructor arguments (a[]) and runtime data structure (e[]) are:
Attached shot: Slider s1 and slider s2 moved / 'dragged'.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- uiInp ------------------------- 20190927 *** ui input field module ui input module extends ui base module with input field ui element. Note: requires uiExt(ension) module (see uiExt.js module) --- Enable ui with uiInp element functions:
--- Create and add to ui an active(2), visible(1) =(3) input field at x/y Colors are bit-coded with 3-bit color-depth according ui.clrs=[...] setup.
Callback cb is called on release (untouch) and change and
For detailed ui setup, including color depth and custom colors, connecting No board or display with touch screen yet? No Problem: Open For helpful details to use the ui base and ui element APIs, take a look --- inp ui element constructor arguments (a[]) and runtime data structure (e[]) are:
Attached shot: 'cleared' entry field tapping x in top right corner; 'typed' on keyboard by tapping: 1 x shift (one shot shift sh1 ^^) - Key K - 3 x shift or long tap (num lock #^) - key 3 - 1 x shift (back to no shift sh0 ^) - y key, 2 x shift (shift lock sh2 ^^^) - Keys B O A R D - 2 x shift (back to no shift sh0 ^) - key x - long tap bottom right button - back space / bs - removes last keyed x.Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ----- keyboard/keypad - 3 x 10 Btns ------------------------- 20190927 *** uiKbd3x10B - ui keyboard module w/ 3 rows x 10 columns of uiBtn ui elements. Note: uiKbd3x10B IS NOT part of the ui singleton. It is a standalone --- Key assugnments and mappings For Keyboards with buttons, key ids are the button ids, and button ids are
Keyboard key handler calls cb callback w/ values v, k, u, e, and t parameters:
e is the key board button that has just been untouched (k: keyboard, u: ui Key value depends on short TAP / LONG TOUCH and shift key mode. The ^-shift key cycles w/ short taps through ^ m=0, ^^ m=1, ^^^ m=2, For REGULAR keys, shift key modes and returned chars with regular - SHORT
LONG TOUCH return number for key with numbers - top row - and for other The ^-shift key itself returns key values: "sh"+mode: "sh0", "sh1", "sh2" Special keys with shift mode 0..3 returns (listed by key, mode and short
In other words - basically:
--- Usage example get the keyboard and 'connect' it to entry field "i1" - as part of UI definition: Note: this keyboard modules requires ui base and uiBtn modules to be
--- Module .connect(arguments)
--- uiKbd3x10B - soft keyboard properties - variables and methods - mixed into ui base:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-20 by @allObjects ui varia 3 - tbp |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-25 by @allObjects ----- 2019-09-24 Update ----- Finally some rework and review round trip completed to share things that had its design in 2015, some rework in 2016 and 2017 and just now. Updated zip file is to be found in --->post #7 . Reviewing and getting code and some doc ready for pub did not go without some enhancements and adding a few vars to the foot print. Event categorization with flags and handling got a significant lift to give more control to the user and application. Also the slider got a technical as well as a face lift. Some issues got resolved, such as ui elements changing unintended their values by just dragging over them. Input field is still a bit bare bones and kept as such... last but not least because of slowness of (communication to) most displays. Have to come up w/ some enhanced version... being a different ui element 'clazz' though to keep the simple version with small foot print. The general idea of publishing in this conversation is to get it out and get feedback. Over time these posts will change including the zip file uploaded in post #8 with all the code - modules, examples and cross development components (on functional changes). Old versions will be kept there as long as possible. After a while things will move into regular site's modules folder and into module and tutorial pages. Cu after reading up from ---> post #7 on. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-28 by @allObjects ----- 2019-09-27 Update ----- As new extension module has been added: support for control with watched push buttons rather than with touch screen - see ---> post #17 . Same time, the keyboard, the input fields and the uiExt extension got some enhancements, last but not least to support watched buttons to drive the ui. So far all but the sliders can be used - with three (3) buttons it is very comfortable: two (2) buttons to cycle forward and backward thru he ui elements and the third - 'Enter' / Tap - button is for tapping. Timing the tapping - how long the push button has been pressed and passing it when calling the tap selected ui element -
The input field has a callback that checks tap time, and when it is more than 550 ms, the input field is cleared. The delete x in the top right corner of the input field is part of the ui element and not one of its own, so it cannot be reached with cycling through the ui elements. Having separate buttons for navigation / 'moving' the selection and the action tapping makes operation safe. Increasing the time for clearing the input field to make it distinctive from cycling backwards with a long press. Other, non-functional changes is the renaming of the example: replacing the DspTouch infix in the names with just Example provides room the examples to also include button operation vs touch operation. Both can be used simultaneously... (with one caveat: touchscreen tapping does not preserve the visual cue what ui element is selected at times. Updated zip file is to be found in --->post #7 . |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-09-28 by Robin Sat 2019.09.28 What a fantastic contribution @allObjects I'm sure you are proud of the final result, now with the finish line in sight!! Had a hunch there would be a fair amount of updating content when I recognized the dozen of link earmarked entries a week ago. Although I won't have immediate time to delve into your accomplishment right now, will set aside some time this winter. Well done. Congrats! EDIT: (ten minutes later) Love the immediate run/launch with the Html pages. Just tried the button press uiExample.html and it works without configuration in Chrome on Windows10, just launch and go. Simple, intuitive, impressive. BRAVO! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-10-01 by @allObjects ----- 2019-09-30 Update ----- Espruino Pixl makes its debut the ui framework... see the Preview in ---> post #18. From #post 18, download, unzip the attached zip file with the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-11-27 by @allObjects New update - with work in progress - that includes Emulations for Pixle.js and even Bangle.js... some work is still going on, especially for handling the non-touch and limited touch screens. Navigation from element to element in the ui works, 'clicking' on (regular) buttons, checkboxes and radio buttons work. Clicking on horizontal and vertical slider are setting their values so far - matter fact of touch emulation in the center - to the middle value. More to come there. Since all is JavaScript you can write code to practically emulate what ever you think of... You would just not emulate on the very low level hardware, but on the module level, add value input fileds and buttons to the html view to bring the module to life and let your application handle it properly in the emulation. This way even coding and emulating of time sensitive / ui dynamic applications are possible. The code already includes Pins and Buttons - specified in the board includes - and setWatch/clearWatch for buttons in the emulator HTML view. If you miss a behavior or item, just extend existing item or add a new one. Updated zip file is to be found in --->post #7 .Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-11-27 by @MaBecker Have you tried your UI with the Bangle Emulator? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-11-27 by @allObjects Yes I did and I like it very much... I know that - for some - an emulator may take a bit the push away to get a real board... on the other hand it makes development of logic so much easier, especially since the upload over BLE 'snails'. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-19 by @MaBecker [ ] How to use firmware included touch screens with ui? Bangle2 Emulator
ESP32 CYD
[ ] How to use build in fonts with ui?
check for setFontXXXXX functions show that setFont6x8 is missing because it is different included than 6x15.
Solution: Including "6x8" directly into the ui.fnts array and make sure it can set via g.setFont6x8
[ ] Any plans to include uiG(auge) as module? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-19 by @allObjects looks like that these are you questions: a. [ ] How to use firmware included touch screens with ui? Generally speaking: starting out with a (custom named and referenced) wrapper that is housing the built-in things - touch / font - is good to start with. The reason for that is that when the UI was built, bangles weren't around yet... But it should then be easy to modify the code to drop the wrapper and use the built-in appliances directly. All is pulled in as modules, so changes can happen gradually. Since displays have quite some variations, take a look at how colors and fonts are referenced in the ui definition and how the respective support mapes it into the hw context. Modules are also pulled by name dynamically, so control can happen in a single place w/ a config-like object, which then can be made dependent on the context / hw ID. ttyl. ao |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-19 by @MaBecker Yes and have one more for now. d. [ ] Can ui switch to Anti-Aliasing functions if available? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-19 by @allObjects It could affect some functionality if the font goes too close to the borders. I show a frame around an active field to show focus and clear it w/ the redrawing the same frame with back ground color. When anti-aliasing goes 'too close' to such frame, you may notice interferences. In the context where and for what the UI was done, memory is on short supply... so no layering... layering would have been the answer to many things. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-19 by @allObjects Since the UI framework was conceived, a lot has changed in Espruino world. The most impacting change is that Bangle2 has a built in touch screen and firmware functions way superior to the touch modules ever existed. Basic touch modules deliver two (2) types of events:
That is the reason that the Rewriting of Two (2) sections the introductory page at espruino.com/ui - UI Framework for microcontrollers are affected:
Take a look at the complete code - same example as documented at [https://www.espruino.com/uiExampleBtn](UI Example - Buttons):
Since dealing with (vector) fonts is always a bit a lottery, the position of the RED button label needed some adjustment.... Interestingly, the label in the second button did just fine... @MaBecker pointed out that there are some other things that need minor changes... one is related to how (default) fonts are loaded and set in current Espruino Graphics object. More about that from @gfwilliams or me, later on. As a closing icing on the cake, I'd like to introduce - re-introduced - a more elaborate callback for the RED button:
1st change:
2nd change:
The 2nd change needs also some layout changes because of the longer button label text (widening the RED button by 5 px (w+5) to 70 and moving the 2nd button 5 pixel (x+5) to the right to 70):
Running the second change (after all those years) became a surprise: Unfortunately, something has changed in the Espruino js interpreter when it comes to address an array literally with a 0 as the console points out:
Something weird... because when duping the element in the console, it shows value 7 - 4 flags set - in its array (state members of the ui element)... even when dumping it after the error happened... Weird, because when accessing the value in console's REPL, it can do so:
Looking at the
From looking at the code and its syntax, the error message makes no sense what so ever... The literal integer number (Yes, the construct re-uses the variable Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-20 by @allObjects ...ooops, I was wrong to conclude from the error that the interpreter has an issue... I looked at the source code I had and did not notice that the ui module version in espruino.com/modules - where you get it with require, has a bug in the display method (`,d: function(...){}). There several 2 ways to fix this until module is fixed. a) you can download a version from forum as documented there () and load the modules from y9ou local modules folder... b) you load the broken module, and then override
Above fix works for both minified and non minified version... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-20 by @allObjects Notice the change in the callback for the 2nd enhancement to set the label of the button depending the state of the RED LED1:
Without the parenthesis around the ternary operator statement, it fails. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-18 by @allObjects
1 of n posts
Tip for best display of code sections without line wrapping : change browser window to the sweet spot where no line wrapping happens.
A while ago I played around with touch screen displays that resulted in a quite terse, resource frugal UI implementation: UI Module w/ Buttons, Checkboxes,... for Display w/ Touchscreen.
Recently I picked up where left of and completed what I was originally going for. Several serious refactoring cycles lead to the 'thing' I'd like to share, to contribute as generally available Espruino modules, and also to provide some tutorials to introduce the rich options... last but not least an introduction how to build and integrate your own ui element extensions.
Already too many words, therefore a picture right away... actually more than one... See image attachments showing Buttons, Check Boxes, Radio Buttons, Sliders and even a soft '101'-Key keyboard, all on a touchscreen LCD (...which you get for a few bucks).
More out of a need or constraint than intentionally, I developed a simple cross development environment in the Web browser - after all, it is with display, and the browser has what is needed: display AND JavaScript. The browser gets the modules from the same sand box folder as the Espruino Web IDE and thus validation in the real environment is just an upload click away... (...is as close as an upload click... on the same screen, just in different window). I'll share crosses development as well. At this point it is developed to the point to support this particular ui framework development work, but it has the core ingredients - such as the cache - that allows to add emulating modules for many hard ware modules to run complete applications.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions