Windows#
Source: lib/ui/win.rs
win -- multi-window runtime: tool windows and dialog windows built by the same App::frame
as the main window, each with its own UI state [src/ui/ui_win.s]
App-facing:
window_begin(id, title, open, flags, rect) -> true: emit the content now (always pair
with window_end; see WF_* / WinRect; open / rect: shared with the library)
window_end()
window_place(id, &rect) move / resize (copied into the window's WINRECT)
window_rect(id) -> Option<WinRect> current placement (None = unknown window)
window_state(id) -> UWS_* UWS_OPEN | UWS_VISIBLE | UWS_ACTIVE | UWS_MINIMIZED |
UWS_FULLSCREEN
window_fullscreen(id, on) (L7) over the whole monitor without a frame, or back;
UIC_FULLSCREEN when the platform or the user changes it
window_activate(id) give it the keyboard (raises it)
window_snap(id, area, dist) its edges snap to the area's while the user moves it
window_destroy(id) free its state and buffers (created again when shown)
window_current() -> id id of the window being built (0 = main)
window_modal() -> id id of the topmost modal window or 0
sync_hook_set(f) f() -> true while background jobs run (`sync`)
Platform: hit_flags_win(win, x, y), win_hooks_set(on) (OS windows through the plat_win_*
API, the asm's uiw_plat_hooks table), uiw_hit_pw (the platform's hit hook), uiw_pw /
uiw_from_pw (UI index <-> platform window).
Runtime (runtime.rs, ctx.rs, chrome.rs, auto.rs, drop.rs): the uiw_* functions below.
How it works: the per-window state of every module lives in WinParts (lib.rs); `Ui::wp`
is the live window's. uiw_use(i) swaps the live parts into the record of the window
that was live and window i's parts out of its record (core::mem::swap of a Box), so every
widget, popup, dialog and the dirty-region code work unchanged in whichever window is
live. Outside of the passes and of the event dispatch the main window (index 0) is live.
Platform operations are never done inside window_begin: they are recorded in Rec::want
and done by uiw_settle after the frame settled (headless runs: none -- the windows only
exist as framebuffers).
The asm keeps the app's `&open` and `&rect` pointers in the window record and writes
through them later (close button, Esc, placement by the user); here the app passes a
Shared<T> (Rc<Cell<T>>) and the record keeps a clone of it.
impl<T: Copy> Shared<T>
impl Ui
fn window_title_height(&self, flags: u32) -> i32uiw_drawable(i): the window exists and is shown (the main window: always) the title bar of a window with these WF_* flags that draws its own (DIP): the style's, higher with a finger, and the window grows with it (lay out what lies below it with this height)fn window_begin(&mut self, id: u32, title: &str, open: Option<&Shared<i32>>, flags: u32, rect: Option<&Shared<WinRect>>) -> boolui_window_begin(id, title, open, flags, rect) -> true: the window is shown, emit its content now (window_end always follows). open None = always open; rect None: the library keeps the placement. The owner is the window being built.fn window_end(&mut self)ui_window_end: close window_begin (also when it returned false)fn sync_hook_set(&mut self, f: Option<fn() -> bool>)ui_sync_hook_set(f): f() -> true while background jobs are pending (the script commandsyncwaits for false)fn window_place(&mut self, id: u32, rect: &WinRect)ui_window_place(id, &rect): set the window's placement (copied into its WINRECT; applied when it is built next). id 0: the main window (headless: its size)fn window_snap(&mut self, id: u32, area: [i32; 4], dist: i32)ui_window_snap(id, area, dist): while the user moves window id, its outer edges snap to the edges ofarea(x, y, w, h in DIP of the owner's client area, like its WINRECT) once they are at mostdistDIP away -- both axes at a corner; dist 0 turns it off. Live where the platform lets the UI see the move (Windows: WM_MOVING) and for scripts (movewin); a window manager that moves the windows itself (X11, Wayland) and the browser do not snap. Call it in every frame the area may change (after the window's first window_begin).fn window_rect(&self, id: u32) -> Option<WinRect>ui_window_rect(id) -> the window's placement (None = unknown window)fn window_state(&mut self, id: u32) -> u32ui_window_state(id) -> UWS_OPEN | UWS_VISIBLE | UWS_ACTIVE | UWS_MINIMIZED | UWS_FULLSCREEN (0 unknown)fn window_fullscreen(&mut self, id: u32, on: bool)(L7) window_fullscreen(id, on): show the window (0 = the main window, else the app's window id) over its whole monitor without a frame, or back to its place and frame as before. window_state reports UWS_FULLSCREEN at once; the platform follows after the frame: Windows a borderless window over the window's monitor (the old placement and style come back), X11 _NET_WM_STATE_FULLSCREEN, Wayland xdg_toplevel set_fullscreen / unset_fullscreen, the browser its Fullscreen API (only from the user's gesture: a key or a click that just happened). A tool window drops its library title bar and border meanwhile. When the platform or the user leaves (or enters) full screen by itself (Esc in the browser, the window manager), the state follows and UIC_FULLSCREEN arrives (arg = the window's id). Headless runs only record it (scripts: \expect window ID fullscreen\\, \system fullscreen off\\). Nothing happens on Android and for Wayland tool windows drawn inside their owner (WST_CHILD). F11 is the app's key for it (GUIDE).fn window_activate(&mut self, id: u32)ui_window_activate(id): give the window the keyboard and put it on topfn window_destroy(&mut self, id: u32)ui_window_destroy(id): hide the window and free its state and buffers (not while it is being built)fn window_current(&self) -> u32ui_window_current -> id of the window being built (0 = main window)fn window_modal(&self) -> u32ui_window_modal -> id of the topmost modal window, 0 = nonefn window_pw(&self, id: u32) -> (i32, i32)uiw_index + uiw_pw: (UI index of app window id (-1 none, 0 the main window), its platform window (-1 none)) // pn-core