pub struct DrawText {
pub pos: [f32; 2],
pub color: Color,
pub decoration: TextDecoration,
pub layout: Arc<PreparedTextLayout>,
}Expand description
Prepared shaped text positioned by its first baseline.
The shared layout keeps source text, glyphs, and line metrics alive. Color is the uniform paint color; styled layouts may additionally carry per-glyph colors. All positions and metrics are logical pixels.
§Examples
use std::sync::Arc;
use ailloli_ui_core::{Color, FontId, TextDecoration, TextStyle};
use ailloli_ui_runtime::scene::DrawText;
use ailloli_ui_text::{TextLayoutParams, TextSystem};
let mut system = TextSystem::new();
let layout = system.layout_cached(TextLayoutParams::new(
"hello", TextStyle::new(FontId::Ui, 14, Color::WHITE),
));
let draw = DrawText { pos: [5.0, 20.0], color: Color::WHITE,
decoration: TextDecoration::None, layout };
assert_eq!(draw.layout.text(), "hello");Fields§
§pos: [f32; 2][x, first_baseline_y] in window-space logical pixels.
color: ColorUniform linear-RGBA paint color.
decoration: TextDecorationRequested paint-only text decoration.
layout: Arc<PreparedTextLayout>Shared, renderer-ready shaped layout.
Implementations§
Source§impl DrawText
Provides the operations defined for DrawText.
impl DrawText
Provides the operations defined for DrawText.
Sourcepub fn decoration_rects(&self, dpr: f32) -> Vec<Rect>
pub fn decoration_rects(&self, dpr: f32) -> Vec<Rect>
Returns logical-pixel underline rectangles for non-empty visual lines.
Decorations other than underline return an empty vector. dpr is
clamped to at least 0.01 using floating-point max; NaN therefore also
becomes 0.01, while positive infinity can yield non-finite snapped
coordinates. Each underline is at least one physical pixel thick, uses
the line width, and is vertically snapped to the effective DPR.
§Examples
use ailloli_ui_core::{Color, FontId, TextDecoration, TextStyle};
use ailloli_ui_runtime::scene::DrawText;
use ailloli_ui_text::{TextLayoutParams, TextSystem};
let mut system = TextSystem::new();
let layout = system.layout_cached(TextLayoutParams::new(
"underlined", TextStyle::new(FontId::Ui, 14, Color::WHITE),
));
let draw = DrawText { pos: [0.0, layout.lines[0].baseline_y], color: Color::WHITE,
decoration: TextDecoration::Underline, layout };
assert_eq!(draw.decoration_rects(2.0).len(), 1);
assert!(draw.decoration_rects(2.0)[0].h >= 0.5);Trait Implementations§
Auto Trait Implementations§
impl Freeze for DrawText
impl !RefUnwindSafe for DrawText
impl Send for DrawText
impl Sync for DrawText
impl Unpin for DrawText
impl !UnwindSafe for DrawText
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
Source§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.