JFLib

Drawing commands#

Source: lib/ui/cmd.rs

cmd -- per-layer draw command lists, recorded during a UI pass and replayed into the
framebuffer afterwards (popups drawn late still end up on top, passes that are thrown
away cost no pixels)                                                 [src/ui/ui_cmd.s]

Drawing calls for apps (current layer, physical pixels):
  draw_color(argb)                     colour for the next draw_* calls
  draw_rect(x, y, w, h)                filled rectangle
  draw_rrect(x, y, w, h, r)            filled rounded rectangle
  draw_frame(x, y, w, h, r, t)         rounded border of thickness t
  draw_text(x, y, s, font_size)        text with baseline y; font_size = FONT_* | size_fx << 8
  draw_icon(cp, x, y, size_fx)         icon, em box top-left at x, y
  icon_hook(f)                         an app draws chosen icons itself (render time)
  draw_circle(cx, cy, r, t)            24.8 fixed; t = 0 fills
  draw_line(x0, y0, x1, y1, width)     24.8 fixed, round caps
  draw_image(sf, x, y, w, h)           surface scaled to w x h (nearest) or 1:1
  draw_clip(x, y, w, h) / draw_unclip()
Internal: cmd_reset, cmd_layer(l) -> previous, cmd_rrect, cmd_text, cmd_custom,
cmd_shadow, render_all, render_popup(dx, dy).

Every record keeps the byte size the asm gives it (cmd_alloc rounds to 8): a layer holds
at most its capacity (CAPS_MAIN / CAPS_SMALL), further commands are dropped as in the asm.
The dirty regions (dirty.rs) hash every record's content (cmd_parts: without its position,
which is mixed in separately, so scrollcopy.rs can hash it relative to a scrolled content)
and its box (cmd_bbox).
  • struct Gfx<'a> the gfx target of a custom draw call (render time): the draw context (clip, origin, colour), the surface and the text engine (its path and rasterizer serve Shapes)
    • dc: &'a mut Dc
    • sf: &'a mut Surface
    • text: &'a mut Text

impl Gfx<'_>

  • fn shapes(&mut self) -> Shapes<'_> the anti-aliased shape calls (fill_rrect, circles, lines) on this target

  • trait Draw a custom draw function (cmd_custom: canvases, custom tracks): draw(g, rect) at render time with the clip set to rect (absolute px). Its identity (the Rc) and the version of the command decide whether it is redrawn.

    • fn draw(&self, g: &mut Gfx, r: [i32; 4])
  • type DrawRef = Rc<dyn Draw>

  • type IconHook = Rc<dyn Fn(&mut Gfx, u32, i32, i32, i32, u32) -> bool> icon_hook: f(g, cp, x, y, size_fx, argb) -> true when it drew icon cp itself (x, y = target pixels with the origin applied), false = the icon font draws it

  • enum Cmd one recorded draw command [C_*]

    • Rect { x: i32, y: i32, w: i32, h: i32, c: u32 }
    • RRect { x: i32, y: i32, w: i32, h: i32, r: u16, t: u16, fill: u32, stroke: u32, stroke2: u32 } -- fill (alpha 0 = none), border t px in stroke, its bottom band in stroke2; r and t are kept as u16
    • PanelFx { x: i32, y: i32, w: i32, h: i32, r: i32, t: i32, fill: u32, stroke: u32 } -- Fractional rounded panel; geometry is 24.8 pixels and composited once.
    • Text { x: i32, y: i32, font: u16, size: i32, c: u32, maxw: i32, s: Vec<u8> } -- text with baseline y; maxw != 0 clips it to x .. x + maxw
    • Icon { x: i32, y: i32, cp: u32, size: i32, c: u32 } -- icon, em box top-left at x, y
    • Image { x: i32, y: i32, w: i32, h: i32, sf: Rc<Surface>, ver: u32 }
    • Clip { x: i32, y: i32, w: i32, h: i32 }
    • Unclip
    • Circle { x: i32, y: i32, r: i32, t: i32, c: u32 } -- 24.8; t = 0 fills
    • Line { x0: i32, y0: i32, x1: i32, y1: i32, w: i32, c: u32 } -- 24.8, round caps
    • Custom { x: i32, y: i32, w: i32, h: i32, f: Option<DrawRef>, user: usize, ver: u32 }
    • Shadow { x: i32, y: i32, w: i32, h: i32, r: i32, depth: i32, c: u32 }

impl Ui

  • fn cmd_layer(&mut self, l: u32) -> u32 cmd_layer(l) -> previous layer
  • fn draw_color(&mut self, argb: u32) ui_draw_color(argb): colour for the following draw_* calls
  • fn draw_color_get(&self) -> u32 the colour of the following draw_* calls (g_dcol)
  • fn draw_rect(&mut self, x: i32, y: i32, w: i32, h: i32) ui_draw_rect(x, y, w, h)
  • fn draw_rrect(&mut self, x: i32, y: i32, w: i32, h: i32, r: i32) ui_draw_rrect(x, y, w, h, r): filled rounded rectangle in the draw colour
  • fn draw_frame(&mut self, x: i32, y: i32, w: i32, h: i32, r: i32, t: i32) ui_draw_frame(x, y, w, h, r, t): border only, in the draw colour
  • fn cmd_rrect(&mut self, x: i32, y: i32, w: i32, h: i32, r: i32, t: i32, fill: u32, stroke: u32, stroke2: u32) cmd_rrect(x, y, w, h, r, t, fill, stroke, stroke2): rounded rectangle with an optional fill and border (stroke2: the bottom edge)
  • fn cmd_panel_fx(&mut self, x: i32, y: i32, w: i32, h: i32, r: i32, t: i32, fill: u32, stroke: u32) Rounded fill/border with 24.8 pixel geometry and a single coverage composite. Fractional bounds participate in dirty-region hashing and clipping.
  • fn draw_text(&mut self, x: i32, y: i32, s: &str, font_size: u32) ui_draw_text(x, y, s, font_size): font_size = FONT_* | size_fx << 8
  • fn cmd_text(&mut self, x: i32, y: i32, s: &[u8], font: u32, size: i32, c: u32, maxw: i32) cmd_text(x, y, s, font, size_fx, colour, maxw): at most 4000 bytes, never cut inside a UTF-8 sequence
  • fn emit_text(&mut self, x: i32, y: i32, s: &str, c: u32) emit_text(x, baseline, s, colour): text in the current text font (styles)
  • fn draw_icon(&mut self, cp: u32, x: i32, y: i32, size: i32) ui_draw_icon(cp, x, y, size_fx)
  • fn draw_circle(&mut self, x: i32, y: i32, r: i32, t: i32) ui_draw_circle(cx, cy, r, t): 24.8 fixed, t = 0 fills
  • fn draw_line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, w: i32) ui_draw_line(x0, y0, x1, y1, width): 24.8 fixed
  • fn draw_image(&mut self, sf: &Rc<Surface>, ver: u32, x: i32, y: i32, w: i32, h: i32) ui_draw_image(sf, x, y, w, h): w / h 0 = natural size; ver stands for the surface's SF_AUX version (bump it when the pixels change)
  • fn draw_clip(&mut self, x: i32, y: i32, w: i32, h: i32) ui_draw_clip(x, y, w, h)
  • fn draw_unclip(&mut self) ui_draw_unclip
  • fn icon_hook(&mut self, f: Option<IconHook>) ui_icon_hook(f): an app draws chosen icons itself (None removes the hook)
  • fn cmd_custom(&mut self, x: i32, y: i32, w: i32, h: i32, f: Option<DrawRef>, user: usize, ver: u32) cmd_custom(x, y, w, h, f, user, version): f.draw(g, rect) at render time, clipped
  • fn cmd_shadow(&mut self, x: i32, y: i32, w: i32, h: i32, r: i32, depth: i32) cmd_shadow(x, y, w, h, r, depth): soft shadow in the draw colour

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