mirror of
https://gitlab.freedesktop.org/pipewire/helvum
synced 2026-03-15 11:36:11 +08:00
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:
@@ -640,7 +640,7 @@ impl GraphView {
|
|||||||
// Get max in column
|
// Get max in column
|
||||||
y1.partial_cmp(y2).unwrap_or(Ordering::Equal)
|
y1.partial_cmp(y2).unwrap_or(Ordering::Equal)
|
||||||
})
|
})
|
||||||
.map_or(20_f32, |(_x, y)| y + 100.0);
|
.map_or(20_f32, |(_x, y)| y + 120.0);
|
||||||
|
|
||||||
imp.nodes.borrow_mut().insert(id, (node, Point::new(x, y)));
|
imp.nodes.borrow_mut().insert(id, (node, Point::new(x, y)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,12 @@ mod imp {
|
|||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let grid = gtk::Grid::new();
|
let grid = gtk::Grid::new();
|
||||||
|
|
||||||
let label = gtk::Label::new(None);
|
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);
|
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) {
|
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||||
match pspec.name() {
|
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()),
|
"pipewire-id" => self.pipewire_id.set(value.get().unwrap()),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,12 @@ mod imp {
|
|||||||
impl ObjectImpl for Port {
|
impl ObjectImpl for Port {
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
self.label.set_parent(&*self.obj());
|
self.label.set_parent(&*self.obj());
|
||||||
|
self.label.set_wrap(true);
|
||||||
|
self.label.set_lines(2);
|
||||||
|
self.label.set_max_width_chars(20);
|
||||||
|
self.label.set_ellipsize(gtk::pango::EllipsizeMode::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispose(&self) {
|
fn dispose(&self) {
|
||||||
@@ -99,7 +104,10 @@ mod imp {
|
|||||||
|
|
||||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||||
match pspec.name() {
|
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()).unwrap(),
|
"pipewire-id" => self.pipewire_id.set(value.get().unwrap()).unwrap(),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user