widget2d

    UI primitive builders (rounded rects, scissor stack, text layout) on top of mizchi/gfx, mizchi/text, mizchi/font (extracted from kagura)

    Download zip
    Author
    Version
    0.6.0
    License
    Apache-2.0
    Last updated
    15 days ago
    Downloads
    47

    Dependencies

    mizchi/widget2d does not have a README file

    BorderWidths

    pub(all) struct BorderWidths {
    top : Double
    right : Double
    bottom : Double
    left : Double
    }

    Border widths for 4 sides independently.

    BorderWidths::has_any

    fn BorderWidths::has_any(self : BorderWidths) -> Bool

    BorderWidths::uniform

    fn BorderWidths::uniform(w : Double) -> BorderWidths

    BorderWidths::zero

    ScissorRect

    pub(all) struct ScissorRect {
    x : Int
    y : Int
    width : Int
    height : Int
    }

    Scissor rectangle for clipping (pixel coordinates).

    ScissorRect::from_screen

    fn ScissorRect::from_screen(screen_w : Int, screen_h : Int) -> ScissorRect

    ScissorRect::intersect

    fn ScissorRect::intersect(self : ScissorRect, other : ScissorRect) -> ScissorRect?

    Intersect two scissor rects. Returns None if they don't overlap.

    ScissorRect::new

    fn ScissorRect::new(x : Int, y : Int, width : Int, height : Int) -> ScissorRect

    ScissorRect::to_dst_region

    fn ScissorRect::to_dst_region(self : ScissorRect, index_count : Int) ->
    DstRegion

    Convert to a DstRegion with the given index count.

    ScissorStack

    pub struct ScissorStack {
    stack : Array[ScissorRect]
    }

    Stack of scissor rects for nested overflow:hidden. Push narrows the clip region, pop restores.

    ScissorStack::current

    fn ScissorStack::current(self : ScissorStack) -> ScissorRect

    Current active scissor rect.

    ScissorStack::depth

    fn ScissorStack::depth(self : ScissorStack) -> Int

    Depth of the scissor stack (1 = root screen, >1 = nested clips).

    ScissorStack::is_visible

    fn ScissorStack::is_visible(self : ScissorStack) -> Bool

    Whether the current scissor rect has any area.

    ScissorStack::new

    fn ScissorStack::new(screen_w : Int, screen_h : Int) -> ScissorStack

    ScissorStack::pop

    fn ScissorStack::pop(self : ScissorStack) -> Unit

    Pop the last pushed scissor rect.

    ScissorStack::push

    fn ScissorStack::push(self : ScissorStack, rect : ScissorRect) -> Bool

    Push a child scissor rect. The effective clip is the intersection of the current clip and the new rect. Returns false if fully clipped.

    border_vertices

    fn border_vertices(x : Double, y : Double, w : Double, h : Double, border : BorderWidths, screen_w : Double, screen_h : Double) -> (Array[Double], Array[Int])

    Generate vertices and indices for a 4-side independent border. Pixel coords in, NDC vertices out (for builtin shader).

    filled_rect_vertices

    fn filled_rect_vertices(x : Double, y : Double, w : Double, h : Double, screen_w : Double, screen_h : Double) -> (Array[Double], Array[Int])

    Generate NDC vertices for a filled rectangle from pixel coords.

    filled_rounded_rect_vertices

    fn filled_rounded_rect_vertices(x : Double, y : Double, w : Double, h : Double, tl : Double, tr : Double, br : Double, bl : Double, screen_w : Double, screen_h : Double) -> (Array[Double], Array[Int])

    Generate NDC vertices for a filled rounded rectangle. Each corner is approximated with segments triangle-fan triangles.

    measure_text

    fn measure_text(text_renderer :
    TextRenderer
    , text : String, size_px : Double) ->
    TextMetrics

    Measure text dimensions without rendering.

    render_text

    fn render_text(text_renderer :
    TextRenderer
    , text : String, size_px : Double, x : Double, y : Double, dst :
    ImageHandle
    , shader :
    ShaderHandle
    , color_hex : Int, screen_w : Double, screen_h : Double) -> Array[
    DrawTrianglesCommand
    ]

    Render text at pixel coordinates using a TextRenderer. Converts pixel-space vertices to NDC for the builtin shader.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io