pub struct PaddingTween { /* private fields */ }Expand description
Implementations§
Methods from Deref<Target = Shape>§
Sourcepub fn child(&self, c: impl Into<Shape>) -> Shape
pub fn child(&self, c: impl Into<Shape>) -> Shape
Adds a child shape. Accepts both Shape and property handles
(Tween, PaddingTween) — they dereference into a shape.
Sourcepub fn children<C>(&self, cs: C) -> Shapewhere
C: IntoChildren,
pub fn children<C>(&self, cs: C) -> Shapewhere
C: IntoChildren,
Adds child shapes. Thanks to IntoChildren it accepts both one
nested shape (including the property handles Tween/PaddingTween)
and a collection/iterator of any Into<Shape> — so it suits both
nesting one ready-made group into another and adding a list:
let group = Shape::rect().children(vec![Shape::circle().size(8.0, 8.0)]);
// Nest a ready-made group as the single child:
let window = Shape::rect().children(group);Sourcepub fn on(&self, tl: &Timeline) -> Shape
pub fn on(&self, tl: &Timeline) -> Shape
Registers the shape on the timeline tl for drawing and returns it,
to stay in the fluent chain. Since a shape is an Rc, the timeline holds
only a reference, and properties can still be animated and read.
At the same time the whole subgraph (the shape itself and all its
children at the moment of the call) remembers this timeline, so an
animation built from any of them can be added by simply writing it as an
expression — without [sequence]/[parallel]:
let tl = Timeline::new(320, 160, Color::BLACK, 30.0);
let box_ = Shape::rect().size(40.0, 40.0).on(&tl);
// A single animation appends itself to the end of the timeline:
box_.x(200.0).over(1.0, Easing::CubicInOut);
// Several simultaneous ones — still via parallel:
tl.parallel(vec![box_.y(40.0).over(1.0, Easing::CubicInOut)]);Sourcepub fn x(&self, value: f32) -> Tween<f32>
pub fn x(&self, value: f32) -> Tween<f32>
X coordinate. x(100.0) sets it immediately;
x(100.0).over(1.0, Easing::CubicInOut) animates.
Sourcepub fn width(&self, value: Length) -> Tween<f32>
pub fn width(&self, value: Length) -> Tween<f32>
Width — as a Length value: pixels (Length::pixel, <= 0 — “auto”)
or a fraction of the parent’s content area (Length::percent,
Length::percent(100.0) — 100%). A pixel width can be animated via
over (see x), and it cancels any previously
set fraction; a fraction, on the other hand, is set instantly (not
animated), resolved on the second layout pass relative to the parent and
overrides the pixel width (clamped by
min_width/max_width).
Sourcepub fn max_width(&self, value: f32) -> Tween<f32>
pub fn max_width(&self, value: f32) -> Tween<f32>
Upper bound of the width (<= 0 — no limit): the final width does not
exceed it. Animatable. See min_width.
Sourcepub fn min_height(&self, value: f32) -> Tween<f32>
pub fn min_height(&self, value: f32) -> Tween<f32>
Lower bound of the height (<= 0 — no limit). Animatable. See
min_width.
Sourcepub fn max_height(&self, value: f32) -> Tween<f32>
pub fn max_height(&self, value: f32) -> Tween<f32>
Upper bound of the height (<= 0 — no limit). Animatable. See
min_width.
Sourcepub fn opacity(&self, value: f32) -> Tween<f32>
pub fn opacity(&self, value: f32) -> Tween<f32>
Opacity 0..=1 (multiplied by the parent’s opacity). See
x.
Sourcepub fn scale(&self, value: f32) -> Tween<f32>
pub fn scale(&self, value: f32) -> Tween<f32>
Scale around the center (1.0 — no change). Applies to the whole
subtree, like rotation. See x.
Sourcepub fn padding<P>(&self, value: P) -> PaddingTween
pub fn padding<P>(&self, value: P) -> PaddingTween
Inner padding. Accepts the CSS-like shorthands Padding:
padding(16.0)— the same on all sides;padding((10.0, 20.0))—(vertical, horizontal);padding((5.0, 10.0, 15.0, 20.0))—(top, right, bottom, left).
Sets the padding immediately and returns a PaddingTween: append
over to animate it, e.g.
padding(24.0).over(1.0, Easing::CubicInOut).
Sourcepub fn content(&self, content: impl Into<String>) -> TextEdit
pub fn content(&self, content: impl Into<String>) -> TextEdit
Fully replaces the text content with new content. Lines are separated by
\n.
Sets the text immediately and returns a TextEdit: append
spawn / typing /
smooth to animate the change on the timeline.
Panics if called on a non-text shape (see Shape::text).
Sourcepub fn rewrite(
&self,
from: impl Into<TextPos>,
to: impl Into<TextPos>,
content: impl Into<String>,
) -> TextEdit
pub fn rewrite( &self, from: impl Into<TextPos>, to: impl Into<TextPos>, content: impl Into<String>, ) -> TextEdit
Replaces the content of the half-open range [from, to) with content.
The bounds are TextPos: a bare character index (0-based, via
Into<TextPos>), the start of a line line(n) or the end
of the text infinite() (for to). The range is
half-open: the character at position to is not included in the
replacement.
// "foo\nbar" → replace the whole first line (with its `\n`) with "X":
let t = Shape::text("foo\nbar").rewrite(0, line(1), "X");Returns a TextEdit (see content). Panics if called
on a non-text shape.
Sourcepub fn font(&self, bytes: impl Into<Rc<Vec<u8>>>) -> Shape
pub fn font(&self, bytes: impl Into<Rc<Vec<u8>>>) -> Shape
Sets the font from the bytes of a .ttf/.otf file (CSS font-family).
Accepts a Vec<u8> or a shared Rc<Vec<u8>> — the latter
is handy for sharing one font across several texts without copying the
bytes.
Panics if called on a non-text shape.
Sourcepub fn font_collection(
&self,
bytes: impl Into<Rc<Vec<u8>>>,
index: u32,
) -> Shape
pub fn font_collection( &self, bytes: impl Into<Rc<Vec<u8>>>, index: u32, ) -> Shape
Sets the font from the bytes of a collection (.ttc), selecting the face
by index. For a regular single-font file use font.
Panics if called on a non-text shape.
Sourcepub fn text_align(&self, align: TextAlign) -> Shape
pub fn text_align(&self, align: TextAlign) -> Shape
Alignment of lines within the block (CSS text-align).
Panics if called on a non-text shape.
Sourcepub fn font_size(&self, value: f32) -> Tween<f32>
pub fn font_size(&self, value: f32) -> Tween<f32>
Font size in pixels (CSS font-size). Animatable. See x.
Panics if called on a non-text shape.
Sourcepub fn palette(&self, palette: Palette) -> Shape
pub fn palette(&self, palette: Palette) -> Shape
The code shape’s highlight palette (see Palette). Set instantly and
returns the shape itself to continue the chain.
Panics if called on a non-code shape (see Shape::code).
Sourcepub fn language(&self, language: Language) -> Shape
pub fn language(&self, language: Language) -> Shape
The code shape’s highlight language (see Language). Set instantly and
returns the shape itself.
Panics if called on a non-code shape (see Shape::code).
Sourcepub fn letter_spacing(&self, value: f32) -> Tween<f32>
pub fn letter_spacing(&self, value: f32) -> Tween<f32>
Letter spacing — extra gap between characters in pixels (CSS
letter-spacing). Animatable. See x.
Panics if called on a non-text shape.
Sourcepub fn line_height(&self, value: f32) -> Tween<f32>
pub fn line_height(&self, value: f32) -> Tween<f32>
Line spacing as a multiplier of the font’s natural line height (CSS
line-height, 1.0 — no change). Animatable. See x.
Panics if called on a non-text shape.
Sourcepub fn highlight(
&self,
from: impl Into<TextPos>,
to: impl Into<TextPos>,
) -> HighlightEdit
pub fn highlight( &self, from: impl Into<TextPos>, to: impl Into<TextPos>, ) -> HighlightEdit
Marks the highlighted character range [from, to) and returns a
HighlightEdit — this is a timeline animation, not a static
property. Highlighted glyphs are drawn at full strength, the rest are
dimmed.
Append over to highlight smoothly over a given
time; without it the edit is applied immediately. Unlike .selection in
Motion Canvas, there can be any number of ranges — highlight each with its
own highlight(..).over(..) in a single parallel:
they merge into one consistent transition. The highlighting is removed
with clear_highlight.
The bounds are TextPos: a bare character index (0-based, via
Into<TextPos>), the start of a line line(n) or the end
of the text infinite(). The range is half-open: the
character at position to is not highlighted.
let tl = Timeline::new(320, 120, Color::BLACK, 30.0);
let code = Shape::code("let answer = 42;").on(&tl);
// Highlight "42" over half a second, dimming the rest:
code.highlight(13, 15).over(0.5, Easing::CubicInOut);Works on both text and code (colors are preserved, only opacity changes).
Panics if called on a non-text shape (see Shape::text).
Sourcepub fn clear_highlight(&self) -> HighlightEdit
pub fn clear_highlight(&self) -> HighlightEdit
Removes the highlighting (see highlight): returns a
HighlightEdit whose over smoothly returns the
whole text to full strength; without over the highlighting is removed
immediately.
Panics if called on a non-text shape.
Sourcepub fn font_size_signal(&self) -> Signal<f32>
pub fn font_size_signal(&self) -> Signal<f32>
The font-size signal. Panics if called on a non-text shape.
Sourcepub fn color_signal(&self) -> Signal<Color>
pub fn color_signal(&self) -> Signal<Color>
The text-color signal. Panics if called on a non-text shape.
Sourcepub fn letter_spacing_signal(&self) -> Signal<f32>
pub fn letter_spacing_signal(&self) -> Signal<f32>
The letter-spacing signal. Panics if called on a non-text shape.
Sourcepub fn line_height_signal(&self) -> Signal<f32>
pub fn line_height_signal(&self) -> Signal<f32>
The line-height signal. Panics if called on a non-text shape.
Sourcepub fn width_signal(&self) -> Signal<f32>
pub fn width_signal(&self) -> Signal<f32>
The width signal.
Sourcepub fn height_signal(&self) -> Signal<f32>
pub fn height_signal(&self) -> Signal<f32>
The height signal.
Sourcepub fn min_width_signal(&self) -> Signal<f32>
pub fn min_width_signal(&self) -> Signal<f32>
The width lower-bound signal.
Sourcepub fn max_width_signal(&self) -> Signal<f32>
pub fn max_width_signal(&self) -> Signal<f32>
The width upper-bound signal.
Sourcepub fn min_height_signal(&self) -> Signal<f32>
pub fn min_height_signal(&self) -> Signal<f32>
The height lower-bound signal.
Sourcepub fn max_height_signal(&self) -> Signal<f32>
pub fn max_height_signal(&self) -> Signal<f32>
The height upper-bound signal.
Sourcepub fn background_signal(&self) -> Signal<Color>
pub fn background_signal(&self) -> Signal<Color>
The background-color signal.
Sourcepub fn radius_signal(&self) -> Signal<f32>
pub fn radius_signal(&self) -> Signal<f32>
The corner-radius signal.
Sourcepub fn opacity_signal(&self) -> Signal<f32>
pub fn opacity_signal(&self) -> Signal<f32>
The opacity signal.
Sourcepub fn rotation_signal(&self) -> Signal<f32>
pub fn rotation_signal(&self) -> Signal<f32>
The rotation signal (degrees).
Sourcepub fn scale_signal(&self) -> Signal<f32>
pub fn scale_signal(&self) -> Signal<f32>
The scale signal.
Sourcepub fn gap_signal(&self) -> Signal<f32>
pub fn gap_signal(&self) -> Signal<f32>
The child-gap signal.
Sourcepub fn pad_top_signal(&self) -> Signal<f32>
pub fn pad_top_signal(&self) -> Signal<f32>
The top inner-padding signal.
Sourcepub fn pad_right_signal(&self) -> Signal<f32>
pub fn pad_right_signal(&self) -> Signal<f32>
The right inner-padding signal.
Sourcepub fn pad_bottom_signal(&self) -> Signal<f32>
pub fn pad_bottom_signal(&self) -> Signal<f32>
The bottom inner-padding signal.
Sourcepub fn pad_left_signal(&self) -> Signal<f32>
pub fn pad_left_signal(&self) -> Signal<f32>
The left inner-padding signal.