feat: use ellipsizing for item names
This commit is contained in:
parent
f9d4ca4867
commit
059f0227f9
1 changed files with 49 additions and 20 deletions
69
src/tab.rs
69
src/tab.rs
|
|
@ -2223,6 +2223,28 @@ impl Item {
|
|||
name.replace('.', ".\u{200B}").replace('_', "_\u{200B}")
|
||||
}
|
||||
|
||||
/// Text widget for a filename in grid/icon view: word-or-glyph wrapping, middle-ellipsized to 3 lines.
|
||||
fn grid_display_name<'a>(
|
||||
name: impl Into<Cow<'a, str>> + 'a,
|
||||
) -> widget::Text<'a, cosmic::Theme, cosmic::Renderer> {
|
||||
widget::text::body(name)
|
||||
.wrapping(text::Wrapping::WordOrGlyph)
|
||||
.ellipsize(text::Ellipsize::Middle(
|
||||
text::EllipsizeHeightLimit::Lines(3),
|
||||
))
|
||||
}
|
||||
|
||||
/// Text widget for a filename in list view: word-or-glyph wrapping, middle-ellipsized to 1 line.
|
||||
fn list_display_name<'a>(
|
||||
name: impl Into<Cow<'a, str>> + 'a,
|
||||
) -> widget::Text<'a, cosmic::Theme, cosmic::Renderer> {
|
||||
widget::text::body(name)
|
||||
.wrapping(text::Wrapping::WordOrGlyph)
|
||||
.ellipsize(text::Ellipsize::Middle(
|
||||
text::EllipsizeHeightLimit::Lines(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn path_opt(&self) -> Option<&PathBuf> {
|
||||
self.location_opt.as_ref()?.path_opt()
|
||||
}
|
||||
|
|
@ -4706,6 +4728,7 @@ impl Tab {
|
|||
vertical_alignment: Vertical::Top,
|
||||
shaping: text::Shaping::default(),
|
||||
wrapping: text::Wrapping::None,
|
||||
ellipsize: text::Ellipsize::End(text::EllipsizeHeightLimit::Lines(1)),
|
||||
};
|
||||
graphics::text::Paragraph::with_text(text)
|
||||
.min_bounds()
|
||||
|
|
@ -4919,7 +4942,11 @@ impl Tab {
|
|||
let (name_width, name_text) = if children.is_empty() {
|
||||
(
|
||||
text_width_heading(&name),
|
||||
widget::text::heading(name).wrapping(text::Wrapping::None),
|
||||
widget::text::heading(name)
|
||||
.wrapping(text::Wrapping::None)
|
||||
.ellipsize(text::Ellipsize::End(
|
||||
text::EllipsizeHeightLimit::Lines(1),
|
||||
)),
|
||||
)
|
||||
} else {
|
||||
children.push(
|
||||
|
|
@ -5218,7 +5245,7 @@ impl Tab {
|
|||
))
|
||||
.into(),
|
||||
widget::tooltip(
|
||||
widget::button::custom(widget::text::body(&item.display_name))
|
||||
widget::button::custom(Item::grid_display_name(&item.display_name))
|
||||
.id(item.button_id.clone())
|
||||
.padding([0, space_xxxs])
|
||||
.class(button_style(
|
||||
|
|
@ -5383,18 +5410,20 @@ impl Tab {
|
|||
false,
|
||||
false,
|
||||
)),
|
||||
widget::button::custom(widget::text::body(item.display_name.clone()))
|
||||
.id(item.button_id.clone())
|
||||
.on_press(Message::Click(Some(*i)))
|
||||
.padding([0, space_xxxs])
|
||||
.class(button_style(
|
||||
item.selected,
|
||||
item.highlighted,
|
||||
item.cut,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)),
|
||||
widget::button::custom(
|
||||
Item::grid_display_name(item.display_name.clone()),
|
||||
)
|
||||
.id(item.button_id.clone())
|
||||
.on_press(Message::Click(Some(*i)))
|
||||
.padding([0, space_xxxs])
|
||||
.class(button_style(
|
||||
item.selected,
|
||||
item.highlighted,
|
||||
item.cut,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)),
|
||||
];
|
||||
|
||||
let column =
|
||||
|
|
@ -5593,7 +5622,7 @@ impl Tab {
|
|||
.size(icon_size)
|
||||
.into(),
|
||||
widget::column::with_children([
|
||||
widget::text::body(item.display_name.clone()).into(),
|
||||
Item::list_display_name(item.display_name.clone()).into(),
|
||||
//TODO: translate?
|
||||
widget::text::caption(format!("{modified_text} - {size_text}"))
|
||||
.into(),
|
||||
|
|
@ -5610,7 +5639,7 @@ impl Tab {
|
|||
.size(icon_size)
|
||||
.into(),
|
||||
widget::column::with_children([
|
||||
widget::text::body(item.display_name.clone()).into(),
|
||||
Item::list_display_name(item.display_name.clone()).into(),
|
||||
widget::text::caption(match item.path_opt() {
|
||||
Some(path) => path.display().to_string(),
|
||||
None => String::new(),
|
||||
|
|
@ -5635,7 +5664,7 @@ impl Tab {
|
|||
.content_fit(ContentFit::Contain)
|
||||
.size(icon_size)
|
||||
.into(),
|
||||
widget::text::body(item.display_name.clone())
|
||||
Item::list_display_name(item.display_name.clone())
|
||||
.width(Length::Fill)
|
||||
.into(),
|
||||
widget::text::body(modified_text.clone())
|
||||
|
|
@ -5702,7 +5731,7 @@ impl Tab {
|
|||
.size(icon_size)
|
||||
.into(),
|
||||
widget::column::with_children([
|
||||
widget::text::body(item.display_name.clone()).into(),
|
||||
Item::list_display_name(item.display_name.clone()).into(),
|
||||
//TODO: translate?
|
||||
widget::text::body(format!("{modified_text} - {size_text}"))
|
||||
.into(),
|
||||
|
|
@ -5719,7 +5748,7 @@ impl Tab {
|
|||
.size(icon_size)
|
||||
.into(),
|
||||
widget::column::with_children([
|
||||
widget::text::body(item.display_name.clone()).into(),
|
||||
Item::list_display_name(item.display_name.clone()).into(),
|
||||
widget::text::caption(match item.path_opt() {
|
||||
Some(path) => path.display().to_string(),
|
||||
None => String::new(),
|
||||
|
|
@ -5744,7 +5773,7 @@ impl Tab {
|
|||
.content_fit(ContentFit::Contain)
|
||||
.size(icon_size)
|
||||
.into(),
|
||||
widget::text::body(item.display_name.clone())
|
||||
Item::list_display_name(item.display_name.clone())
|
||||
.width(Length::Fill)
|
||||
.into(),
|
||||
widget::text(modified_text)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue