feat: add Ellipsize to widgets
This commit is contained in:
parent
f2ef716ad5
commit
cc670e1966
18 changed files with 181 additions and 9 deletions
|
|
@ -355,6 +355,37 @@ pub fn to_wrap(wrapping: Wrapping) -> cosmic_text::Wrap {
|
|||
}
|
||||
}
|
||||
|
||||
/// Converts some [`Ellipsize`] strategy to a [`cosmic_text::Ellipsize`] strategy.
|
||||
pub fn to_ellipsize(
|
||||
ellipsize: crate::core::text::Ellipsize,
|
||||
) -> cosmic_text::Ellipsize {
|
||||
match ellipsize {
|
||||
crate::core::text::Ellipsize::None => cosmic_text::Ellipsize::None,
|
||||
crate::core::text::Ellipsize::Start(limit) => {
|
||||
cosmic_text::Ellipsize::Start(to_ellipsize_height_limit(limit))
|
||||
}
|
||||
crate::core::text::Ellipsize::Middle(limit) => {
|
||||
cosmic_text::Ellipsize::Middle(to_ellipsize_height_limit(limit))
|
||||
}
|
||||
crate::core::text::Ellipsize::End(limit) => {
|
||||
cosmic_text::Ellipsize::End(to_ellipsize_height_limit(limit))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_ellipsize_height_limit(
|
||||
limit: crate::core::text::EllipsizeHeightLimit,
|
||||
) -> cosmic_text::EllipsizeHeightLimit {
|
||||
match limit {
|
||||
crate::core::text::EllipsizeHeightLimit::Lines(lines) => {
|
||||
cosmic_text::EllipsizeHeightLimit::Lines(lines)
|
||||
}
|
||||
crate::core::text::EllipsizeHeightLimit::Height(height) => {
|
||||
cosmic_text::EllipsizeHeightLimit::Height(height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts some [`Color`] to a [`cosmic_text::Color`].
|
||||
pub fn to_color(color: Color) -> cosmic_text::Color {
|
||||
let [r, g, b, a] = color.into_rgba8();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
//! Draw paragraphs.
|
||||
use iced_core::text::Ellipsize;
|
||||
|
||||
use crate::core;
|
||||
use crate::core::alignment;
|
||||
use crate::core::text::{
|
||||
|
|
@ -24,6 +26,7 @@ struct Internal {
|
|||
align_y: alignment::Vertical,
|
||||
bounds: Size,
|
||||
min_bounds: Size,
|
||||
ellipsize: Ellipsize,
|
||||
version: text::Version,
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +86,10 @@ impl core::text::Paragraph for Paragraph {
|
|||
);
|
||||
|
||||
buffer.set_wrap(font_system.raw(), text::to_wrap(text.wrapping));
|
||||
buffer.set_ellipsize(
|
||||
font_system.raw(),
|
||||
text::to_ellipsize(text.ellipsize),
|
||||
);
|
||||
|
||||
buffer.set_text(
|
||||
font_system.raw(),
|
||||
|
|
@ -101,6 +108,7 @@ impl core::text::Paragraph for Paragraph {
|
|||
align_x: text.align_x,
|
||||
align_y: text.align_y,
|
||||
shaping: text.shaping,
|
||||
ellipsize: text.ellipsize,
|
||||
wrapping: text.wrapping,
|
||||
bounds: text.bounds,
|
||||
min_bounds,
|
||||
|
|
@ -177,6 +185,7 @@ impl core::text::Paragraph for Paragraph {
|
|||
align_x: text.align_x,
|
||||
align_y: text.align_y,
|
||||
shaping: text.shaping,
|
||||
ellipsize: text.ellipsize,
|
||||
wrapping: text.wrapping,
|
||||
bounds: text.bounds,
|
||||
min_bounds,
|
||||
|
|
@ -394,6 +403,10 @@ impl core::text::Paragraph for Paragraph {
|
|||
glyph.y - glyph.y_offset * glyph.font_size,
|
||||
))
|
||||
}
|
||||
|
||||
fn ellipsize(&self) -> Ellipsize {
|
||||
self.0.ellipsize
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Paragraph {
|
||||
|
|
@ -438,6 +451,7 @@ impl Default for Internal {
|
|||
}),
|
||||
font: Font::default(),
|
||||
shaping: Shaping::default(),
|
||||
ellipsize: Ellipsize::default(),
|
||||
wrapping: Wrapping::default(),
|
||||
align_x: Alignment::Default,
|
||||
align_y: alignment::Vertical::Top,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue