view: Improve layout of labels on nodes and ports

This sets a maximum width of 20 chars on labels on nodes and ports.
Longer labels will wrap to a second line.

For labels longer than two lines, the label is ellipsized at the end.
The full label can still be viewed via hovering for a tooltip.

Co-authored-by: Roger Roger <me@rogerrogert.de>
This commit is contained in:
Tom A. Wagner
2023-02-12 20:58:34 +01:00
parent fe05282f5a
commit 91d7e10bdc
3 changed files with 19 additions and 3 deletions

View File

@@ -48,7 +48,12 @@ mod imp {
fn new() -> Self {
let grid = gtk::Grid::new();
let label = gtk::Label::new(None);
label.set_wrap(true);
label.set_lines(2);
label.set_max_width_chars(20);
label.set_ellipsize(gtk::pango::EllipsizeMode::End);
grid.attach(&label, 0, 0, 2, 1);
@@ -95,7 +100,10 @@ mod imp {
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
match pspec.name() {
"name" => self.label.set_text(value.get().unwrap()),
"name" => {
self.label.set_text(value.get().unwrap());
self.label.set_tooltip_text(value.get().ok());
}
"pipewire-id" => self.pipewire_id.set(value.get().unwrap()),
_ => unimplemented!(),
}