Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Ellipsize #84

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

hojjatabdollahi
Copy link
Contributor

@hojjatabdollahi hojjatabdollahi commented Feb 25, 2023

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 hojjatabdollahi marked this pull request as draft March 3, 2023 00:09
@hojjatabdollahi
Copy link
Contributor Author

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

image

@hojjatabdollahi hojjatabdollahi changed the title WIP: Taking a stab at Ellipsize WIP: Ellipsize Mar 4, 2023
@nicoburns
Copy link
Contributor

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!

@hojjatabdollahi
Copy link
Contributor Author

hojjatabdollahi commented Mar 6, 2023

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.

@nicoburns
Copy link
Contributor

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!

@hojjatabdollahi
Copy link
Contributor Author

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.

@geom3trik
Copy link

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.

@hojjatabdollahi
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants