Divide height among two labels

I’m not sure what I ask for is even possible, but here it goes:

I have a list(view) row of a fixed height and variable width which contains a box with two labels: a title and a small summary. The title should occupy up to 3 lines and then ellipsize.
The summary should fill the remaining space depending on how much height the title needs. Could be to hide the summary completely if the title needs all the space. Or to show 1 to 2 lines of the summary if there is enough empty space.

title needs two rows which leaves one for the summary:

title only needs one row so the summary could take up two rows:

Tweaking the line & visible properties manually in inspector yields the desired results. But I struggle to automate the layout. As far as I can see there is no way to react to the size allocation of a label in Gtk4 anymore (Gtk3 had the “size-allocate” signal). Being inside a listview makes things even more confusing since the rows are created but everything still has an allocation of 0x0 as long as they are not in the current viewport of the listview.

Sounds like you want the Gtk.Label:lines.

From what I understand ‘lines’ just is an upper limit. Not the actual number of lines of the label.

Ah, when you said this I thought “maximum number of lines” was what you intended. I suppose you could create a custom widget and do something in measure(), but I’m not sure otherwise.

Maybe Gtk.Inscription might be useful?

This is pretty close! Thanks for the tip.

but as you can see it starts drawing a third line even though there are just a few pixels left.

That would come close to re-inventing text layout as a whole, wouldn’t it?

Never mind: was missing the text-overflow property. With this and min-lines at 0 there is still clipping text. But turning min-lines up to 1 and limiting the title label works for me I guess.

Thanks everyone!

1 Like

Glad you got it sorted, that looks nice!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.