JFLib

render2d/hl.rs#

Source: lib/render2d/hl.rs

hl -- highlighting selected and hovered entities (G6d, decision 30; docs/RENDER2D.md "Hervorheben").  A child of
scene.rs.

Two bits per entity on a layer (an insert as a whole): selected, hovered.  On the GPU a mask of two bits per record of the
pool and per instance of a block (u32 words: a header word with the instances' first word, then the records', then the
instances'); changing a highlight sends the changed words only (runs, a copy each), never geometry.  While anything is
highlighted the write pass of the visibility is write_hl, which puts a visible record's bits into bits 29 and 30 of its
word in the visible list, and the layers holding a highlighted entity draw with vertex shaders that read them there
(hl_wgsl: the same shaders with the colour mixed toward the highlight and strokes wider); every other pipeline, and
every frame without a highlight, stays as it was.
/// selected: the colour three quarters of the way to HL_SELECTED_RGB, strokes a quarter pixel wider on either side (a
/// hairline stays on the fast way of short thin strokes)
HL_SELECTED: u8 = 1
/// hovered: the colour seven eighths of the way to HL_HOVER_RGB, strokes a pixel wider on either side (over a selection)
HL_HOVER: u8 = 2
/// the highlights' colours (sRGB, 0xRRGGBB) and the least alpha a highlighted colour gets (hl.wgsl)
HL_SELECTED_RGB: u32 = 0x1E64FF
HL_HOVER_RGB: u32 = 0xFF8C1A
HL_ALPHA: u32 = 0xB0
  • struct HighlightInfo what the last prepare sent of the highlights (Scene::highlight_info). It may grow
    • entities: u32 -- entities highlighted (selected, hovered or both)
    • words: u32 -- the mask's words on the GPU; the words and runs the last prepare sent; it made the mask anew
    • sent_words: u32
    • runs: u32
    • full: bool

impl Scene

  • fn set_highlight(&mut self, id: EntityId, bits: u8) -> Result<()> an entity on a layer is highlighted (HL_SELECTED, HL_HOVER, both, or 0: not); an insert as a whole. Only the mask's changed words go up with the next prepare
  • fn set_highlights(&mut self, ids: &[EntityId], bits: u8) -> Result<()> many at once (the same bits for each)
  • fn highlight(&self, id: EntityId) -> u8 an entity's highlight bits (0 for a dead id)
  • fn clear_highlights(&mut self, bits: u8) these bits off on every entity (HL_HOVER: no hover left; HL_SELECTED | HL_HOVER: nothing highlighted)
  • fn highlighted(&self) -> Vec<EntityId> the entities highlighted now
  • fn highlight_info(&self) -> HighlightInfo what the last prepare sent of the highlights

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