From d91c0d492724705ae18567724578b60d2bb3c894 Mon Sep 17 00:00:00 2001 From: ifengqi <362254883@qq.com> Date: Thu, 2 Jan 2025 15:22:51 +0800 Subject: [PATCH] make the project more flexible. (#714) * make the project more flexible. * fmt --- renderer/src/text/attrs.rs | 2 +- renderer/src/text/layout.rs | 8 +++++++- renderer/src/text/mod.rs | 2 +- src/lib.rs | 2 +- src/views/editor/mod.rs | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/renderer/src/text/attrs.rs b/renderer/src/text/attrs.rs index 265b2dbc..87c97463 100644 --- a/renderer/src/text/attrs.rs +++ b/renderer/src/text/attrs.rs @@ -183,7 +183,7 @@ impl<'a> Attrs<'a> { } #[derive(PartialEq, Clone)] -pub struct AttrsList(pub(crate) cosmic_text::AttrsList); +pub struct AttrsList(pub cosmic_text::AttrsList); impl AttrsList { /// Create a new attributes list with a set of default [Attrs] diff --git a/renderer/src/text/layout.rs b/renderer/src/text/layout.rs index a7c02d75..4b98e962 100644 --- a/renderer/src/text/layout.rs +++ b/renderer/src/text/layout.rs @@ -91,7 +91,7 @@ impl LayoutRun<'_> { } } - fn cursor_from_glyph_right(&self, glyph: &LayoutGlyph) -> Cursor { + pub fn cursor_from_glyph_right(&self, glyph: &LayoutGlyph) -> Cursor { if self.rtl { Cursor::new_with_affinity(self.line_i, glyph.start, Affinity::After) } else { @@ -221,6 +221,12 @@ impl TextLayout { } } + pub fn new_with_text(text: &str, attrs_list: AttrsList) -> Self { + let mut layout = Self::new(); + layout.set_text(text, attrs_list); + layout + } + pub fn set_text(&mut self, text: &str, attrs_list: AttrsList) { self.buffer.lines.clear(); self.lines_range.clear(); diff --git a/renderer/src/text/mod.rs b/renderer/src/text/mod.rs index 37925a94..73a83079 100644 --- a/renderer/src/text/mod.rs +++ b/renderer/src/text/mod.rs @@ -6,4 +6,4 @@ pub use cosmic_text::{ fontdb, CacheKey, Cursor, Family, LayoutGlyph, LayoutLine, Stretch, Style, SubpixelBin, SwashCache, SwashContent, Weight, Wrap, }; -pub use layout::{HitPoint, HitPosition, TextLayout, FONT_SYSTEM}; +pub use layout::{HitPoint, HitPosition, LayoutRun, TextLayout, FONT_SYSTEM}; diff --git a/src/lib.rs b/src/lib.rs index 30d0c3d4..bba0924e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,7 +220,7 @@ pub use app_state::AppState; pub use clipboard::{Clipboard, ClipboardError}; pub use floem_reactive as reactive; pub use floem_renderer::text; -use floem_renderer::Renderer; +pub use floem_renderer::Renderer; pub use id::ViewId; pub use peniko; pub use peniko::kurbo; diff --git a/src/views/editor/mod.rs b/src/views/editor/mod.rs index 7ca4ac57..979b3b67 100644 --- a/src/views/editor/mod.rs +++ b/src/views/editor/mod.rs @@ -129,7 +129,7 @@ prop_extractor! { } } impl EditorStyle { - fn ed_text_color(&self) -> Color { + pub fn ed_text_color(&self) -> Color { self.text_color().unwrap_or(Color::BLACK) } }