JFLib

Widgets#

Source: lib/ui/basic.rs

basic -- the basic widgets                                           [src/ui/ui_basic.s]

  text(style, s)                         TS_* | TX_* flags (TX_ELLIPSIS: cut with "…" at
                                         the placed width, record value 1 when cut;
                                         TX_WRAP: lines at the layout width, value = lines;
                                         TX_HYPHENATE: words that do not fit hyphenated,
                                         hyph.rs; soft hyphens always)
  button(id, label) -> EV                standard button
  accent_button(id, label) -> EV         accent (primary) button
  icon_button(id, icon, label) -> EV     subtle toolbar button (label = tooltip / name;
                                         ST_LARGE shows it under a big icon)
  toggle_button(id, label, &mut v) -> EV checked look while v != 0; toggles v
  tool_button(id, icon, label, &mut sel, mine) -> EV   selects sel = mine (tool palettes)
  checkbox(id, label, &mut v) -> EV      v: 0, 1, 2 = indeterminate
  radio(id, label, &mut v, mine) -> EV   v = mine when clicked
  checkbox_wrap / radio_wrap             the same with a label that wraps (next_size(-1, 0)): a mark
                                         beside a long text, a click on the text counts
  switch(id, label, &mut v) -> EV        toggle switch
  slider(id, &mut v, &range) -> EV       EV_ACT while the value changes, EV_COMMIT on release
  progress(id, v, max)                   progress bar
  separator()                            divider line across the current box
  icon(cp, size_dip)                     an icon in the text colour
  image(id, &sf, ver) -> EV              a surface at its natural size (or next_size)
  canvas(id, draw, user, version) -> &UiInput   custom area: draw.draw(g, rect) at render
                                         time, clipped; bump `version` when its content
                                         changes
  hair() -> px                           border width for the current dpi
Label strings are copied, so they may live in scratch buffers.

impl Ui

  • fn hair(&self) -> i32 ui_hair: max(1, (dpi + 24) / 96)
  • fn focus_ring_draw(&mut self, ev: u32) ui_focus_ring_draw(ev): the style's focus visual around last_rect when it is shown (ev: the widget's events; custom widgets built on hit_rect / behave call it last)
  • fn text(&mut self, style: u32, s: &str) ui_text(style, s): a text in a text style (TS_* | TX_*)
  • fn heading(&mut self, level: u32, style: u32, s: &str) A section title: text(style, s) that screen readers know as a heading of level (1 the top level ..= 9; record K_HEADING, value: the level) -- their heading navigation finds it.
  • fn button(&mut self, id: u32, label: &str) -> u32 ui_button(id, label) -> EV_* (EV_ACT on click)
  • fn label_button(&mut self, id: u32, label: &str, typography: u32, inset: i32) -> u32 A focusable text action with explicit TS_*/TX_* typography and horizontal inset in DIP. Uses the style's button surface and ordinary button semantics. Long labels are ellipsized visually; accessibility and agent inspection retain the full label.
  • fn accent_button(&mut self, id: u32, label: &str) -> u32 ui_accent_button(id, label) -> EV_*: the accent (primary) button
  • fn icon_button(&mut self, id: u32, icon: u32, label: &str) -> u32 ui_icon_button(id, icon, label) -> EV_*: subtle toolbar button
  • fn toggle_button(&mut self, id: u32, label: &str, v: &mut i32) -> u32 ui_toggle_button(id, label, &mut v) -> EV_*: checked look while v != 0; toggles v
  • fn tool_button(&mut self, id: u32, icon: u32, label: &str, sel: &mut i32, mine: i32) -> u32 ui_tool_button(id, icon, label, &mut sel, mine) -> EV_*: subtle icon button, checked when sel == mine; the tool buttons of one variable are one Tab stop (arrows inside)
  • fn checkbox(&mut self, id: u32, label: &str, v: &mut i32) -> u32 ui_checkbox(id, label, &mut v) -> EV_*: v 0, 1, 2 = indeterminate (Space toggles, Enter is the dialog's)
  • fn checkbox_wrap(&mut self, id: u32, label: &str, v: &mut i32) -> u32 ui_checkbox_wrap(id, label, &mut v) -> EV_*: a check box for a text that may be long: the mark, beside it the label wrapped at the width the layout gives (next_size(-1, 0)); a click on the text toggles too; the record is the check box's, named by the text
  • fn radio_wrap(&mut self, id: u32, label: &str, v: &mut i32, mine: i32) -> u32 ui_radio_wrap(id, label, &mut v, mine) -> EV_*: a radio for a text that may be long, as checkbox_wrap
  • fn radio(&mut self, id: u32, label: &str, v: &mut i32, mine: i32) -> u32 ui_radio(id, label, &mut v, mine) -> EV_*: v = mine when clicked; the radios of one variable are one Tab stop, the arrows select inside (kbnav.rs)
  • fn switch(&mut self, id: u32, label: &str, v: &mut i32) -> u32 ui_switch(id, label, &mut v) -> EV_*: toggle switch
  • fn slider(&mut self, id: u32, v: &mut i32, rg: &Range) -> u32 ui_slider(id, &mut v, &range) -> EV_*: EV_ACT while the value changes, EV_COMMIT on release
  • fn progress(&mut self, id: u32, v: i32, max: i32) ui_progress(id, v, max): progress bar
  • fn separator(&mut self) ui_separator: divider across the current box (the style draws it)
  • fn icon(&mut self, cp: u32, size: i32) ui_icon(cp, size_dip): an icon in the text colour
  • fn image(&mut self, id: u32, sf: &Rc<Surface>, ver: u32) -> u32 ui_image(id, sf, ver) -> EV_* (clickable when id != 0): a surface at its natural size (or next_size); ver stands for its SF_AUX version
  • fn canvas(&mut self, id: u32, draw: Option<DrawRef>, user: usize, version: u32) -> &UiInput ui_canvas(id, draw, user, version) -> &UiInput: a custom area. The hit box wants every pointer move; the cursor comes from next_flags bits 12..15 (CUR_* << HB_CURSOR_SHIFT), default crosshair (with HB_CURSOR_SET as given: 0 is the arrow). next_flags(HB_KEYS): every key is the canvas's while it has the focus (a press gives it the focus, so does ui.focus(id)); it takes them with ui.key_take.
  • fn canvas_label(&mut self, label: &str) (E14) the name of the next canvas's own K_CANVAS record ("Webseite"): what a screen reader says for it and a script's canvas:"Webseite" selector; the records the canvas publishes for its content (sem_rect) stay as they are

Source: docs/API.md in the JFLib repository.