cosmic-text icon indicating copy to clipboard operation
cosmic-text copied to clipboard

WIP: Ellipsize

Open hojjatabdollahi opened this issue 2 years ago • 7 comments

This is just the beginning for Ellipsize, and I have questions! I would appreciate any feedback.

Here is the Ellipsize enum, I think multi-line ellipsization would only be useful for Ellipsize::End :


pub enum Ellipsize {
    /// No Ellipsize
    None,
    /// Ellipsis at the start, will create a single line with ellipsis at the start
    Start,
    /// Ellipsis in the middle, will create a single line with ellipsis in the middle
    Middle,
    /// Ellipsis at the end, can create one, or more lines depending on the `HeighLimit` and `Wrap`
    End(HeightLimit),
}

pub enum HeightLimit {
    /// Default is a single line
    Default,
    /// Number of maximum lines allowed, `Line(0)`, or `Line(1)`, would be the same as `Default`,
    /// which is a single line. The ellipsis will show at the end of the last line.
    Lines(u8),
    /// The amount of text is limited to the current buffer height. Depending on the font size,
    /// fewer or more lines will be displayed.
    Height,
}

Current implementation:

  • I'm shaping a "…" character to match the font family and size and store it in the ShapeLine to insert it later where it's needed. This will be customizable.
  • Currently I store the ellipsize attribute in the Text. I think it should be stored in any widget that uses BufferLine. For example a label can have multiple paragraphs, but if I want it to ellipsize after 5 lines, it should happen regardless of how many paragraphs fit in those 5 lines. I doubt that we want to have ellipsizing per paragraph.

Questions: 1- Do we want ellipsis based on height? Depending on the font size you might be able to fit more or fewer lines in the same text area.

2- When it comes to text selection, what should happen? If I create a label with some of the text ellipsized, and then select the text (including the ellipsis) and copy it, does that mean I copy the ellipsis character? or the hidden text?

hojjatabdollahi avatar Feb 25 '23 03:02 hojjatabdollahi

Ellipsize::End for Text in editor-libcosmic example.

image

hojjatabdollahi avatar Mar 04 '23 19:03 hojjatabdollahi

Ellipsize::End for Text in editor-libcosmic example.

image

The elipsis seems to be overlapping the switch (to it's right) here. That doesn't seem right...

I think multi-line ellipsization would only be useful for Ellipsize::End

IMO it would make sense to also make it available for Ellipsize::Start. I can't actually see myself using that variant, but given that cosmic-text is a relatively low-level library and this would presumably add very little to the implementation complexity, I think we ought to bias towards making the API as flexible as possible. I guess you could also make it work for Ellipsize::Middle. It would look weird, but that's also true of single line middle-ellipsization!

nicoburns avatar Mar 06 '23 15:03 nicoburns

The elipsis seems to be overlapping the switch (to it's right) here. That doesn't seem right...

That's actually the switch overlapping with the text. I wish I could set a minimum width for the UI elements in Iced!

Regarding the multi-line ellipsizing, it would increase the complexity, especially because I'm thinking the multi-line ellipsization should happen in Buffer and not Bufferline to allow for ellipsizing multi-paragraph labels.

hojjatabdollahi avatar Mar 06 '23 15:03 hojjatabdollahi

That's actually the switch overlapping with the text. I wish I could set a minimum width for the UI elements in Iced!

Ah, yeah. Iced's layout is... a bit lacking.

Regarding the multi-line ellipsizing, it would increase the complexity, especially because I'm thinking the multi-line ellipsization should happen in Buffer and not Bufferline to allow for ellipsizing multi-paragraph labels.

Hmm... ok. Well, I'll defer to your expertise on this issue!

nicoburns avatar Mar 06 '23 15:03 nicoburns

Hmm... ok. Well, I'll defer to your expertise on this issue!

Please don't! I'll take any help I can get.

With multi-line ellipsize, I think GTK does it with a set_line function and I think I read somewhere that it only affects Ellipsize::End and won't do anything in other cases. But I'm not 100% sure.

hojjatabdollahi avatar Mar 06 '23 15:03 hojjatabdollahi

Hi, was just wondering if this is still being worked on? I was going to implement this in my UI framework but then noticed this PR to add it at the cosmic-text level.

geom3trik avatar Aug 09 '23 22:08 geom3trik

Hi, was just wondering if this is still being worked on?

Hi,

I have been super busy irl. But this and a few RTL features are definitely somethings I will do. However, if you want to take over or help out, I would be happy.

This was my plan: I was thinking to change the visual line struct and add a property that describes if this visual line is ellipsized, hyphenated, wrapped, or none. That way instead of cosmic-text always adding an ellipsis glyph, the GUI framework can decide what it wants to do with visual lines that are ellipsized, if it wants to show ellipsis, or fade out the last few letters, or add some marker (like an arrow) that says the text is cut off.

hojjatabdollahi avatar Aug 10 '23 16:08 hojjatabdollahi

Hi, just wondering if there's been any additional work on this or what would be needed to get it across the finish line

airstrike avatar Sep 08 '24 17:09 airstrike

I haven't had a chance to work on this and the codebase has changed a lot since when I started this PR, so I don't know how much more work is left to do.

Please feel free to build upon / copy / ignore this! I will close this PR as I won't be able to work on it for a few more months.

hojjatabdollahi avatar Sep 08 '24 18:09 hojjatabdollahi