Style contract#
Source: lib/ui/style.rs
style -- the contract between the core and a style (ASMLIB/inc/style.inc)
The core holds every widget's logic (measuring, placing, input, state, semantics); how
things look comes from exactly one style crate, chosen when the app is linked
(build_rs.py --style S, the app passes `&style::STYLE` to run). Size functions return
the widget's size and may keep what they computed in Sp::s for the paint call; paint
functions see the placed rectangle and the state and emit draw commands -- no layout,
no input, no semantic records.
The contract is split like the files of a style (ASMLIB/styles/<name>/*.s): Style (theme,
type ramp, fonts) and one sub-trait per widget family -- StyleBasic (basic.s), StyleValue
(value.s), StyleEdit (edit.s), StyleList (list.s), StylePopup (popup.s), StyleChrome
(chrome.s), StyleMisc (misc.s). R5: the default bodies (empty / zero) exist only while
the widget families are being ported; a finished style overrides every function.
struct Sp<'a>the SP record: inputs of a widget's size / paint call (SP_* of style.inc)x: i32-- placed rectangle (px; filled before the paint call)y: i32w: i32h: i32state: u32-- 0 rest, 1 hover, 2 pressed, 3 disabledev: u32-- EV_* of behave()flags: u32-- ST_* / BOX_* / MIF_* / RG_* flags of the widgeticon: u32-- icon code point (0 = none)label: Option<&'a str>value: i32value2: i32s: [i32; 4]-- kept by the style from its size call to its paint call (SP_S0 .. SP_S3)label2: Option<&'a str>-- the 8-byte SP_VALUE variants: a second text (menu accelerator, info bar message)f: f64-- ... an f64 (angle degrees)img: Option<&'a Rc<gfx::Surface>>-- SP_LABEL variants: a thumbnail (pan), a TRACK record (value sliders: flags, n, stops)img_ver: u32track: Option<&'a Track>
impl Sp<'_>
fn rect(&self) -> [i32; 4]fn place(&mut self, r: [i32; 4])trait Style: StyleBasic + StyleValue + StyleEdit + StyleList + StylePopup + StyleChrome + StyleMisc + Synca style: tokens, type ramp, fonts and every widget family's paint functionsfn name(&self) -> &'static strthe style's short name, as build_rs.py --style knows it ("winui", "kde"): the name Ui::set_style switches to (several styles linked into one app)fn ribbon_height(&self) -> i32Ribbon height in DIP. Existing styles retain the original 110-DIP layout.fn ribbon_padding(&self) -> u32Outer ribbon padding in DIP, independently styled from control content heights.fn ribbon_preview(&self, _typography: u32) -> Option<(u32, i32, u32)>Optional document-style gallery face, size in 24.8 DIP and ink color. None preserves the ordinary UI type ramp in existing style previews.fn ribbon_metrics(&self) -> crate::RibbonMetricsGroup sizing and overflow policy. Existing styles preserve compact flyouts.fn ribbon_box_flags(&self) -> u32BOX_* decoration of the ribbon's scroll box (BOX_LAYER: a framed panel). A style that paints the band itself returns 0 and draws it inribbon_band.fn ribbon_band(&self, _ui: &mut Ui, _sp: &Sp)Paint the ribbon band whenribbon_box_flagsis 0 (sp: the band, px). It is drawn right after the band is placed, below the groups.fn ribbon_tabs_height(&self) -> i32Height of the register row ofUi::ribbon_tabsin DIP.fn ribbon_tabs_strip(&self, ui: &mut Ui, sp: &Sp)Paint the register row behind its registers (sp: the row; s[0], s[1]: x and width of the selected register in px, width 0 when none is shown). The default draws a divider along the bottom that leaves the selected register open toward the ribbon.fn ribbon_tab(&self, ui: &mut Ui, sp: &Sp)Paint one register (sp: rect, label, ev, state 3 = disabled; value 1 = selected; flags RT_FILE / RT_CONTEXT; value2 the ARGB colour of its context set or 0).fn keytip(&self, ui: &mut Ui, sp: &Sp)Paint a key tip badge of the ribbon's access keys (sp: the badge, label = its keys).fn preview_card_offset(&self) -> Option<[i32; 2]>Optional optical offset of a preview card in 24.8 DIP. Opts into the fractional panel painter; None keeps the original integer painter.fn tokens(&self, dark: bool) -> [u32; T_COUNT]the T_* tokens (light or dark; accent entries may be 0: accent() fills them)fn accent(&self, theme: &mut [u32; T_COUNT], dark: bool, rgb: u32)fill T_ACCENT, _HOVER, _PRESSED and T_ACCENT_TEXT from 0xRRGGBB (0 = the default)fn ts_size(&self) -> [u8; 8]font px / line px / FONT_* of TS_CAPTION .. TS_DISPLAY (+ one spare) at 100 %fn ts_size_fx(&self) -> [u16; 8]Font sizes in 24.8 DIP. The default keeps every existing integer type ramp exact.fn ts_line(&self) -> [u8; 8]fn ts_font(&self) -> [u8; 8]fn fonts(&self) -> [&'static [u8]; 4]Embedded SGF1 or TrueType/OpenType assets of FONT_REG, FONT_SEMI, FONT_BOLD, FONT_ICON.fn font_raster(&self) -> [text::FontRaster; 4]Raster policy for the four embedded UI faces. Runtime/document fonts keep their own defaults. Existing styles preserve their pixel output.fn font_names(&self) -> [[&'static str; 5]; 4]per embedded font: family, style, full, typographic family, typographic style (sty_font_names)fn paint_icon(&self, _g: &mut crate::Gfx, _cp: u32, _x: i32, _y: i32, _size_fx: i32, _color: u32, _accent: u32, _dark: bool, _disabled: bool, _dpi: u32) -> boolPaint a semantic icon with the shared rasterizer; false uses the icon font. Coordinates are target pixels, size is 24.8 pixels; dpi permits fixed DIP details. Application icon hooks run first. Existing styles retain their original monochrome font rendering.fn data(&self) -> &'static dyn StyleDataThe painters of the data views (grids, trees, badges, meters, charts). The default paints them from the theme tokens (stock.rs), so every style shows them; a style returns its own StyleData to give them its look.fn shell(&self) -> &'static dyn StyleShellThe painters of the app shell parts (navigation pane, command bar, splitter, breadcrumb, segmented control, wizard steps, toasts, spinner, calendar). Default: token-based (stock.rs).
trait StyleDatadata views: grid header / rows, tree rows, badges, status dots, meters, charts (data.rs, chart.rs). Every method has a token-based default (stock.rs); a style overrides what it wants to look different.fn grid_metrics(&self, _ui: &Ui) -> (i32, i32, i32)(header strip height, row height, cell padding) in DIPfn grid_header_bg(&self, ui: &mut Ui, sp: &Sp)the header strip behind the header cells (rect = the strip)fn grid_header(&self, ui: &mut Ui, sp: &Sp)header cell: label, ev, flags GH_*; s[0] = the label inset (px)fn grid_row(&self, ui: &mut Ui, sp: &Sp)row background: ev, value 1 = selected, value2 = row index, flags GR_*fn tree_twisty(&self, ui: &mut Ui, sp: &Sp)tree expander glyph: value 1 = expanded, evfn badge_size(&self, ui: &mut Ui, sp: &mut Sp) -> (i32, i32)badge: flags BADGE_*, label; size -> (w, h)fn badge(&self, ui: &mut Ui, sp: &Sp)fn status_dot(&self, ui: &mut Ui, sp: &Sp)status dot: flags BADGE_*fn meter(&self, ui: &mut Ui, sp: &Sp)meter (capacity bar): value, value2 maximum, flags BADGE_* of the fillfn chart_palette(&self, ui: &Ui) -> [u32; 8]the categorical colours of charts (series 0 .. 7, 0xAARRGGBB)
trait StyleShellapp shell parts: navigation pane and items, command bar, splitter grip, breadcrumb, segmented control, wizard steps, toasts, spinner, indeterminate progress, calendar cells (shell.rs, notify.rs, datepick.rs). Token-based defaults in stock.rs.fn nav_pane(&self, ui: &mut Ui, sp: &Sp)the navigation pane's surface (rect = the pane), flags 1 = compactfn nav_item_size(&self, ui: &mut Ui, sp: &mut Sp) -> (i32, i32)navigation item: ev, value 1 = selected, icon, label, label2 = badge text, flags NAV_*; size -> (w, h)fn nav_item(&self, ui: &mut Ui, sp: &Sp)fn nav_section_size(&self, ui: &mut Ui, sp: &mut Sp) -> (i32, i32)section header of the navigation pane: label, flags NAV_COMPACT (then a divider)fn nav_section(&self, ui: &mut Ui, sp: &Sp)fn command_bar(&self, ui: &mut Ui, sp: &Sp)the bar behind a command bar (rect = the bar)fn split_grip(&self, ui: &mut Ui, sp: &Sp)splitter grip: ev, flags 1 = vertical split (a horizontal grip)fn breadcrumb_sep(&self, ui: &mut Ui, sp: &Sp)breadcrumb separator (rect = its place)fn segment(&self, ui: &mut Ui, sp: &Sp)segmented control item: ev, value 1 = selected, label, flags SEG_FIRST / SEG_LASTfn wizard_step(&self, ui: &mut Ui, sp: &Sp)wizard step row: value step number (from 1), value2 WS_* state, label, evfn toast(&self, ui: &mut Ui, sp: &mut Sp)toast card: flags IB_* severity, label title, label2 message; s[0] = close button x, s[1] its size (set by the painter, hence &mut)fn spinner(&self, ui: &mut Ui, sp: &Sp)spinner: value phase 0 .. 1023 (one turn), rect = its squarefn progress_indeterminate(&self, ui: &mut Ui, sp: &Sp)indeterminate progress bar: value phase 0 .. 1023fn calendar_day(&self, ui: &mut Ui, sp: &Sp)day cell of a calendar: label, value 1 = selected, value2 1 = today, flags 1 = other month, evfn dock_group(&self, ui: &mut Ui, sp: &Sp)a dock group's surface (rect = tab strip and content; dock.rs), value 1 = the keyboard focus is in the groupfn dock_header(&self, ui: &mut Ui, sp: &Sp)the tab strip of a dock group (rect = the strip, SM_DOCK_HDR high), value as dock_groupfn dock_tab_size(&self, ui: &mut Ui, sp: &mut Sp) -> (i32, i32)a tab of a dock group: label, icon, ev, value 1 = the shown panel, value2 1 = the focus is in the group, flags DOCK_TAB_HOLD = held long enough to be dragged (show it through the tokens); size -> (w, h), the core takes w (a tab is as high as the strip)fn dock_tab(&self, ui: &mut Ui, sp: &Sp)fn dock_rail(&self, ui: &mut Ui, sp: &Sp)the rail of a collapsed dock side (rect), flags DOCK_LEFT / DOCK_RIGHT / DOCK_BOTTOMfn dock_marker(&self, ui: &mut Ui, sp: &Sp)a drop marker while a panel is dragged: value DOCK_MK_* (the part of the place it fills), ev EV_HOVER while the pointer is over itfn dock_preview(&self, ui: &mut Ui, sp: &Sp)where the dragged panel would go (rect), value 1 = a floating window therefn desk_bg(&self, ui: &mut Ui, sp: &Sp)(L7) the background of a window area (desk.rs; rect = the area)fn desk_window(&self, ui: &mut Ui, sp: &Sp)a window inside an area: shadow, surface and frame (rect = the window), value 1 = the active window, flags 1 = maximised (it fills the area: no shadow, square)fn desk_titlebar(&self, ui: &mut Ui, sp: &Sp)its title bar (rect = the bar over the whole width, the buttons are drawn after it): value 1 = active, icon, label = the title; s[0], s[1] = x and width of the icon and title (px)fn desk_button(&self, ui: &mut Ui, sp: &Sp)a button of its title bar: ev, flags HB_MIN / HB_MAX / HB_CLOSE, icon IC_CHROME_*, value 1 = the window is active; default: the style's caption_buttonfn desk_snap(&self, ui: &mut Ui, sp: &Sp)where a dragged window snaps when it is released now (rect), value 1 = maximisedfn taskbar(&self, ui: &mut Ui, sp: &Sp)the bar behind a taskbar (rect)fn taskbar_button_size(&self, ui: &mut Ui, sp: &mut Sp) -> (i32, i32)a window's button in a taskbar: label, icon, ev, value 1 = the active window, value2 1 = minimised, flags DTB_ICONS (icons only); size -> (w, h), the core takes w (a button is as high as the bar)fn taskbar_button(&self, ui: &mut Ui, sp: &Sp)
trait StyleBasicbuttons, check boxes, radios, switches, sliders, progress, separators (basic.s)fn focus_ring(&self, _ui: &mut Ui, _r: [i32; 4], _radius_dip: i32)focus visual around rectangle r (px) of a control with that corner radius (DIP)fn drop_highlight(&self, ui: &mut Ui, r: [i32; 4])a drop target with a matching drag over it (rectangle r, px; drop_target): by default a 2 DIP accent frame over a light accent tintfn button_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)buttons (ST_ACCENT, ST_SUBTLE, ST_CHECKED, ST_LARGE, ST_COMPACT, ST_ICON_ONLY)fn button(&self, _ui: &mut Ui, _sp: &Sp)fn checkbox_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)value 0 / 1 / 2 (indeterminate)fn checkbox(&self, _ui: &mut Ui, _sp: &Sp)fn radio_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)value 1 = selectedfn radio(&self, _ui: &mut Ui, _sp: &Sp)fn switch_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)value 0 / 1, value2 knob position 0 .. 256 (animated)fn switch(&self, _ui: &mut Ui, _sp: &Sp)fn slider_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)size: value 1 = vertical; must set s[0] = thumb px along the axis; paint: value thumb offset, value2 track length (px)fn slider(&self, _ui: &mut Ui, _sp: &Sp)fn progress_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)value, value2 maximumfn progress(&self, _ui: &mut Ui, _sp: &Sp)fn separator_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> i32thickness incl. margins; paint: value 1 = horizontal line (in a vertical box)fn separator(&self, _ui: &mut Ui, _sp: &Sp)
trait StyleValuevalue sliders (gradient tracks), angle, pan (value.s)fn value_slider_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)flags RG_*, value t 0..65536 along the travel, track (gradient) or None; state held = 2fn value_slider(&self, _ui: &mut Ui, _sp: &Sp)fn value_slider_thumb(&self, _ui: &mut Ui) -> i32thumb length px (travel = length - thumb)fn angle_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)f degrees, s[0] 1 = focus visualfn angle(&self, _ui: &mut Ui, _sp: &Sp)fn pan_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)img thumbnail or None; paint: value, value2 = the point (px)fn pan(&self, _ui: &mut Ui, _sp: &Sp)
trait StyleEdittext boxes (edit.s)fn textbox_font(&self, ui: &mut Ui, _sp: &Sp) -> (i32, i32)Select the single-line input face and return its line height and baseline in px. Default preserves the body font; icon inputs may use a compact search-field face.fn textbox_metrics(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)value natural width (DIP), flags 1 = multi-line (value2 line height px); must set s[0], s[1], s[2] = left, right, top text inset (px)fn textbox_frame(&self, _ui: &mut Ui, _sp: &Sp)ev (hover), value 1 = editing, value2 1 = disabled; the core draws text, selection, caretfn textbox_vbar(&self, _ui: &mut Ui, _sp: &Sp)value view h, value2 content h, s[0] scroll y, s[1] text top (px)
trait StyleListfocus rectangles, scroll bars, list rows, tabs, expanders (list.s)fn focus_rect(&self, _ui: &mut Ui, _x: i32, _y: i32, _w: i32, _h: i32)focus visual drawn ON a rectangle (rows, tabs, headers)fn scrollbar_thickness(&self, _ui: &mut Ui) -> i32hover area, track margin at both ends, shortest thumb (px)fn scrollbar_margin(&self, _ui: &mut Ui) -> i32fn scrollbar_min_thumb(&self, _ui: &mut Ui) -> i32fn scrollbar_room(&self, _ui: &mut Ui) -> i32room a view that scrolls only vertically keeps free right of its content for the bar, overflowing or not, so the content ends before a bar that stays visible (px; 0 = the bar floats over the content)fn scrollbar(&self, _ui: &mut Ui, _sp: &Sp)flags 1 = vertical, value expansion 0..256, s[0] track start, s[1] thumb length, value2 thumb offset (px)fn list_drop_line(&self, _ui: &mut Ui, _sp: &Sp)reorder marker centred on y across x .. + wfn list_row(&self, _ui: &mut Ui, _sp: &Sp)ev, value 1 = selected, value2 1 = disabled, flags 1 = dragged row, 2 = focus visualfn tab_metrics(&self, _ui: &mut Ui, _sp: &mut Sp)sets s[0] label padding, s[1] height, s[2] pill widthfn tab_font(&self, ui: &mut Ui, _selected: bool)Select the font used to measure or paint a tab; default preserves the body face.fn tab(&self, _ui: &mut Ui, _sp: &Sp)tab: ev, value selected, value2 disabled, label; pill: strip rect, value pill xfn tab_pill(&self, _ui: &mut Ui, _sp: &Sp)fn expander_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)header: ev, value open, value2 disabled, label; body: the content card's rectanglefn expander_header(&self, _ui: &mut Ui, _sp: &Sp)fn expander_body(&self, _ui: &mut Ui, _sp: &Sp)
trait StylePopupflyouts, menus, menu bars, drop-downs, split buttons, combo boxes, tooltips (popup.s)fn flyout_pad(&self, _ui: &mut Ui) -> i32pxfn flyout_box(&self, _ui: &mut Ui) -> u32BOX_* | PAD_* flags of the contentfn flyout_frame(&self, _ui: &mut Ui, _sp: &Sp)shadow + surface of a flyout / menu (rect = the flyout)fn menu_item_h(&self, _ui: &mut Ui) -> i32row height pxfn menu_item_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)flags MIF_*, label, label2 accelerator text, icon, ev; size must set s[1] = accelerator widthfn menu_item(&self, _ui: &mut Ui, _sp: &Sp)fn menu_sep_size(&self, _ui: &mut Ui) -> i32fn menu_sep(&self, _ui: &mut Ui, _sp: &Sp)fn menubar_item_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)flags 1 open, 2 current item, value mnemonic byte index or -1, label, evfn menubar_item(&self, _ui: &mut Ui, _sp: &Sp)fn dropdown_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)flags ST_*, icon, label, value open, value2 disabledfn dropdown(&self, _ui: &mut Ui, _sp: &Sp)fn split_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)size sets s[0] / s[1] = main / chevron part width; paint: ev main, s[2] chevron events, value open, value2 1 main / 2 chevron disabledfn split(&self, _ui: &mut Ui, _sp: &Sp)fn combo_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)size: value widest text px; paint: label the selected text, ev, value2 disabledfn combo(&self, _ui: &mut Ui, _sp: &Sp)fn tooltip_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)size sets s[0] text width, s[1] / s[2] gap below / above the pointer; paint: labelfn tooltip(&self, _ui: &mut Ui, _sp: &Sp)
trait StyleChromelayout metrics, dialogs, info bars, status / title bars, caption buttons, window frames (chrome.s)fn navigation_surface(&self, ui: &Ui) -> u32Background for navigation placed on a branded accent surface.fn metric(&self, _id: u32) -> i32layout value SM_* (sizes, gaps, box flags, text styles)fn dialog_smoke(&self, _ui: &mut Ui, _sp: &Sp)fn dialog_frame(&self, _ui: &mut Ui, _sp: &Sp)dialog surface (value footer h)fn infobar_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)size: flags severity, label title, label2 message, sets s[0] / s[1] title / message width; paint sets s[2] / s[3] = close button x / size (hence &mut); close: evfn infobar(&self, _ui: &mut Ui, _sp: &mut Sp)fn infobar_close(&self, _ui: &mut Ui, _sp: &Sp)fn statusbar(&self, _ui: &mut Ui, _sp: &Sp)fn caption_button(&self, _ui: &mut Ui, _sp: &Sp)ev, flags HB_* (HB_CLOSE), icon, value 1 = window activefn window_titlebar(&self, _ui: &mut Ui, _sp: &Sp)background of a library title bar: rect = the bar, value 1 = activefn window_border(&self, _ui: &mut Ui, _sp: &Sp)value thickness pxfn window_dialog_fill(&self, _ui: &mut Ui, _sp: &Sp)
trait StyleMiscswatches, colour picker parts, box decorations, window background (misc.s)fn swatch_size(&self, _ui: &mut Ui, _sp: &mut Sp) -> (i32, i32)value colour, value2 1 = selected, evfn swatch(&self, _ui: &mut Ui, _sp: &Sp)fn color_preview(&self, _ui: &mut Ui, _argb: u32, _r: [i32; 4])fn color_marker(&self, _ui: &mut Ui, _x_fx: i32, _y_fx: i32)marker at 24.8 pxfn color_wheel(&self, _ui: &mut Ui, _sp: &Sp)rect = the wheel's square, s[0] radius px, value hue (tenths of a degree), value2 saturation 0..1000, s[1] 1 = focus visualfn box_deco(&self, _ui: &mut Ui, _sp: &Sp)BOX_BG / BOX_CARD / BOX_LAYER decoration (sp: rectangle, flags)fn window_bg(&self, _ui: &mut Ui, _w: i32, _h: i32)the background of a window's whole surface (px)