Skip to main content

Graphics

Struct Graphics 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn pop_clip_rect(&mut self)

Restores the previous widget-local clip rectangle.

Source

pub fn with_clip<F: FnOnce(&mut Self)>(&mut self, rect: Recti, f: F)

Executes f with an additional widget-local clip applied.

Source

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.

Source

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.

Source

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.

Source

pub fn draw_icon(&mut self, id: IconId, rect: Recti, color: Color)

Draws one icon rectangle using widget-local coordinates.

Source

pub fn draw_image(&mut self, image: Image, rect: Recti, color: Color)

Draws one image rectangle using widget-local coordinates.

Source

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.

Source

pub fn draw_frame(&mut self, rect: Recti, colorid: ControlColor)

Draws one framed control using the current style colors.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a, 'b> Drop for Graphics<'a, 'b>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for Graphics<'a, 'b>

§

impl<'a, 'b> !RefUnwindSafe for Graphics<'a, 'b>

§

impl<'a, 'b> !Send for Graphics<'a, 'b>

§

impl<'a, 'b> !Sync for Graphics<'a, 'b>

§

impl<'a, 'b> Unpin for Graphics<'a, 'b>

§

impl<'a, 'b> UnsafeUnpin for Graphics<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for Graphics<'a, 'b>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.