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: f32Dims 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>
impl<'a, R: Renderer> Style<'a, R>
pub fn new(theme: &'a Theme, inner: &'a mut R) -> Self
Sourcepub fn renderer(&self) -> &R
pub fn renderer(&self) -> &R
The backend underneath, for a pass that needs to measure through it
while drawing somewhere else (see Extent).
fn swatch(&self, role: Role) -> Swatch
fn pstroke(&self, stroke: impl Into<RoleStroke>) -> PaletteStroke
pub fn rect( &self, rect: Rect, rounding: WorldPx, fill: Role, stroke: impl Into<RoleStroke>, )
pub fn line(&self, points: Vec<Pos2>, stroke: impl Into<RoleStroke>)
pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<RoleStroke>)
pub fn circle( &self, center: Pos2, radius: WorldPx, fill: Role, stroke: impl Into<RoleStroke>, )
pub fn circle_filled(&self, center: Pos2, radius: WorldPx, fill: Role)
pub fn add_convex_polygon( &self, points: Vec<Pos2>, fill: Role, stroke: impl Into<RoleStroke>, )
pub fn text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: Role, ) -> Rect
pub fn rotated_text( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: Role, angle: Angle, )
pub fn text_wrapped( &self, pos: Pos2, anchor: Align2, text: impl ToString, font: &Font, color: Role, max_width: WorldPx, ) -> Rect
pub fn text_size(&self, text: impl ToString, font: &Font) -> Vec2
pub fn text_size_wrapped( &self, text: impl ToString, font: &Font, max_width: WorldPx, ) -> Vec2
pub fn text_layout(&self, text: &str, font: &Font, max_width: WorldPx) -> Layout
pub fn draw_image(&self, rect: Rect, image: &Asset)
pub fn image_intrinsic_size(&self, image: &Asset) -> Option<Vec2>
Sourcepub fn animator(&self) -> Option<&dyn Animator>
pub fn animator(&self) -> Option<&dyn Animator>
The frame animation behind this backend, or None offline. See
Renderer::animator.
Sourcepub fn visible_world_bounds(&self) -> Option<Rect>
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.
Sourcepub fn with_opacity<T>(
&mut self,
factor: f32,
draw: impl FnOnce(&mut Style<'_, R>) -> T,
) -> T
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.
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.
pub fn set_edit_text(&mut self, edit: EditText)
pub fn set_cursor(&mut self, cursor: Cursor)
pub fn cursor(&self) -> Option<Cursor>
Sourcepub fn pointer_world(&self) -> Option<Pos2>
pub fn pointer_world(&self) -> Option<Pos2>
The pointer in world space. See Animator::pointer_world.
Sourcepub fn remap_rect(&self, rect: Rect) -> Rect
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.
Sourcepub fn animate(&self, key: AnimKey, goal: f32, over: Duration) -> f32
pub fn animate(&self, key: AnimKey, goal: f32, over: Duration) -> f32
The current value of the easing keyed by key. See Animator::animate.
pub fn request_repaint(&self)
pub fn request_repaint_after(&self, after: Duration)
Sourcepub fn now(&self) -> Duration
pub fn now(&self) -> Duration
The frame clock. See Canvas::now.