diff --git a/src/core/text/build.rs b/src/core/text/build.rs index 4d5a32e..3611918 100644 --- a/src/core/text/build.rs +++ b/src/core/text/build.rs @@ -1,6 +1,6 @@ -use std::marker::{PhantomData, Sized}; use crate::prelude::*; use cosmic_text::{Attrs, Family, Metrics}; +use std::marker::{PhantomData, Sized}; pub struct TextBuilder { pub content: String, diff --git a/src/core/text/edit.rs b/src/core/text/edit.rs index d9ecc19..dc25e0b 100644 --- a/src/core/text/edit.rs +++ b/src/core/text/edit.rs @@ -14,13 +14,6 @@ pub struct TextEdit { } impl TextEdit { - pub fn region(&self) -> UiRegion { - self.tex() - .map(|t| t.size) - .unwrap_or(Vec2::ZERO) - .align(self.align) - } - pub fn select_content(&self, start: Cursor, end: Cursor) -> String { let (start, end) = sort_cursors(start, end); let mut iter = self.buf.lines.iter().skip(start.line); diff --git a/src/core/text/mod.rs b/src/core/text/mod.rs index bcd471f..30839a2 100644 --- a/src/core/text/mod.rs +++ b/src/core/text/mod.rs @@ -34,6 +34,23 @@ impl TextView { hint, } } + + pub fn region(&self) -> UiRegion { + self.tex() + .map(|t| t.size) + .unwrap_or(Vec2::ZERO) + .align(self.align) + } + + fn tex_region(&self, tex: &RenderedText) -> UiRegion { + let region = tex.size.align(self.align); + let dims = tex.handle.size(); + let mut region = region.offset(tex.top_left_offset); + region.x.end = region.x.start + UiScalar::abs(dims.x); + region.y.end = region.y.start + UiScalar::abs(dims.y); + region + } + fn render(&mut self, ctx: &mut SizeCtx) -> RenderedText { let width = if self.attrs.wrap { Some(ctx.px_size().x) @@ -68,11 +85,7 @@ impl TextView { } pub fn draw(&mut self, painter: &mut Painter) -> UiRegion { let tex = self.render(&mut painter.size_ctx()); - let region = tex.size.align(self.align); - let dims = tex.handle.size(); - let mut region = region.offset(tex.top_left_offset); - region.x.end = region.x.start + UiScalar::abs(dims.x); - region.y.end = region.y.start + UiScalar::abs(dims.y); + let region = self.tex_region(&tex); if let Some(hint) = &self.hint && let [line] = &self.buf.lines[..] && line.text().is_empty() diff --git a/src/layout/text.rs b/src/layout/text.rs index 0998407..424a221 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -35,7 +35,7 @@ pub struct TextAttrs { pub line_height: f32, pub family: Family<'static>, pub wrap: bool, - /// inner alignment of text region (within where its drawn) + /// inner alignment of text region (within where it's drawn) pub align: RegionAlign, }