JFLib

plat/web_windows.rs#

Source: lib/plat/web_windows.rs

Library windows and popups composited into one browser canvas. Every surface is drawn
by the existing software renderer; the browser host receives pixels, not another UI.
The windows keep their pixels as R, G, B, A rows (the order of the browser's ImageData and
Android's Bitmap): the frames' B, G, R, x is swapped once, while copying the dirty
rectangles in, and the host copies rows without touching pixels.  One window over the
whole canvas without popups is the canvas itself (no composition); otherwise the windows
and popups are composited into the canvas buffer.
(G4d) The GPU output: window 0 shows on a canvas of its own above this one (web_gpu.rs), the canvas
here rests with its last frame; what leaves it comes back whole, and the canvas above goes only after
that frame (flush).
(L7) Full screen: window 0 asks the page for the browser's Fullscreen API (REQUEST_FULLSCREEN;
it shows WST_FULLSCREEN at once, the page's answer jfgui_fullscreen confirms it or takes it
back: refused without the user's gesture, left with Esc); a tool window covers the canvas
(its place comes back after).  Android: nothing.
(G7a) The pointer lock (plock.rs): the page locks the canvas (REQUEST_POINTER_LOCK; Pending) from
the user's gesture -- at once while the page still has the activation of the press that made the
app ask, else with the next press in it -- and answers with jfgui_pointer_lock; the raw motion
comes through jfgui_motion.  Android and iOS: Unsupported.
  • fn win_create( title: &str, width: i32, height: i32, _flags: u32, _owner: i32, x: i32, y: i32, ) -> i32 Create a window within the app canvas; window zero uses the host viewport.

  • fn win_destroy(id: i32) Destroy a library surface and return focus to the main window.

  • fn win_show(id: i32, mode: u32) Show or hide a library surface.

  • fn win_activate(id: i32) Set keyboard focus to an enabled library window.

  • fn win_enable(id: i32, enabled: bool) Enable or disable window input, including modality established by the UI runtime.

  • fn win_set_rect(id: i32, x: i32, y: i32, width: i32, height: i32) Change a library surface rectangle, preserving fields equal to PW_KEEP. Window zero is the host's viewport: its place and size follow the host alone (E_RESIZE), not a saved placement.

  • fn win_get_rect(id: i32) -> Option<[i32; 4]> Current canvas-relative client rectangle.

  • fn win_work_area(_id: i32) -> Option<[i32; 4]> The browser canvas is the available work area.

  • fn win_set_title(id: i32, title: &str) Update a library title and the browser document title for window zero.

  • fn win_state(id: i32) -> u32 Current library state flags; browser surfaces use library-owned chrome.

  • fn win_cmd(id: i32, command: u32) Apply library-window commands; close is delivered to the normal app close workflow.

/// (G7a) (browser) ask the page for the pointer lock of the canvas (one byte, 1 lock / 0 let go):
/// requestPointerLock from the user's gesture (with unadjustedMovement where the browser has it);
/// the page answers with jfgui_pointer_lock, the motion comes with jfgui_motion
REQUEST_POINTER_LOCK: u32 = 31
  • extern "C" fn jfgui_pointer_lock(state: u32) -> u32 (G7a) the page's pointer lock changed: 1 the canvas holds it, 0 it let go (Esc, the browser, the page lost the focus), 2 the browser refused it (pointerlockerror after a press) -> 1 taken

  • extern "C" fn jfgui_motion(dx: f64, dy: f64) -> u32 (G7a) the locked pointer's motion from the page (movementX / movementY, summed since the last call): raw with unadjustedMovement, else the browser's CSS pixels -> 1 taken

/// (L7) (browser) ask the page to show the canvas in full screen (one byte, 1 on / 0 off): the
/// Fullscreen API from the user's gesture; the page answers with jfgui_fullscreen
REQUEST_FULLSCREEN: u32 = 23
  • extern "C" fn jfgui_fullscreen(on: u32) -> u32 (L7) the page's full screen of the canvas (1 in full screen, 0 not: left, refused): window 0's WST_FULLSCREEN follows, an E_RESIZE lets the UI look (UIC_FULLSCREEN on a change of its own)

  • fn win_begin_move(id: i32) Begin a pointer-driven move of a non-main library window, from where the pointer went down (a finger may have moved on before the UI knew it is a drag).

  • fn win_begin_resize(id: i32, edges: u32) Begin resizing a library surface inside the browser canvas, from where the pointer went down.

  • fn win_size(id: i32) -> (i32, i32) Physical client dimensions.

  • fn win_dpi(id: i32) -> i32 Current host DPI of a library surface.

  • fn win_set_min_size(id: i32, width: i32, height: i32) Minimum drag-resize dimensions in DIP.

  • fn win_present(id: i32, frame: &Frame<'_>, rects: Option<&[[i32; 4]]>) Copy the dirty rectangles of a software-renderer frame into the window's surface (R, G, B, A); the next flush shows them.

  • fn win_set_cursor(_id: i32, shape: u32) Request one of the shared browser pointer shapes.

  • fn win_hit_hook(_hook: Option<fn(i32, i32, i32) -> u32>) Hit testing remains inside the shared UI; no OS nonclient callback is installed.

  • fn win_move_hook(_hook: Option<fn(i32, &mut [i32; 4])>) Dragged library surfaces are not snapped in the browser yet.

  • fn set_refresh(_callback: Option<fn()>) Native modal resize callbacks are unnecessary for host-stepped browser rendering.

  • fn cursor_create( _pixels: &[u8], _width: i32, _height: i32, _x: i32, _y: i32, _dpi: i32, ) -> i32 Custom native cursor handles are unavailable; use the shared system-shape cursor mapping.

  • fn cursor_destroy(_id: i32) No native custom cursor handle exists.

  • fn cursor_dpi(dpi: i32) -> i32 Cursor scale follows the canvas DPI.

  • fn cursor_probe(_shape: u32, _dpi: i32) -> (u64, i32) (tests, E3) the cursor shown for shape at dpi and the width of a drawn one: none here (the system has the shapes, cursor_fallback's for the rest)

  • fn popup_anchor(_slot: u32, _anchor: [i32; 4], _kind: u32, _nat: [i32; 2]) The canvas shows popups where the library put them (inside the canvas).

  • fn popup_placed(_slot: u32) -> Option<[i32; 2]> Popups stay where the library put them.

  • fn popup(slot: u32, owner: i32, rect: Option<[i32; 4]>, frame: Option<&Frame<'_>>) Paint an existing library popup into the canvas overlay stack.

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