ui/desk.rs#
Source: lib/ui/desk.rs
desk -- windows inside an area of a window: the app's programs in windows of their own
(title bar with icon, title and buttons, moving, resizing at every edge and corner,
maximising, minimising, z-order, snapping, keyboard, screen readers) and a taskbar; the
state is the app's DeskState
desk_begin(id, &mut st, wins) the area takes the next place (without next_size it fills
the box); wins describe every open window each frame, in
the order of the taskbar (DeskWin: key != 0, title, icon,
DWF_* flags, minimum and first size)
desk_next(&mut st) -> Some(key) the next window to fill, from the bottom of the z-order to
the top (minimised ones are left out): emit its content (a
vertical box that clips) and call it again until None
desk_end(&mut st) -> Vec<DeskEv> what the user did: close requests (the app takes the
window out of its list, or asks first), activation, moves,
resizes, state changes (also those of the taskbar)
desk_taskbar_begin(id) a taskbar of desk `id`: a row with the style's surface;
desk_taskbar_end() the app's own items (a start button, a clock) go before
and after desk_taskbar. Between desk_begin and desk_end
without next_size / next_rect it takes the strip the
area keeps free (DeskState::set_reserve)
desk_taskbar(id, &mut st, flags) a button per window of desk `id` (icon, title; the
active one pressed): a click activates, a second click
minimises, a right click (menu key, Shift+F10) opens
Wiederherstellen / Minimieren / Maximieren / Schließen;
what does not fit goes into a "Weitere Fenster" menu at
the end; DTB_ICONS: icons only
DeskState plain data: the windows' places, the z-order, maximised /
minimised / snapped, the active one -- save() -> text,
load(text), activate / minimize / maximize / restore /
toggle_max / snap / cycle / set_rect / forget, order /
active / state / rect / contains, set_reserve
The windows: a press anywhere on one brings it to the front and makes it active (drawn as
active, its content gets the keys). The title bar moves it (a maximised or snapped one comes
back to its size under the pointer); while it is dragged its edges stick to the area's edges,
and with the pointer at the area's left or right edge it snaps to that half, at the top edge
it maximises (a preview shows where). Every edge and corner resizes it down to its minimum
size; a double click on the title bar maximises or restores it; the icon and a right click on
the title bar open its menu. Esc cancels a drag. The area keeps every window reachable: when it shrinks, at least
KEEP DIP of a window and its whole title bar stay inside (shown there, the place in the state
stays). Maximised windows fill the area minus the reserved strip (a taskbar inside it); new
windows are cascaded from the top left. Places are logical (DIP from the area's start
corner): a mirrored (RTL) window shows them mirrored, the title bar's buttons at the left.
Keyboard (while the focus is inside the area, or nowhere): Alt+F6 / Alt+Shift+F6 the next /
previous window (the active one goes to the back), Alt+F10 maximises / restores the active
one, Alt+F9 minimises it, Alt+- opens its menu. Tab never enters the windows behind the
active one (their widgets are no Tab stops); each window is an F6 pane, and a focus that
arrives in a window behind (F6, a screen reader, focus(id)) brings it to the front. The
active window gets the keyboard focus back where it was (else its first Tab stop).
Screen readers: each shown window is a dialog record named by its title (" (maximiert)"
after it when it is), the active one selected; its title bar, buttons and content are inside
it, whatever the windows above cover. The taskbar is a group "Taskleiste" with a button per
window (" (minimiert)" after a minimised one's title, the active one pressed).
Structural changes (buttons, menus, keys) are applied at desk_end, followed by another pass;
drags change the place at once. Widget ids are parts of the area id (pid).
Every window keeps the state of its window areas (WinParts::desk): an area of the same id in
two windows keeps its own; desk_taskbar shows the area of desk_begin's window (outside of
desk_begin .. desk_end the window being built's, else the first window's that has the id).
/// DeskWin flags: no close button (the app closes the window itself)
DWF_NOCLOSE: u32 = 1
/// no minimise button (and no minimising by keys or the taskbar)
DWF_NOMIN: u32 = 2
/// no maximise button (no double click, no snapping to the top edge)
DWF_NOMAX: u32 = 4
/// a fixed size: no resize grips, no maximising, no snapping to a half
DWF_FIXED: u32 = 8
/// a new window starts maximised (an IDE)
DWF_MAXIMIZED: u32 = 16
/// no taskbar button
DWF_NOTASK: u32 = 32
/// DeskState::state: maximised (with DW_MIN: it comes back maximised)
DW_MAX: u32 = 1
/// minimised (hidden until restored)
DW_MIN: u32 = 2
/// snapped to the start (left) / end (right) half of the area (mirrored windows show it the
/// other way round)
DW_LEFT: u32 = 4
DW_RIGHT: u32 = 8
/// desk_taskbar flags: icons only
DTB_ICONS: u32 = 1
struct DeskWin<'a>a window as the app describes it to desk_begin every framekey: u32-- != 0 and stable (the saved state refers to it)title: &'a str-- shown in its title bar, its taskbar button and to screen readersicon: u32-- IC_* of its title bar and taskbar button (0 = none)flags: u32-- DWF_*min: [i32; 2]-- the smallest content size (DIP, without the title bar; 0 = the library's)size: [i32; 2]-- the size a new window gets (DIP, without the title bar; 0 = the library's)
impl<'a> DeskWin<'a>
const fn new(key: u32, title: &'a str, icon: u32) -> DeskWin<'a>a window with the library's sizes and every buttonconst fn flags(mut self, f: u32) -> DeskWin<'a>add DWF_* flagsconst fn min(mut self, w: i32, h: i32) -> DeskWin<'a>the smallest content size (DIP)const fn size(mut self, w: i32, h: i32) -> DeskWin<'a>the content size of a new window (DIP); DWF_FIXED windows keep itenum DeskEvwhat desk_end reportsClose(u32)-- the user wants to close the window (close button, menu, taskbar): take it out of the list of windows (DeskState keeps its place until forget), or ask firstActivate(u32)-- it became the active windowMove(u32)-- the user moved it (a drag ended)Resize(u32)-- the user resized itState(u32)-- minimised, maximised, restored or snapped (DeskState::state)
struct DeskStatethe windows of an area: kept by the app and passed to desk_begin / desk_next / desk_end / desk_taskbar. Plain data: save() / load() turn it into a few lines of text (desk 1, thenwin KEY X Y W H STATEfrom the bottom of the z-order to the top -- x, y from the area's start corner, outer size, all DIP; STATE the DW_* bits -- andactive KEY; unknown lines are skipped). The reserved strip is no part of it.
impl DeskState
fn new() -> DeskStateno windows: every window goes cascaded to the front in its first framefn reset(&mut self)forget every window: each goes to its first place in the next framefn set_reserve(&mut self, insets: [i32; 4])the strip the area keeps free for a taskbar inside it (DIP: start, top, end, bottom): maximised and snapped windows leave it out, the title bars stay above it; not savedfn reserve(&self) -> [i32; 4]the reserved strip (set_reserve)fn contains(&self, key: u32) -> boolthe state knows the windowfn order(&self) -> Vec<u32>the windows from the bottom of the z-order to the top (minimised ones too)fn active(&self) -> u32the active window (0: none)fn state(&self, key: u32) -> u32DW_* bits of the window (0: a normal window, or an unknown one)fn rect(&self, key: u32) -> Option<[i32; 4]>the normal place of the window: x, y from the area's start corner, outer width and height (DIP) -- what it comes back to from maximised, snapped or minimisedfn set_rect(&mut self, key: u32, r: [i32; 4])set the normal place of a window (DIP; see rect); a maximised or snapped one shows it once restoredfn activate(&mut self, key: u32)bring the window to the front and make it active (a minimised one comes back)fn minimize(&mut self, key: u32)minimise the window (it keeps its place in the z-order; the topmost other one becomes active)fn maximize(&mut self, key: u32)maximise the window (and activate it)fn restore(&mut self, key: u32)a minimised window comes back (as it was: maximised stays maximised); else a maximised or snapped one goes back to its normal place; it becomes activefn toggle_max(&mut self, key: u32)maximise the window, or restore a maximised (or snapped) onefn snap(&mut self, key: u32, half: u32)snap the window to the start (DW_LEFT) or end (DW_RIGHT) half of the area, 0: back to its normal placefn cycle(&mut self, forward: bool) -> Option<u32>the next window (forward: the active one goes to the back and the one below it comes to the front; back: the one at the back comes to the front) among the windows that are not minimised -> the window now activefn forget(&mut self, key: u32)forget a window (a closed one: it comes back cascaded)fn save(&self) -> Stringthe state as text (see DeskState)fn load(text: &str) -> Option<DeskState>a state saved with save -> None when the text is no desk state (version 1)
impl Ui
fn desk_begin(&mut self, id: u32, st: &mut DeskState, wins: &[DeskWin])desk_begin(id, &mut st, wins): open the window area (always pair with desk_end; fill it with desk_next). It takes the next place of the box (the whole rest when no size was set); wins: every open window, each frame (titles and icons may change), in the order the taskbar shows them.fn desk_next(&mut self, st: &mut DeskState) -> Option<u32>desk_next(&mut st) -> the next window to fill (None: done), from the back to the front; its content goes into a vertical box (it clips) until the next callfn desk_end(&mut self, st: &mut DeskState) -> Vec<DeskEv>desk_end(&mut st) -> what the user did in this pass (and the taskbar since the last desk_end): close requests, activation, moves, resizes, state changesfn desk_taskbar_begin(&mut self, id: u32)desk_taskbar_begin(id): open a taskbar for deskid(always pair with desk_taskbar_end): a row with the style's taskbar surface; the app's items and desk_taskbar go inside. Inside desk_begin .. desk_end without next_size / next_rect it takes the area's reserved strip (DeskState::set_reserve: the bottom one, else the top one), else the next place, TASK_H DIP high unless next_size says otherwise.fn desk_taskbar_end(&mut self)desk_taskbar_endfn desk_taskbar(&mut self, id: u32, st: &mut DeskState, flags: u32)desk_taskbar(id, &mut st, flags): the buttons of deskid's windows (DTB_*), in the order of desk_begin's list; without a size they take the room the row leaves. Their changes apply at once; desk_end reports them.