-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial Scheduler Updating Widgets
If you change a widget state through code, that widget is not updated automatically. Usually you want to call the 'update' method from the widget state; for example if we're in a callback:
use ez_term::*;
fn my_callback(context: Context) {
let label_state = context.state_tree.get_mut("my_label").to_label_mut();
label_state.set_text("new_text".to_string());
// After changing the state we call the update method to call for a redraw
label_state.update(context.scheduler);
}
The update method is in fact a convenience that calls "scheduler.update_widget". This scheduler method takes a full path parameter (IDs cannot be used here). It is therefore almost always more convenient to call 'update' on the widget state.
It is also possible to call a global screen update. In this case, all widgets, starting from the root layout, will be redrawn. For performance reasons, only changed pixels will actually be redrawn, but global updates will still be more costly than updating individual states. The option is made available but should generally not be used; try updating individual states rather than using this. If for whatever reason you do actually need to refresh the entire screen, this is how to do it:
use ez_term::*;
fn my_callback(context: Context) {
let label_state = context.state_tree.get_mut("my_label").to_label_mut();
label_state.set_text("new_text".to_string());
scheduler.force_redraw();
}
If you bind a widget property to a (custom) property, and you change the value of the (custom) property, the widgets bound to it will update automatically. This is the only case in which you never have to call an update method. For example, if you bind the height of widget_2 to the height of widget_1, and the height of widget_1 changes, then widget_2 will be updated automatically.
The general tutorial continues with: Managing Selection.
Tutorial
Tutorial-Project-StructureMinimal example
EzLang
EzLang basics
EzLang Templates
Ezlang Layout modes
EzLang Box mode layouts
EzLang Stack mode layouts
EzLang Table mode layouts
EzLang Float mode layouts
EzLang Tab mode layouts
EzLang Screen mode layouts
EzLang Layout Scrolling
EzLang Layout Views
EzLang Widget overview
EzLang Label
EzLang Text Input
EzLang Button
EzLang Checkbox
EzLang Radio button
EzLang Dropdown
EzLang Slider
EzLang Canvas
EzLang Property Binding
EzLang Sizing
EzLang Size hints
EzLang Auto scaling
EzLang Maths Sizing
EzLang Manual Sizing
EzLang Positioning
EzLang Layout Mode Positioning
EzLang Position Hints
EzLang Position Maths
EzLang Manual Position
EzLang Adjusting Position
EzLang Keyboard Selection
Scheduler
Widget States and the State Tree
The Scheduler Object
Managing callbacks
Callback Structure
Callback Configs
Callback: On keyboard enter
Callback: On Left Mouse Click
Callback: On Press
Callback: On Select
Callback: On Deselect
Callback: On Right Mouse Click
Callback: On Hover
Callback: On Drag
Callback: On Scroll Up
Callback: On Scroll Down
Callback: On Value Change
Callback: Custom Key Binds
Callback: Global Key Binds
Callback: Property Binds
Tasks
Scheduled Single Exectution Tasks
Scheduled Recurring Tasks
Threaded Tasks
Custom Properties
Modals
Programmatic Widgets
Updating widgets
Managing selection
Default global (key)binds
Performance
Examples
Layout: Box Mode NestedLayout: Box Mode Size Hints
Layout: Stack Mode
Layout: Table Mode Dynamic
Layout: Table Mode Static
Layout: Float Mode Manual
Layout: Float Mode Position hints
Layout: Screen Mode
Layout: Tab Mode
Layout: Scrolling
Layout: Views
Widget: Label
Widget: Text input
Widget: Button
Widget: Checkbox
Widget: Radio Button
Widget: Dropdown
Widget: Slider
Widget: Progress Bar
Widget: Canvas
Scheduler: Schedule Once
Scheduler: Schedule Once Callback
Scheduler: Schedule Recurring
Scheduler: Schedule Recurring Callback
Scheduler: Threaded Task State Tree
Scheduler: Threaded Task Custom Property
Scheduler: Create Widgets
Scheduler: Modal Popup
Reference
WidgetsCommon Properties
Label
Text Input
Button
Checkbox
Radio button
Dropdown
Slider
Canvas
Scheduler
Schedule once
Schedule Recurring
Schedule Threaded
Cancel Task
Cancel Recurring Task
Create Widget
Remove Widget
Select Widget
Deselect Widget
Update Widget
Force Redraw
Open Modal
Dismiss Modal
Bind Global Key
Remove Global Key
Clear Global Keys
Bind Property
Create Custom Properties
Get Property
Get Property Mut
Overwrite Callback Config
Update Callback Config
Exit