-
Notifications
You must be signed in to change notification settings - Fork 0
Examples Scheduler Create Widget
ddbnl edited this page Sep 3, 2022
·
1 revision
In this examples we'll use mock SQL records to programmatically create widgets. We will create a layout template that can display an SQL record. Then we'll iterate over SQL records from code and create widgets for them. We'll also create a Layout that can display multiple sql record widgets.
- Layout:
mode: box
orientation: vertical
border: true
- Label:
text: Retrieved SQL records:
auto_scale: true, true
halign: center
padding_bottom: 1
// This is the layout we will spawn widgets inside of
- Layout:
id: sql_records_layout
mode: box
orientation: vertical
scroll_y: true
// This is the template we will spawn from code
- <SqlRecord@Layout>:
mode: box
orientation: horizontal
auto_scale_height: true
- Label:
id: record_id
auto_scale_height: true
size_hint_x: 1
- Label:
id: record_name
auto_scale_height: true
size_hint_x: 1
- Label:
id: record_date
auto_scale_height: true
size_hint_x: 1
We now have a main UI that can hold our records. We also have a Layout template that can be spawned to display a record. Let's now go to the code:
fn main() {
use ez_term::*;
use std::collections::HashMap;
let (root_widget, mut state_tree, mut scheduler) = load_ui();
// Let's create some mock SQL records to spawn widgets from
let mut sql_records = Vec::new();
for x in 1..=100 {
let mut sql_record = HashMap::new();
sql_record.insert("id", format!("{}", x));
sql_record.insert("name", format!("Record {}", x));
sql_record.insert("date", format!("{}-{}-2022", (x / 31) + 1, x % 31 + 1));
sql_records.push(sql_record);
}
// Now we'll iterate over the records and spawn a template for each one
let template_name = "SqlRecord";
let parent_id = "sql_records_layout";
for (i, sql_record) in sql_records.iter().enumerate() {
let new_id = format!("record_{}", i);
let (new_widget, mut new_states) =
scheduler.prepare_create_widget(template_name, &new_id, parent_id, &mut state_tree);
// We will modify the widget state of each label to reflect the SQL record
new_states.get_mut("record_id").as_label_mut().set_text(sql_record.get("id").unwrap().to_string());
new_states.get_mut("record_name").as_label_mut().set_text(sql_record.get("name").unwrap().to_string());
new_states.get_mut("record_date").as_label_mut().set_text(sql_record.get("date").unwrap().to_string());
scheduler.create_widget(new_widget, new_states, &mut state_tree);
}
run(root_widget, state_tree, scheduler);
}
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