Skip to main content

Style

Struct Style 

Source
pub struct Style<'a, R: Renderer> {
    theme: &'a Theme,
    inner: &'a mut R,
    opacity: f32,
}
Expand description

Theme-aware drawing surface: a &Theme paired with a &mut renderer backend. See the module docs.

Fields§

§theme: &'a Theme§inner: &'a mut R§opacity: f32

Dims every color resolved through this Style. 1.0 unless the draw is inside a Style::with_opacity run.

Implementations§

Source§

impl<'a, R: Renderer> Style<'a, R>

Source

pub fn new(theme: &'a Theme, inner: &'a mut R) -> Self

Source

pub fn theme(&self) -> &Theme

The active theme — used by the render path for fonts.

Source

pub fn renderer(&self) -> &R

The backend underneath, for a pass that needs to measure through it while drawing somewhere else (see Extent).

Source

fn swatch(&self, role: Role) -> Swatch

Source

fn pstroke(&self, stroke: impl Into<RoleStroke>) -> PaletteStroke

Source

pub fn rect( &self, rect: Rect, rounding: WorldPx, fill: Role, stroke: impl Into<RoleStroke>, )

Source

pub fn line(&self, points: Vec<Pos2>, stroke: impl Into<RoleStroke>)

Source

pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<RoleStroke>)

Source

pub fn circle( &self, center: Pos2, radius: WorldPx, fill: Role, stroke: impl Into<RoleStroke>, )

Source

pub fn circle_filled(&self, center: Pos2, radius: WorldPx, fill: Role)

Source

pub fn add_convex_polygon( &self, points: Vec<Pos2>, fill: Role, stroke: impl Into<RoleStroke>, )

Source

pub fn text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: Role, ) -> Rect

Source

pub fn rotated_text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: Role, angle: Angle, )

Source

pub fn text_wrapped( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: Role, max_width: WorldPx, ) -> Rect

Source

pub fn text_size(&self, text: impl ToString, font: &Font) -> Vec2

Source

pub fn text_size_wrapped( &self, text: impl ToString, font: &Font, max_width: WorldPx, ) -> Vec2

Source

pub fn text_layout(&self, text: &str, font: &Font, max_width: WorldPx) -> Layout

Source

pub fn draw_image(&self, rect: Rect, image: &Asset)

Source

pub fn image_intrinsic_size(&self, image: &Asset) -> Option<Vec2>

Source

pub fn animator(&self) -> Option<&dyn Animator>

The frame animation behind this backend, or None offline. See Renderer::animator.

Source

pub fn visible_world_bounds(&self) -> Option<Rect>

The visible world-space rect for viewport culling, or None on backends with no viewport (SVG export). See Renderer::visible_world_bounds.

Source

pub fn with_opacity<T>( &mut self, factor: f32, draw: impl FnOnce(&mut Style<'_, R>) -> T, ) -> T

Draw a faded run: draw receives a Style whose colors are dimmed by factor (composing with each role’s own alpha). The fade is a swatch transform applied where roles resolve, so no backend holds fade state and every backend fades identically. Nestable — a nested run multiplies the factors. Used for ghost/dimmed previews and faint overlays.

Source§

impl<C: Canvas> Style<'_, C>

Live-canvas conveniences: when the backend is a Canvas, a tool reaches the cursor, the in-place editor, the pointer, the keyed easings and the repaint schedule straight through the Style it already holds.

Source

pub fn set_edit_text(&mut self, edit: EditText)

Source

pub fn set_cursor(&mut self, cursor: Cursor)

Source

pub fn cursor(&self) -> Option<Cursor>

Source

pub fn pointer_world(&self) -> Option<Pos2>

The pointer in world space. See Animator::pointer_world.

Source

pub fn remap_rect(&self, rect: Rect) -> Rect

World-space rect → screen-space rect, for placing screen-space overlays (e.g. the selection bar) relative to a selection’s on-canvas bounds.

Source

pub fn animate(&self, key: AnimKey, goal: f32, over: Duration) -> f32

The current value of the easing keyed by key. See Animator::animate.

Source

pub fn request_repaint(&self)

Source

pub fn request_repaint_after(&self, after: Duration)

Source

pub fn now(&self) -> Duration

The frame clock. See Canvas::now.

Source

pub fn pointer_kind(&self) -> PointerKind

Auto Trait Implementations§

§

impl<'a, R> Freeze for Style<'a, R>

§

impl<'a, R> RefUnwindSafe for Style<'a, R>
where R: RefUnwindSafe,

§

impl<'a, R> Send for Style<'a, R>
where R: Send,

§

impl<'a, R> Sync for Style<'a, R>
where R: Sync,

§

impl<'a, R> Unpin for Style<'a, R>

§

impl<'a, R> UnsafeUnpin for Style<'a, R>

§

impl<'a, R> !UnwindSafe for Style<'a, R>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more