You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/arduino-libraries/tc-menu/renderer-take-over-display.md
+46-28Lines changed: 46 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,17 +14,21 @@ weight = 2
14
14
toc_needed = true
15
15
+++
16
16
17
-
TcMenu allows you to take over the display from the renderer very easily, once you own the display, you will be called back at regular intervals by the rendering class, and it is your responsibility to update the display at this time (if there are changes that require redrawing). **You should never update the screen outside of these callbacks**, as doing so would interfere with TcMenu rendering.
17
+
TcMenu allows you to take over the display from the renderer very easily, and once you own the display, you will be called back at regular intervals by the rendering class. During the time that you've taken over the display or presented a dashboard, you're responsible for the user input and rendering. **Please note that you should never update the screen outside of these callbacks**, as doing so would interfere with TcMenu rendering.
18
18
19
-
There are three choices for drawing custom screens:
19
+
{{< blockClear "left" >}}
20
+
21
+
## Different methods for taking control of the display
22
+
23
+
There are three choices for custom drawing:
20
24
21
25
* A functional approach based on providing a callback function that gets called frequently to draw
22
26
* An object-oriented approach, where you provide an extension of `CustomDrawing` to the renderer, it gets called at various points in the renderer's lifecycle (reset, start, draw).
23
27
* Using the custom `DrawableDashboard` support where you provide one or more dashboard configurations, with the option of further customizing it using a delegate.
24
28
25
29
Below we discuss them all in turn.
26
30
27
-
## Functional approach to take over display
31
+
## 1. Functional approach to take over display
28
32
29
33
To use a regular function callback to take over the display:
30
34
@@ -46,7 +50,7 @@ When conditions change such that you no longer need display control:
46
50
47
51
renderer.giveBackDisplay();
48
52
49
-
## Functional approach to capturing display timeout / reset
53
+
###Functional approach to capturing display timeout / reset
50
54
51
55
You can also add a callback function that will be informed when the menu is reset after timing out, by default this happens after 30 seconds of inactivity. This is useful if you don't want to display the menu all the time. First define the function:
52
56
@@ -71,7 +75,7 @@ Or even turn off the reset / inactivity support altogether:
71
75
72
76
The original purpose of the reset / inactivity support was for complex menus, where if the user left the system deeply nested several menus down, after a timeout it would return to the root of the structure ready for the next user.
73
77
74
-
## Object oriented approach to display management
78
+
## 2. Object oriented approach to display management
75
79
76
80
If we extend the class `CustomDrawing` and provide that instance to the renderer, then we can both handle taking over the display and reset events at the same time. {{< refdocs title="See custom drawing class in reference docs" src="/tcmenu/html/class_custom_drawing.html" >}}. Here we present a simple way to extend it.
77
81
@@ -115,50 +119,55 @@ Then to take over the display, use the no parameter version of the method:
115
119
116
120
renderer.takeOverDisplay();
117
121
118
-
## Using the `DrawableDashboard` to draw a dashboard
122
+
## 3. Using the `DrawableDashboard` to draw a dashboard
119
123
120
124
`DrawableDashboard` makes it possible to create dashboard style views out of menu items with only a few lines of code. Each dash item is basically a menu item that you can choose how it is presented. You can set where they appear on the screen, color, font and how much space to take up. The easiest way to get started is probably to look at one of the examples (such as the SimHub example).
121
125
122
-
You can have more than one dashboard but only one can be attached to the renderer at once.
126
+
Below is an example dashboard from the `esp32Simhub` example, it is from a racing simulator and contains a few different menu items presented in the dashboard, and also some custom items as well. We'll go through each below.
127
+
128
+
{{< figure src="/products/arduino-libraries/images/electronics/arduino/themes/tft-dashboard-example.jpg" title="Dashboard example on ILI9431" alt="An example dashboard rendered onto a TFT ILI9431 display" width="200px" >}}
123
129
124
-
Generally speaking we create a main dashboard object as a pointer to a `DrawableDashboard`. For example, you may create it as follows:
130
+
If we look at the above image, we see that it has a very large `N` item on the left which is the value of the current gear menu item, this is using a very large font that can easily be generated using [tcMenu Designers font generator]({{< relref "using-custom-fonts-in-menu.md">}}). To the right we have some more menu items with static text next to them, and at the top, we custom draw the LED matrix. The full example is packaged with [tcMenu library in the examples/esp folder](https://github.com/TcMenu/tcMenuLib/blob/main/examples/esp/esp32SimHub/dashboardSetup.cpp).
131
+
132
+
To get started, we create a main `DrawableDashboard` object and as it is done only once at startup we normally use `new` to create it. For example:
125
133
126
134
mainDashboard = new DrawableDashboard(renderer.getDeviceDrawable(), &renderer, &widgetConnected,
127
135
DrawableDashboard::DASH_ON_RESET_CLICK_EXIT);
128
136
129
-
You then set the main colors for the dashboard (background and primary foreground):
Where the coordinates are the top left, the parameters are described below, the valueChars is the width in characters, you can optionally override the title, and optionally set how many ticks the value highlights on update for.
155
+
Where `menuItem` is the item to present, then the coordinates provided by the `Coord`are the top left, the `drawingParameters` are described below, the valueChars is the width in characters, you can optionally override the title for the item, and optionally set how many ticks the value highlights on update for. Colors are best provided using the `RGB(red, green, blue)` macro using values between 0..255.
147
156
148
-
The simplest drawing parameters is defined as follows, the colors never change:
157
+
The simplest drawing parameters is defined as follows, the colors are fixed, and you can provide alignment (see below) and font:
You can define parameters that highlight the value when the value changes:
161
+
In addition to above, You can define parameters that highlight the value when the value changes, parameters are as above, but with a highlight background and foreground color:
You can define parameters that highlight as integer values change, relevent to Analog, Enum, Boolean and ScrollChoice menu items:
166
+
You can define parameters that highlight as integer values change, for example an analog value may turn red when a certain value is reached, this is relevant to Analog, Enum, Boolean and ScrollChoice menu items:
@@ -174,15 +183,24 @@ You can define parameters for text items that match on equality:
174
183
175
184
For alignment the options are:
176
185
177
-
* TITLE_LEFT_VALUE_LEFT
178
-
* TITLE_LEFT_VALUE_RIGHT
179
-
* NO_TITLE_VALUE_LEFT
180
-
* NO_TITLE_VALUE_RIGHT
181
-
* TITLE_RIGHT_VALUE_LEFT
182
-
* TITLE_RIGHT_VALUE_RIGHT
186
+
*`TITLE_LEFT_VALUE_LEFT`
187
+
*`TITLE_LEFT_VALUE_RIGHT`
188
+
*`NO_TITLE_VALUE_LEFT`
189
+
*`NO_TITLE_VALUE_RIGHT`
190
+
*`TITLE_RIGHT_VALUE_LEFT`
191
+
*`TITLE_RIGHT_VALUE_RIGHT`
183
192
184
193
Along with the ability to use a delegate this gives a lot of flexibility in screen drawing outside the regular menu rendering.
185
194
186
195
## Setting the speed of rendering
187
196
188
197
You can adjust the number of update cycles per second by calling `setUpdatesPerSecond` on the renderer, it takes place immediately, even if already started.
198
+
199
+
## Using a delegate to customize the dashboard - ADVANCED
200
+
201
+
Optionally, you can set a delegate if you want to draw extra things to the display, or need more control around how it opens and closes.
202
+
203
+
* Step 1 - create a class that extends from `DrawableDashboardDelegate`
204
+
* Step 2 - now override the functions you need to handle, see the documentation for the class for the options.
205
+
* Step 3 - add the delegate to the dash, `mainDashboard->setDelegate(&myDelegate);`
Copy file name to clipboardExpand all lines: content/arduino-libraries/tc-menu/using-custom-fonts-in-menu.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ toc_needed = true
15
15
16
16
In the theme plugin properties you can often select the font to use. However, there are a few points to bear in mind when using fonts. Here are the key points:
17
17
18
-
*From version 3.0 Most graphical plugins (other than Uno specific) support TcUnicode, a font rendering system that has full Unicode UTF-8 support. These fonts can be easily created in the designer UI, see further down. It is also backward compatible with Adafruit fonts.
18
+
* Most graphical plugins (other than Uno specific) support TcUnicode, a font rendering system that has full Unicode UTF-8 support. These fonts can be easily created in the designer UI, see further down. It is also backward compatible with Adafruit fonts.
19
19
* Each plugin's text drawing can also use native text drawing, based on how the underlying library itself draws fonts. You must use a compatible font.
20
20
* Some libraries such as U8G2 and TFT_eSPI generally include the fonts in the package, and it is up to you to know which ones are available.
21
21
* For Adafruit_GFX the fonts are generally included as needed from the `Fonts` directory, either in the package itself, or from your local project. They will be included once only in the C++ menu file and the variable for the font will be exported.
@@ -62,23 +62,22 @@ It is a struct, so has trivially simple copy characteristics.
62
62
63
63
## Creating a Unicode or Adafruit font using the designer UI
64
64
65
-
From V3.0 of designer onwards you can create an embedded font from a font available on your desktop. The font creator presently supports header generation for both Adafruit_GFX or TcUnicode fonts. TcUnicode fonts are described in more detail in the next section.
65
+
TcMenu Designer can create an embedded font from a font available on your desktop. The font creator presently supports header generation for both Adafruit_GFX or TcUnicode fonts. TcUnicode fonts are described in more detail in the next section.
66
66
67
67
**NOTE: It is your responsibility to check the usage license on the font you choose, to ensure you are legally allowed to use it in an embedded context.**
68
68
69
69
To start the font creation utility, it is best to have a project open first, as it will then offer to save within your project.
70
70
71
-
From the "Code" menu select "Font Creation Utility" (requires 3.0) and the following dialog will be shown:
71
+
From the "Code" menu select "Font Creation Utility" and the following dialog will be shown:
Notice that the above diagram is annotated with numbers, this is roughly the order that you'd use the panel. Each point is described below:
75
+
We'll now go through the general way in which to work with fonts:
76
76
77
-
1. Font load button. Click this button to load a font into the creator tool. Once loaded by default it will show the glyphs for Latin in the selection area (4). Clicking on the "Choose Ranges" in the button bar (5) allows you to change the Unicode ranges that are selected.
78
-
2. Size in pixels of the font to generate, adjust this as needed, as you adjust the font will update in the selection area.
79
-
3. Font style allows you to change the style, toggling italics and bold typeface, again the selection area automatically updates.
80
-
4. The selection area is where you can turn on and off both character groups and characters. Toggle the group by clicking the checkbox next to it. To add/remove whole groups use the "Choose Ranges" button.
81
-
5. The button bar has the two options for code generation, each of these will take a file name and write the font in the format selected. Each of these formats, and their limitations are described below.
77
+
1. Open a font into the editor either using `Open Embedded Font` which allows you to open an existing font XML file previously saved. Alternatively, `Import Font` imports a font from any file format supported by FreeFont library. When importing a font, make sure you choose the Unicode ranges that you want to include, by default all Latin ranges are selected.
78
+
2. One a font is opened you can choose which glyphs to include, and also touch up any minor rendering errors. To either select or deselect a glyph click on it, a popup will allow you to either edit the glyph or toggle its selection status. To toggle the group by clicking the `select/clear all` checkbox next to it.
79
+
3. You can `Save` the font as XML, it can be loaded back at any time using `Open Embedded Font`.
80
+
4. To export the font simply use the `Generate` menu button, where you can choose either to export to clipboard or file. When the clipboard option is ticked, the header file will be saved to the clipboard. The two export options are discussed below.
0 commit comments