Controls¶
Tesserae draws MD3's stateful controls itself: the checkbox, radio button, switch, slider, range slider, spin box, linear and circular progress, loading indicator and time picker dial. They work with a mouse, a keyboard and a screen reader, and follow the theme, including light and dark (Themes). Each control also has a page under Components, and the Python signatures are in the Python API.
In a view¶
In a *_View.tdl, these widgets are controls: Checkbox, RadioButton, Switch, Slider, RangeSlider, SpinBox,
LinearProgress, CircularProgress, LoadingIndicator and TimePickerDial.
Container {
Style { Flex_Direction: vertical, Gap: 8, Width: 320, Padding: 16 }
Children {
Checkbox {
Name: agree
Label: "I agree"
Checked: <| agreed |> # one bare reference: the user's change is written back to `agreed`
Handlers {
On_Change: agreement_changed
}
}
Switch {
Name: dark
Selected: <| dark |>
}
Slider {
Name: volume
Value: <| volume |>
Min: 0
Max: 1
Step: 0.1
Style { Width: 200 }
}
SpinBox {
Name: quantity
Value: <| quantity |>
Min: 1
Max: 9
}
LinearProgress {
Name: loaded
Value: <| loaded |>
Style { Width: 200 }
}
}
}
- State:
checked(Checkbox),selected(RadioButton, Switch),value(Slider, SpinBox, the progress widgets),lowandhigh(RangeSlider),hour,minuteandmode(TimePickerDial), anddisabled(on every control that has one: not the progress widgets or the dial). Given one bare reference to a Signal or aStatename, the property is two-way: the user's changes are written back. Any other expression is one-way. on_changeruns for changes the user makes, never for ones your code or a binding makes.labelon a Checkbox, RadioButton or Switch is text beside it that is part of what you press, and what a screen reader calls it. On the others it is what a screen reader calls the control (A11y { Label: ... }says the same on any node).- A
CheckboxwithChecked: nullis neither on nor off (a parent of some checked children).Error: truedraws a Checkbox or RadioButton in the error colours. ASwitchwithIcons: trueshows a check on its handle when on and a cross when off. - A
Slidertakesmin,max(0 and 1 when left out),step,Ticks: true(a mark at each step, which needsstep),Value_Indicator: true(a bubble with the value while dragged),Vertical: true(the bottom ismin;heightis its length andwidththe touch target's),size(xs,s,m,l,xl: MD3 Expressive's thicker track and thin handle) and, from sizesup, aniconat the start of the track. ARangeSlideris a slider with two handles,lowandhigh, and the same keys. - A
SpinBoxtakesvalue,min,maxandstep, anddecimals(how many places show),prefix,suffixandwrap(a step past one bound lands on the other, which needs both). A boundvalueis shown kept between the bounds. ItsA11ylabel goes to its text field. It is sized by MD3, two 40 px buttons around a 64 px field (152 px wide), not bywidth; like any box it is stretched across the layout, so give its parentAlign_Content: left(or itselfalign_self) to keep that size. Holding a button repeats the step; Page Up and Page Down step by ten. - The progress widgets take
valuefrom 0 to 1, or nothing (Value: null) for a wait with no end.trackis the colour role behind the indicator,thicknessthe bar's height or the ring's width in pixels. ALinearProgressalso hasbuffer(how much has loaded, 0 to 1),stop_indicator,wavyandtwo_bar(an endless wait sweeps as two bars); aCircularProgresshaswavy; aLoadingIndicatorhascontained. - A
TimePickerDialhashour(0 to 23),minute(0 to 59),mode(hourorminute, which hand the face shows and sets) andauto_advance(true: letting go in hour mode moves on to the minutes). - The colour picker's parts (
ColourArea,ColourStrip,ColourField,ColourSwatches) are controls too, made for the colour picker and usable alone. Theirvalueis a colour as text,'#rrggbb'or'#rrggbbaa'when its alpha is below 1, and is two-way;on_inputruns on every change the user makes while a drag is going. They are sized byStyle { width, height }(a square of 256 by 176, a strip of 256 by 24, a field of 256 or 58 wide). - The icon picker's mind (
IconBrowser) is a control that draws nothing, made for the icon picker: it keeps the list, the search and the cursor, and the view reaches it through names it binds (valueandscrollare two-way;grid,cursor,count,currentandmessageare its outputs;commandasks it to do something). You callIconPicker, not this. - The font list's mind (
FontBrowser) is a control that draws nothing, made for the font list: it asks for the installed families and keeps the search and the cursor; the view reaches it through names it binds (valueandscrollare two-way;entries,cursor_name,count,modeandmessageare its outputs;commandasks it to do something). You callFontList, not this. - The key-chord field's mind (
ChordRecorder) is a control that draws nothing, made for the key chord field: it records the key presses its view sends it and reads typed chords; the view reaches it through names it binds (value,draftandrecordingare two-way;preview,invalidandmessageare its outputs;commandsends it a key or a typed text). You callKeyChordField, not this. - The list editor's mind (
ListModel) is a control that draws nothing, made for the list editor: it holds the items of one kind and does the edits the rows send it; the view reaches it through names it binds (valueis two-way;rows,options,count,can_add,can_removeandmessageare its outputs;commandsends itset,add,remove,upordown). You callListEditor, not this. - The token button's mind (
TokenList) is a control that draws nothing, made for the token button: it takes the tokens as data, searches them and keeps the cursor; the view reaches it through names it binds (value,queryandscrollare two-way;entries,cursor_ref,countandcurrentare its outputs;commandsends it a key or a click). You callTokenButton, not this. - Size:
Style { width, height }sets the control's touch target; it's MD3's 48 px when not given. A slider'swidthis its track's length, a dial's is its face, and a progress bar's is its track. - Colour:
foregroundreplacesprimary, the colour of the selected or active parts. - Radio groups: radio buttons with the same
Group:name exclude each other, and the group is a single Tab stop whose arrow keys move the selection. - From Python,
view.control("root.agree")returns the control, andview.node("root.agree")its node (a node's id is the path from the root, using itsname).
From Python¶
from tess_ui import controls
cb = controls.Checkbox(app.window, checked=True, label="Remember me") # follows the app's theme
app.window.root.add_child(cb.node)
cb.checked.set(False) # its state is a Signal
stop = cb.on_change(print) # the user's changes
cb.disabled.set(True)
Every control has .node (a tess_re node to put in a tree), its state as
Signals, set_theme(theme) and destroy(); all but the progress widgets and the loading indicator also have .disabled and
on_change(fn) (which returns a function that stops it). On an App's window, a
control made without theme= takes the app's theme and follows it
through set_dark, the OS switching light and dark, and
set_theme_specs. Give theme= a tess_ui.Theme to pin it to
that theme instead. On a window no App owns, a control without one uses
MD3's baseline colours. tess_ui.widgets' checkbox, slider and
so on build these too, attached to the window's root.
| Control | State | Input |
|---|---|---|
Checkbox |
checked |
click, Space, Enter toggle it |
RadioButton |
selected |
a click selects it; with group=RadioGroup(), the arrow keys move the selection |
Switch |
selected |
click, Space, Enter toggle it; the handle grows while pressed |
Slider(value=, min=, max=, step=, width=) |
value |
press or drag (the pointer is captured); arrows, Page Up/Down, Home/End; on_change once a drag ends |
RangeSlider(low=, high=, min=, max=, step=, width=) |
low, high |
the same, for two handles; high is never below low |
SpinBox(value=, min=, max=, step=, decimals=, prefix=, suffix=, wrap=) |
value |
− and + buttons, the up and down arrows, typing |
TimePickerDial(hour=, minute=, mode=, auto_advance=) |
hour, minute, mode |
press or drag points the hand; the hour snaps to 12, the minute to 5; releasing on the hour moves on to minutes |
LinearProgress(value=, width=), CircularProgress(value=) |
value: 0–1, or None for indeterminate |
none |
LoadingIndicator() |
none | none: it morphs forever |
Screen readers hear each control's role, label and state, and can step a
slider, spin box or dial (a11y_action increment, decrement and
set_value).
A control inside something clickable, such as a checkbox in a clickable list row or card, takes its own click: the row's handler doesn't run. A disabled control takes the click too, so nothing happens. See nested clickables.
What they look like¶
MD3's specification: a checkbox is 18 px, a radio button 20 px, a switch a 52×32 track, a slider a 4 px track with a 20 px handle, each centred in its touch target with the state layer, ripple and keyboard focus ring from Interaction & Accessibility. Disabled controls use MD3's disabled colours: content at 38%, containers at 12%. The timing is MD3's motion tokens.