snap text on shader

This commit is contained in:
2025-08-23 22:16:00 -04:00
parent 5ce6fca275
commit 50ccf7393d
10 changed files with 101 additions and 64 deletions

View File

@@ -2,16 +2,33 @@ use crate::prelude::*;
pub struct Text {
content: String,
attrs: TextAttrs,
}
impl Text {
pub fn size(mut self, size: impl UiNum) -> Self {
self.attrs.size = size.to_f32();
self
}
pub fn color(mut self, color: UiColor) -> Self {
self.attrs.color = color;
self
}
pub fn line_height(mut self, height: f32) -> Self {
self.attrs.line_height = height;
self
}
}
impl<Ctx> Widget<Ctx> for Text {
fn draw(&self, painter: &mut Painter<Ctx>) {
painter.draw_text(&self.content);
painter.draw_text(&self.content, &self.attrs);
}
}
pub fn text(text: impl Into<String>) -> Text {
Text {
content: text.into(),
attrs: TextAttrs::default(),
}
}