pub struct Text {
pub color: [f64; 3],
/* private fields */
}Expand description
A text member — a port of lib3’s Text. See the module doc for how this
differs from the JS Object3D subclass it ports.
Fields§
§color: [f64; 3]Member colour, linear, default white. See the module doc.
Implementations§
Source§impl Text
impl Text
Sourcepub fn new() -> Self
pub fn new() -> Self
new Text() — every layout property at its LAYOUT_DEFAULTS value, and
_needsSync = true, so the first sync always lays out.
Sourcepub fn set_text(&mut self, value: impl Into<String>)
pub fn set_text(&mut self, value: impl Into<String>)
Sets the string to lay out — text.text = value.
Sourcepub fn set_font_size(&mut self, value: f64)
pub fn set_font_size(&mut self, value: f64)
Sets the font size — text.fontSize = value.
Sourcepub fn font_family(&self) -> &str
pub fn font_family(&self) -> &str
CSS font family. Canvas layout only; vector layout never reads it.
Sourcepub fn set_font_family(&mut self, value: impl Into<String>)
pub fn set_font_family(&mut self, value: impl Into<String>)
Sets the CSS font family — text.fontFamily = value.
Sourcepub fn font_weight(&self) -> &str
pub fn font_weight(&self) -> &str
CSS font weight. Canvas layout only.
Sourcepub fn set_font_weight(&mut self, value: impl Into<String>)
pub fn set_font_weight(&mut self, value: impl Into<String>)
Sets the CSS font weight — text.fontWeight = value.
Sourcepub fn font_style(&self) -> &str
pub fn font_style(&self) -> &str
CSS font style. Canvas layout only.
Sourcepub fn set_font_style(&mut self, value: impl Into<String>)
pub fn set_font_style(&mut self, value: impl Into<String>)
Sets the CSS font style — text.fontStyle = value.
Sourcepub fn letter_spacing(&self) -> f64
pub fn letter_spacing(&self) -> f64
Extra space added per glyph. See the module’s asymmetric-spacing note.
Sourcepub fn set_letter_spacing(&mut self, value: f64)
pub fn set_letter_spacing(&mut self, value: f64)
Sets the letter spacing — text.letterSpacing = value.
Sourcepub fn line_height(&self) -> LineHeight
pub fn line_height(&self) -> LineHeight
Line height, as LineHeight.
Sourcepub fn set_line_height(&mut self, value: LineHeight)
pub fn set_line_height(&mut self, value: LineHeight)
Sets the line height — text.lineHeight = value.
Sourcepub fn set_anchor_x(&mut self, value: Anchor)
pub fn set_anchor_x(&mut self, value: Anchor)
Sets the horizontal anchor — text.anchorX = value.
Sourcepub fn set_anchor_y(&mut self, value: Anchor)
pub fn set_anchor_y(&mut self, value: Anchor)
Sets the vertical anchor — text.anchorY = value.
Sourcepub fn text_align(&self) -> TextAlign
pub fn text_align(&self) -> TextAlign
Multi-line alignment.
Sourcepub fn set_text_align(&mut self, value: TextAlign)
pub fn set_text_align(&mut self, value: TextAlign)
Sets the text alignment — text.textAlign = value.
Sourcepub fn max_width(&self) -> f64
pub fn max_width(&self) -> f64
Line-wrap width, world units. f64::INFINITY by default (no wrap).
Sourcepub fn set_max_width(&mut self, value: f64)
pub fn set_max_width(&mut self, value: f64)
Sets the line-wrap width — text.maxWidth = value.
Sourcepub fn text_render_info(&self) -> Option<&TextRenderInfo>
pub fn text_render_info(&self) -> Option<&TextRenderInfo>
The most recent layout, or None before the first Text::sync.
Sourcepub fn set_opacity(&mut self, value: f64)
pub fn set_opacity(&mut self, value: f64)
Does not trigger re-layout; writes through to the owning batch’s per-glyph opacity attribute when batched.
Sourcepub fn member_id(&self) -> Option<usize>
pub fn member_id(&self) -> Option<usize>
None when the member has not joined a batch (-1 in the JS).
Sourcepub fn set_vector_mode(&mut self, on: bool)
pub fn set_vector_mode(&mut self, on: bool)
_vectorMode / _vectorFont. Passing None for the font while the mode
is on is the “still loading” state sync has a branch for.
Sourcepub fn vector_mode(&self) -> bool
pub fn vector_mode(&self) -> bool
Whether vector-outline layout is on.
Sourcepub fn set_vector_font(&mut self, font: Option<Rc<VectorFont>>)
pub fn set_vector_font(&mut self, font: Option<Rc<VectorFont>>)
_vectorFont, set by the owning BatchedText.
Sourcepub fn sync(&mut self) -> &TextRenderInfo
pub fn sync(&mut self) -> &TextRenderInfo
sync(callback, renderer) — lay out the glyphs, unless a cached layout is
still valid.
The callback is a JS idiom for “the layout may be asynchronous”; it never is, so it is dropped. The renderer argument was already unused in the JS.
Note the vector-mode-without-a-font branch: it installs an empty layout
and returns without clearing the dirty flag, so the next sync after
the font arrives re-lays out. It also does not touch
layouts_performed, because no layout happened.