JFLib

ui/stencil.rs#

Source: lib/ui/stencil.rs

stencil -- the Shapes window of a diagram editor (Visio's Shapes pane), generic: the app hands
in stencils with tiles (a name, a QuickInfo, a preview drawn through ui::Draw); the panel lays
them out, takes the pointer, the keyboard and drags, tells screen readers, and reports what
happened.  It knows nothing about diagrams; every text it shows comes from the app.

  stencil_panel(id, &mut StencilState, &StencilPanel) -> Vec<StencilEvent>
       top to bottom: the search box (IC_SEARCH, labels.search as its placeholder) with a
       button for the recent searches (labels.history; neither with StencilState::no_search,
       JD15), the "More shapes" button
       (StencilPanel::more_id, labels.more), the title rows -- the quick shapes collection
       (SK_QUICK, labels.quick), the search results while StencilPanel::results is Some
       (SK_SEARCH, labels.results with "{}" = their number), a row per stencil --, a movable
       splitter (StencilState::split, DIP; 0 = automatic), the tiles of the active view in a
       scroll view.  Give it a size with next_size first (none: it fills its box).
  stencil_drag_decode(bytes) -> Option<(stencil, tile)>   the keys a tile drag carries
       (DragData::bytes of the app's kind StencilPanel::drag_kind: two u32, little-endian)

Views (StencilState::active = the key of a title; a key that names none -- the default --
shows the first stencil): a stencil shows its TL_QUICK tiles, a thin line, then the others
(MS-04); an SD_EDITABLE stencil always has both parts, an empty part shows a hint
(labels.quick_empty, labels.drop_hint).  The quick collection shows the TL_QUICK tiles of
every stencil under small captions (none: labels.quick_empty).  The results show the hits
the app found (none: labels.no_results_title / _text).  No stencil at all: an empty state
(labels.empty_title / _text) with a link labels.more (StencilEvent::More).
View modes (StencilState::view): SV_ICONS_NAMES tiles of 72 x 76 DIP (the preview on top,
the name in up to two lines, cut with "…"), SV_ICONS 40 x 40 (the name in the tooltip only),
SV_NAMES rows with the name, SV_DETAILS rows with the preview, the name and the QuickInfo.
The tooltip of a tile is "name – QuickInfo".  Tiles without a preview show IC_SHAPES.

Search: typing reports Search (the app recomputes `results`; the results become the active
view, an empty query returns to the view before); Enter keeps the query in
StencilState::history (newest first, at most 10, no duplicates); Down, Alt+Down or F4 in the
box, or the button beside it, list the history (a pick searches again); Esc clears the query
(in an empty box Esc gives up the focus).  The number of results is announced politely.
Input: a click on a title activates it; Up / Down / Home / End move between the titles (the
focused title is the active one).  A click on a tile -> Activate (the app arms click placing
and marks the tile TL_ARMED), Enter / Space / a double click -> Place; a right click,
Shift+F10 or the menu key -> TileMenu / StencilMenu with a point (window px) for
ui.menu_popup_at -- or open the menu in the same pass with ui.menu_popup, which for the menu
key opens at the widget with its first row focused.  The tiles are one Tab stop (entered at
the armed tile): the arrows move in the grid, Home / End to the first / last tile.  "More
shapes" (a click, Enter / Space, Alt+Down / F4) and the empty state's link -> More with the
lower left corner of the button (the app opens its menu there with ui.menu_popup_at).
Drags: every tile that is not disabled is a drag source (DragData::of_app(drag_kind, the
stencil and tile key), the tile's name as its label, DE_COPY): DragStart, DragEnd.  An
SD_EDITABLE stencil takes tile drags on its title row (appended) and, while it is shown, on
its tile area (an accent mark shows where): Dropped with the index into its tiles to insert
before (counted with the dragged tile still in place) and whether it went into the quick
part; the app moves the tile when it came from the same stencil.
Screen readers and scripts: the panel is a box named labels.panel; the title rows are tabs
(K_TAB, selected = active: `click tab:"Allgemein"`, `expect tab:"Allgemein" selected`) --
a vertical tab list is what the title rows are, and scripts and the platforms' screen
readers know tabs with a selection; the tiles are buttons named by the tile (checked with
TL_ARMED, disabled with TL_DISABLED, the QuickInfo as their description: `click
button:"Rechteck"`, `drag button:"Rechteck" tab:"Favoriten"`); the quick collection's
captions are headings; the search box is an edit named labels.search (`#ID+1`); the
splitter is a slider named "Teiler" (F8 reaches it, the arrows move it).
Only the rows of tiles in view (and those of the focused and the dragged tile) are laid out
and drawn: a stencil of 300 tiles costs what a screenful costs.

Ids: the panel `id`; the search box id + 1, the history button and its list id + 2 (its rows
id + 0x10 + k), the splitter id + 4, the title view id + 5, the tile view id + 6, the empty
state's link id + 7, the tile area's drop target id + 8; the titles id + 0x100 (quick),
id + 0x101 (results), id + 0x102 + i (stencil i); the tiles id + 0x1000 + n (n: the place
in the view).  StencilPanel::more_id is the app's own.
/// StencilTile::flags: a quick shape of its stencil (shown above the line, in the quick
/// collection)
TL_QUICK: u32 = 1 << 20
/// StencilTile::flags: armed for click placing (drawn checked)
TL_ARMED: u32 = 1 << 21
/// StencilTile::flags: disabled (no input, no drag)
TL_DISABLED: u32 = ST_DISABLED
/// StencilDef::flags: the stencil takes dropped tiles (favourites, "My shapes"): added and
/// reordered by the app on StencilEvent::Dropped
SD_EDITABLE: u32 = 1 << 20
/// StencilState::view: icons with the names below (the default)
SV_ICONS_NAMES: u8 = 0
/// StencilState::view: icons only (the name in the tooltip)
SV_ICONS: u8 = 1
/// StencilState::view: names only, one row each
SV_NAMES: u8 = 2
/// StencilState::view: rows with the icon, the name and the QuickInfo
SV_DETAILS: u8 = 3
/// StencilState::active: the quick shapes collection
SK_QUICK: u32 = 0xFFFF_FFFE
/// StencilState::active: the search results
SK_SEARCH: u32 = 0xFFFF_FFFF
  • struct StencilTile<'a> a tile of a stencil (a master): what the panel shows of it
    • key: u32 -- the app's key for it (unique within its stencil; a drag and the events carry it)
    • name: &'a str -- its name (the label, the button's name for screen readers and scripts)
    • tip: &'a str -- its QuickInfo: the tooltip after the name, the details view, the description
    • draw: Option<DrawRef> -- its preview (None: a generic shapes icon)
    • ver: u32 -- the preview's version (cmd_custom: change it when the drawing changes)
    • flags: u32 -- TL_QUICK, TL_ARMED, TL_DISABLED

impl<'a> StencilTile<'a>

  • const fn new(key: u32, name: &'a str) -> StencilTile<'a> a tile without a QuickInfo, a preview or flags

  • const fn tip(mut self, tip: &'a str) -> StencilTile<'a> with a QuickInfo

  • fn preview(mut self, draw: Option<DrawRef>, ver: u32) -> StencilTile<'a> with a preview and its version

  • const fn flags(mut self, f: u32) -> StencilTile<'a> add flags (TL_QUICK, TL_ARMED, TL_DISABLED)

  • struct StencilDef<'a> a stencil: its title row and its tiles

    • key: u32 -- the app's key (below 0xFFFF_FFF0: the SK_* keys are the panel's)
    • title: &'a str
    • tiles: &'a [StencilTile<'a>]
    • flags: u32 -- SD_EDITABLE
  • struct StencilHit<'a> a hit of the app's search: the tile and the stencil it belongs to

    • stencil: u32
    • tile: StencilTile<'a>
  • struct StencilLabels<'a> the texts of the panel (the app translates them; the panel has none of its own)

    • panel: &'a str -- the panel's name for screen readers ("Shapes")
    • search: &'a str -- the search box's placeholder and name ("Shapes suchen")
    • history: &'a str -- the history button's tooltip and name ("Letzte Suchen")
    • more: &'a str -- the "More shapes" button and the empty state's link ("Weitere Shapes")
    • quick: &'a str -- the quick collection's title ("Quick-Shapes")
    • results: &'a str -- the results' title, "{}" = their number ("Suchergebnisse ({})"); also announced
    • quick_empty: &'a str -- the hint of an empty quick collection and of an empty quick part of an editable stencil ("Hier Quick-Shapes ablegen")
    • drop_hint: &'a str -- the hint of an editable stencil without other tiles ("Shapes hierher ziehen")
    • empty_title: &'a str -- the empty state without stencils
    • empty_text: &'a str
    • no_results_title: &'a str -- the results without a hit
    • no_results_text: &'a str
  • struct StencilPanel<'a> what stencil_panel shows in a pass

    • stencils: &'a [StencilDef<'a>]
    • results: Option<&'a [StencilHit<'a>]> -- the hits of StencilState::query: Some while the app searches (the query is not empty)
    • drag_kind: u32 -- the app's own drag kind of a tile (DT_USER0 << k)
    • more_id: u32 -- the widget id of the "More shapes" button (activated: StencilEvent::More)
    • labels: StencilLabels<'a>
  • struct StencilState what the panel keeps between passes (the app owns it; the public fields are the app's to read and set)

    • active: u32 -- the key of the active title: a stencil's, SK_QUICK or SK_SEARCH
    • view: u8 -- SV_ICONS_NAMES, SV_ICONS, SV_NAMES, SV_DETAILS
    • query: String -- the search box's text
    • history: Vec<String> -- the recent searches, newest first (at most 10; the app may store and restore them)
    • split: i32 -- the height of the title rows in DIP (the splitter; 0 = automatic: up to 40 % of the panel); the panel keeps it between one row and all of them
    • no_search: bool -- (JD15) the panel shows no search box (Visio's option "Show Shape Search pane" off); the query stays, set it to "" to end a search

impl StencilState

  • fn new() -> StencilState a new state: the first stencil active, icons and names, no query

  • enum StencilEvent what happened in the panel in a pass (stencil_panel returns them in order)

    • Activate { stencil: u32, tile: u32 } -- a click on a tile: the app arms click placing (and marks the tile TL_ARMED)
    • Place { stencil: u32, tile: u32 } -- Enter / Space on a tile or a double click: place it in the middle of the view
    • TileMenu { stencil: u32, tile: u32, at: [i32; 2] } -- a right click, Shift+F10 or the menu key on a tile: its menu at at (window px)
    • StencilMenu { stencil: u32, at: [i32; 2] } -- the same on a title row (SK_QUICK / SK_SEARCH for those two)
    • Search -- StencilState::query changed: the app recomputes the results
    • Dropped { stencil: u32, before: usize, quick: bool, from_stencil: u32, from_tile: u32 } -- a tile was dropped onto the SD_EDITABLE stencil stencil: insert it before its tile before (an index into its tiles, counted with a dragged tile of its own still in place; its length = at the end); quick: into the quick part
    • More { at: [i32; 2] } -- "More shapes" or the empty state's link: the app opens its menu at at (window px, the lower left corner of the button), ui.menu_popup_at
    • DragStart { stencil: u32, tile: u32 } -- a tile began to be dragged
    • DragEnd -- that drag ended (dropped somewhere or cancelled; ui.drag_effect tells)
  • fn stencil_drag_decode(bytes: &[u8]) -> Option<(u32, u32)> the stencil and tile keys of a tile drag's bytes (DragData::bytes of StencilPanel:: drag_kind), None when they are no tile drag's

impl Ui

  • fn stencil_panel(&mut self, id: u32, st: &mut StencilState, p: &StencilPanel<'_>) -> Vec<StencilEvent> The Shapes window of a diagram editor (see the module header): the search box, "More shapes", the title rows, a splitter and the tiles of the active view, in the size next_size gave (else it fills its box). Returns what happened, in order.

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