pub struct TextLabel {Show 16 fields
pub asset_id: AssetId,
pub font: Option<FontHandle>,
pub content: String,
pub x: f32,
pub y: f32,
pub color: [f32; 3],
pub scale: f32,
pub centered: bool,
pub align: TextAlign,
pub fit: SpriteFit,
pub background: [f32; 4],
pub padding: f32,
pub wrap_width: f32,
pub max_lines: u32,
pub visible: bool,
pub screen: Option<AssetId>,
}Expand description
Screen-space text drawn as a UI overlay on top of the 3D scene each frame.
Text is laid out using the referenced Font. A label naming none
draws with the engine’s built-in face at 24px, which costs the build nothing
(the face ships inside the binary) and renders the same whether the world was
compiled or assembled in code. The content field can be updated every frame
(e.g. by an FpsCounter).
A \n in content starts a new line. When background has an alpha > 0, a
box is filled behind the glyphs, extended outward by padding pixels,
useful for HUD chips.
TextLabel {
content: "FPS: --".into(),
x: 10.0,
y: 10.0,
color: [1.0, 1.0, 1.0],
scale: 1.0,
..Default::default()
};Fields§
§asset_id: AssetIdAsset identity; injected via inject_name. Not part of args.
font: Option<FontHandle>The Font asset to use for rendering. Unset draws with the engine’s built-in face at its native 24px.
content: StringText to display. Can be updated each frame.
x: f32Horizontal position in pixels from the left edge of the window.
y: f32Vertical position in pixels from the top edge of the window.
color: [f32; 3]Linear-space RGB text colour.
scale: f32Uniform scale applied on top of the font’s size_px (24 for the
built-in face). 1.0 = native size. Ignored when centered is set, which
sizes the text to the viewport instead.
centered: boolWhen true, fit the label to the viewport and center it there each frame,
so x, y, align and scale are all ignored.
align: TextAlignHorizontal alignment relative to x (measured with the real font
metrics). Ignored when centered is set.
fit: SpriteFitHow a screen-owned label maps from the reference canvas to the window when
their aspect ratios differ (matches Sprite’s fit). Bottom
keeps a label flush with a bottom-anchored sprite it labels.
background: [f32; 4]RGBA fill of a box drawn behind the text. An alpha of 0 (the default) draws no box; any alpha > 0 draws the box at that opacity.
padding: f32Pixels the background box extends past the text on every side. Only
meaningful when background is visible.
wrap_width: f32Width in the label’s own pixels that text wraps within. 0 (the
default) never wraps, so the text runs as far as it needs to. Any
greater value breaks the content into lines at word boundaries, using
the real font metrics, splitting a word only when it cannot fit a line
on its own. Authored newlines are kept as breaks either way. Ignored
when centered is set, since a centered label is sized to the viewport
rather than to a container.
max_lines: u32Most lines the label draws. 0 (the default) draws every line. When the
text needs more than this, the last drawn line ends in an ellipsis, so
text bounded by wrap_width is bounded in both directions and can never
spill out of the box that holds it.
visible: boolWhen false, the label is hidden.
screen: Option<AssetId>Screen this label belongs to. Resolved automatically from
the naming convention (<screen>_*); you don’t set this directly.
None means the label is always visible.
Trait Implementations§
Source§impl Component for TextLabel
impl Component for TextLabel
Source§const NAME: &'static str = "TextLabel"
const NAME: &'static str = "TextLabel"
Source§fn inject_name(&mut self, id: AssetId)
fn inject_name(&mut self, id: AssetId)
Source§fn from_baked(bytes: &[u8]) -> Result<TextLabel, CnResult>
fn from_baked(bytes: &[u8]) -> Result<TextLabel, CnResult>
Source§fn inject_locator(&mut self, _locator: PayloadLocator)
fn inject_locator(&mut self, _locator: PayloadLocator)
Source§impl ComponentSlot for TextLabel
impl ComponentSlot for TextLabel
Source§const DISCRIMINANT: u8
const DISCRIMINANT: u8
ComponentId.Source§impl<'de> Deserialize<'de> for TextLabel
impl<'de> Deserialize<'de> for TextLabel
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<TextLabel, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TextLabel, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<TextLabel> for ComponentAsset
impl From<TextLabel> for ComponentAsset
Source§fn from(c: TextLabel) -> ComponentAsset
fn from(c: TextLabel) -> ComponentAsset
impl RuntimeComponent for TextLabel
Source§impl Serialize for TextLabel
impl Serialize for TextLabel
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for TextLabel
impl RefUnwindSafe for TextLabel
impl Send for TextLabel
impl Sync for TextLabel
impl Unpin for TextLabel
impl UnsafeUnpin for TextLabel
impl UnwindSafe for TextLabel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().