Add text::Wrapping support
Co-authored-by: Neeraj Jaiswal <neerajj85@gmail.com>
This commit is contained in:
parent
8d826cc662
commit
f98328f4f1
21 changed files with 160 additions and 30 deletions
|
|
@ -161,6 +161,7 @@ impl text::Editor for () {
|
|||
_new_font: Self::Font,
|
||||
_new_size: Pixels,
|
||||
_new_line_height: text::LineHeight,
|
||||
_new_wrapping: text::Wrapping,
|
||||
_new_highlighter: &mut impl text::Highlighter,
|
||||
) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ pub struct Text<Content = String, Font = crate::Font> {
|
|||
|
||||
/// The [`Shaping`] strategy of the [`Text`].
|
||||
pub shaping: Shaping,
|
||||
|
||||
/// The [`Wrapping`] strategy of the [`Text`].
|
||||
pub wrapping: Wrapping,
|
||||
}
|
||||
|
||||
/// The shaping strategy of some text.
|
||||
|
|
@ -67,6 +70,22 @@ pub enum Shaping {
|
|||
Advanced,
|
||||
}
|
||||
|
||||
/// The wrapping strategy of some text.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub enum Wrapping {
|
||||
/// No wrapping.
|
||||
None,
|
||||
/// Wraps at the word level.
|
||||
///
|
||||
/// This is the default.
|
||||
#[default]
|
||||
Word,
|
||||
/// Wraps at the glyph level.
|
||||
Glyph,
|
||||
/// Wraps at the word level, or fallback to glyph level if a word can't fit on a line by itself.
|
||||
WordOrGlyph,
|
||||
}
|
||||
|
||||
/// The height of a line of text in a paragraph.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum LineHeight {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Edit text.
|
||||
use crate::text::highlighter::{self, Highlighter};
|
||||
use crate::text::LineHeight;
|
||||
use crate::text::{LineHeight, Wrapping};
|
||||
use crate::{Pixels, Point, Rectangle, Size};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
|
@ -50,6 +50,7 @@ pub trait Editor: Sized + Default {
|
|||
new_font: Self::Font,
|
||||
new_size: Pixels,
|
||||
new_line_height: LineHeight,
|
||||
new_wrapping: Wrapping,
|
||||
new_highlighter: &mut impl Highlighter,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ impl<P: Paragraph> Plain<P> {
|
|||
horizontal_alignment: text.horizontal_alignment,
|
||||
vertical_alignment: text.vertical_alignment,
|
||||
shaping: text.shaping,
|
||||
wrapping: text.wrapping,
|
||||
}) {
|
||||
Difference::None => {}
|
||||
Difference::Bounds => {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
Widget,
|
||||
};
|
||||
|
||||
pub use text::{LineHeight, Shaping};
|
||||
pub use text::{LineHeight, Shaping, Wrapping};
|
||||
|
||||
/// A paragraph of text.
|
||||
#[allow(missing_debug_implementations)]
|
||||
|
|
@ -29,6 +29,7 @@ where
|
|||
vertical_alignment: alignment::Vertical,
|
||||
font: Option<Renderer::Font>,
|
||||
shaping: Shaping,
|
||||
wrapping: Wrapping,
|
||||
class: Theme::Class<'a>,
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +49,8 @@ where
|
|||
height: Length::Shrink,
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
shaping: Shaping::Basic,
|
||||
shaping: Shaping::default(),
|
||||
wrapping: Wrapping::default(),
|
||||
class: Theme::default(),
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +117,12 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the [`Wrapping`] strategy of the [`Text`].
|
||||
pub fn wrapping(mut self, wrapping: Wrapping) -> Self {
|
||||
self.wrapping = wrapping;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style of the [`Text`].
|
||||
#[must_use]
|
||||
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
|
||||
|
|
@ -198,6 +206,7 @@ where
|
|||
self.horizontal_alignment,
|
||||
self.vertical_alignment,
|
||||
self.shaping,
|
||||
self.wrapping,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -232,6 +241,7 @@ pub fn layout<Renderer>(
|
|||
horizontal_alignment: alignment::Horizontal,
|
||||
vertical_alignment: alignment::Vertical,
|
||||
shaping: Shaping,
|
||||
wrapping: Wrapping,
|
||||
) -> layout::Node
|
||||
where
|
||||
Renderer: text::Renderer,
|
||||
|
|
@ -253,6 +263,7 @@ where
|
|||
horizontal_alignment,
|
||||
vertical_alignment,
|
||||
shaping,
|
||||
wrapping,
|
||||
});
|
||||
|
||||
paragraph.min_bounds()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue