pub struct Graphics<'a, 'b> { /* private fields */ }Expand description
Widget-local 2D geometry builder.
Coordinates passed to this builder are local to the widget rectangle that created it:
(0, 0) is the widget’s top-left corner, while (width, height) is the bottom-right corner.
Nested clips are also widget-local and are pushed onto the shared draw-context clip stack after
being translated into screen space, so a widget-local clip can only reduce visibility and can
never expand beyond the area the widget already owns.
The builder tessellates higher-level shapes into triangles immediately and software-clips every triangle against the current widget-local clip rectangle before storing it. Because the emitted triangles are already clipped, nested local clip scopes do not need to flush the batch or emit retained clip commands.
Implementations§
Source§impl<'a, 'b> Graphics<'a, 'b>
impl<'a, 'b> Graphics<'a, 'b>
Sourcepub fn local_rect(&self) -> Recti
pub fn local_rect(&self) -> Recti
Returns the widget-local rectangle available to this graphics builder.
This is the widget’s full layout rect expressed in local coordinates, regardless of parent
clipping. Use Graphics::current_clip_rect when the visible area matters.
Sourcepub fn current_clip_rect(&self) -> Recti
pub fn current_clip_rect(&self) -> Recti
Returns the current widget-local clip rectangle.
The returned rect is derived from the shared draw-context clip stack. It is therefore already intersected with the widget root and all earlier local clip scopes.
Sourcepub fn push_clip_rect(&mut self, rect: Recti)
pub fn push_clip_rect(&mut self, rect: Recti)
Narrows the current clip by intersecting it with rect.
The clip is expressed in widget-local coordinates, translated into screen space, and pushed
onto the shared draw-context stack. Because DrawCtx::push_clip_rect intersects against
the current top, this can never expand the visible area.
Sourcepub fn set_clip_rect(&mut self, rect: Recti)
pub fn set_clip_rect(&mut self, rect: Recti)
Replaces the current clip with an intersection against rect.
Unlike push_clip_rect, this keeps the current stack depth. The replacement is still
monotonic: it intersects with the existing top clip instead of replacing it wholesale.
Sourcepub fn pop_clip_rect(&mut self)
pub fn pop_clip_rect(&mut self)
Restores the previous widget-local clip rectangle.
Sourcepub fn with_clip<F: FnOnce(&mut Self)>(&mut self, rect: Recti, f: F)
pub fn with_clip<F: FnOnce(&mut Self)>(&mut self, rect: Recti, f: F)
Executes f with an additional widget-local clip applied.
Sourcepub fn draw_rect(&mut self, rect: Recti, color: Color)
pub fn draw_rect(&mut self, rect: Recti, color: Color)
Fills a solid axis-aligned rectangle in widget-local coordinates.
Rectangles are routed through the same triangle path as every other filled primitive so the widget paint stack only has one geometry implementation to maintain.
Sourcepub fn draw_box(&mut self, rect: Recti, color: Color)
pub fn draw_box(&mut self, rect: Recti, color: Color)
Draws a 1-pixel outline around rect.
The outline is decomposed into four filled edge rectangles so it stays on the same clipped triangle path as every other solid primitive.
Sourcepub fn draw_text(&mut self, font: FontId, text: &str, pos: Vec2i, color: Color)
pub fn draw_text(&mut self, font: FontId, text: &str, pos: Vec2i, color: Color)
Draws text using widget-local coordinates for the glyph origin.
Text itself still reuses the existing retained text command, but the graphics builder owns the local-to-screen translation and the clip-state wrapping so widgets no longer have to decide which paint API to use.
Sourcepub fn draw_icon(&mut self, id: IconId, rect: Recti, color: Color)
pub fn draw_icon(&mut self, id: IconId, rect: Recti, color: Color)
Draws one icon rectangle using widget-local coordinates.
Sourcepub fn draw_image(&mut self, image: Image, rect: Recti, color: Color)
pub fn draw_image(&mut self, image: Image, rect: Recti, color: Color)
Draws one image rectangle using widget-local coordinates.
Sourcepub fn draw_slot_with_function(
&mut self,
id: SlotId,
rect: Recti,
color: Color,
payload: Rc<dyn Fn(usize, usize) -> Color4b>,
)
pub fn draw_slot_with_function( &mut self, id: SlotId, rect: Recti, color: Color, payload: Rc<dyn Fn(usize, usize) -> Color4b>, )
Re-renders a slot and then draws it using widget-local coordinates.
Sourcepub fn draw_frame(&mut self, rect: Recti, colorid: ControlColor)
pub fn draw_frame(&mut self, rect: Recti, colorid: ControlColor)
Draws one framed control using the current style colors.
Sourcepub fn draw_widget_frame(
&mut self,
focused: bool,
hovered: bool,
rect: Recti,
colorid: ControlColor,
opt: WidgetOption,
)
pub fn draw_widget_frame( &mut self, focused: bool, hovered: bool, rect: Recti, colorid: ControlColor, opt: WidgetOption, )
Draws one widget frame using the same focus/hover color promotion as the legacy widget helpers.
Sourcepub fn draw_control_text(
&mut self,
text: &str,
rect: Recti,
colorid: ControlColor,
opt: WidgetOption,
)
pub fn draw_control_text( &mut self, text: &str, rect: Recti, colorid: ControlColor, opt: WidgetOption, )
Draws centered or aligned control text inside rect.
This reuses the shared control-text positioning helper from DrawCtx so widget and
container labels stay visually identical even though widgets now paint through Graphics.
Sourcepub fn draw_control_text_with_font(
&mut self,
font: FontId,
text: &str,
rect: Recti,
colorid: ControlColor,
opt: WidgetOption,
)
pub fn draw_control_text_with_font( &mut self, font: FontId, text: &str, rect: Recti, colorid: ControlColor, opt: WidgetOption, )
Draws centered or aligned control text using an explicit font.
Sourcepub fn stroke_line(&mut self, a: Vec2f, b: Vec2f, width: f32, color: Color)
pub fn stroke_line(&mut self, a: Vec2f, b: Vec2f, width: f32, color: Color)
Strokes one solid line segment with the provided width.
The stroke is tessellated into two triangles instead of relying on platform line primitives. That keeps behavior predictable across backends and makes rectangular clipping behave the same way as filled polygon rendering.
Sourcepub fn fill_polygon(&mut self, points: &[Vec2f], color: Color)
pub fn fill_polygon(&mut self, points: &[Vec2f], color: Color)
Fills a simple polygon described in widget-local coordinates.
Convex polygons take the fast triangle-fan path. Concave simple polygons fall back to a compact ear-clipping triangulator implemented here to avoid pulling a heavier dependency into the core crate. Self-intersecting polygons are intentionally unsupported.