-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial EzLang Button
ddbnl edited this page Aug 29, 2022
·
2 revisions
Clickable button; displays a small animation when clicked. Bind an 'on_press' callback to a button to make it functional. Callbacks are explained in details the scheduler chapter, but an example will be shown here. Buttons always have borders, so the effective height and width (i.e. surface for button text) are always 2 pixels smaller.
Here are a few cropped examples with screenshots (see 'examples' for the full functional EzLang/code):
// This is a button with auto scale enabled. This way it will not take up any more space than needed.
// Keep in mind that since auto scale width is enabled, the button will always be height 1. Check the next button
// for multi line button text.
- Button:
text: Scaled button
auto_scale: true, true
fg_color: yellow
// This button has multi-line text.
- Button:
text: Multi Line
size_hint_x: none
width: 9
auto_scale_height: true
fg_color: yellow
// This is a layout with a normal button and a disabled button. We'll give the enabled button a color so it's easier
// for the user to see what is enabled and what is disabled.
- Layout:
auto_scale: true, true
- Button:
text: Enabled button
auto_scale: true, true
fg_color: yellow
- Button:
text: Disabled button
auto_scale: true, true
fg_color: yellow
disabled: true
// Buttons are of course only useful if bound to a callback. We'll bind this button to a callback that changes the
// text of the label next to it (see button_example.rs).
- Layout:
auto_scale: true, true
- Button:
id: change_label_button
text: Change label
auto_scale: true, true
fg_color: yellow
selection_order: 1
- Label:
id: my_label
text: Original text
auto_scale: true, true
valign: middle
let change_label_callback = |context: Context| {
let state = context.state_tree.get_mut("my_label").as_label_mut();
state.set_text("Button was clicked!".to_string());
state.update(context.scheduler);
false
};
The general tutorial continues with: EzLang Checkbox.
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