Skip to content

Add canvas_rounded_rect drawing primitive #19

@niklabh

Description

@niklabh

Description

The canvas API currently supports canvas_rect, canvas_circle, canvas_line, and canvas_text — but there's no way to draw a rounded rectangle. This is one of the most commonly needed primitives for building UIs (cards, buttons, panels).

This is listed in the roadmap under Phase 2 (GPU & Graphics).

What to implement

Host side (oxide-browser)

  1. capabilities.rs: Register a new host function api_canvas_rounded_rect with parameters:

    • x, y, w, h (f32) — position and size
    • r, g, b, a (u32) — fill color
    • radius (f32) — corner radius
  2. ui.rs: Add a new DrawCommand::RoundedRect variant and handle it in the canvas painter using egui's Rounding support (painter.rect_filled already supports Rounding)

SDK side (oxide-sdk)

  1. oxide-sdk/src/lib.rs: Add the FFI import and a safe wrapper:
    pub fn canvas_rounded_rect(x: f32, y: f32, w: f32, h: f32, radius: f32, r: u8, g: u8, b: u8, a: u8) { ... }

Docs

  1. Update DOCS.md with the new function in the Canvas API table

References

  • See existing canvas_rect implementation for the pattern to follow
  • egui supports rounded rects natively: Rect + Rounding

Difficulty

Beginner to Intermediate — follow the existing pattern for canvas_rect. Touches 4 files but the changes are mechanical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions