-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial EzLang Position Maths
When setting the 'x' or 'y' properties, it is possible to refer to other widgets' properties and even perform maths on them. Any mathematical expression using the following symbols is allowed: '+', '-', '*', '/', '(', ')'. In between these operators, you can use actual numbers (1, 3.14, etc.) and references to other properties. When a referenced property changes, it will trigger an update automatically.
First, we'll look at an example of simply binding the 'y' property of one widget to another, without using math. If you need to refresh your memory on how to reference properties, we discussed it here:
- <MyLabel@Label>:
text: My text
auto_scale: true, true
border: true
- Layout:
mode: float
border: true
- MyLabel:
id: label_1
pos: 5, 5
auto_scale: true, true
- MyLabel:
pos: 15, parent.label_1.y
auto_scale: true, true
Now let's use maths to make the label y position a fixed amount below the other label y:
- <MyLabel@Label>:
text: My text
auto_scale: true, true
border: true
- Layout:
mode: float
border: true
- MyLabel:
id: label_1
pos: 3, 3
auto_scale: true
- MyLabel:
x: parent.label_1.x
y: parent.label_1.y + 5
auto_scale: true
You can use as many numbers or references to other properties as you want in these formulas. The only restriction is that the other properties should also be usize. To show this, let's look at a more complex example. We want a slider widget, and a label widget that hovers above the slider widget handle. To accomplish this, we need to bind the 'x' property of the label to be equal to ratio of the slider value. In other words, if the slider is 75% towards its maximum value, we need the label 'x' property to be 75% of the slider width. Let's look at how to do this:
- Layout:
mode: float
- Label:
id: my_label
text: parent.label_slider.value
x: ( parent.label_slider.width - 1 ) * (parent.label_slider.value / (parent.label_slider.max - parent.label_slider.min))
y: 0
auto_scale: true, true
- Slider:
id: label_slider
pos: 0, 1
min: 0
max: 100
step: 5
value: 50
auto_scale: true, true
The general tutorial continues with: EzLang Manual Position.
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