Skip to content

Commit dfcbd6e

Browse files
committed
Set PickerGroupBox width to largest group, center Picker
This more or less works. Scaling in increments doesn't seem to be possible, so centering is really only possible for the group box alone, or with a limit to width.
1 parent 29b7f48 commit dfcbd6e

File tree

2 files changed

+3
-46
lines changed

2 files changed

+3
-46
lines changed

src/picker/group_box/mod.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ impl ObjectImpl for PickerGroupBoxInner {
4646
});
4747
SIGNALS.as_ref()
4848
}
49-
50-
fn constructed(&self, widget: &Self::Type) {
51-
self.parent_constructed(widget);
52-
widget.set_halign(gtk::Align::Center);
53-
}
5449
}
5550

5651
impl WidgetImpl for PickerGroupBoxInner {
@@ -59,24 +54,13 @@ impl WidgetImpl for PickerGroupBoxInner {
5954
}
6055

6156
fn preferred_width(&self, _widget: &Self::Type) -> (i32, i32) {
62-
let minimum_width = self
57+
let width = self
6358
.groups
6459
.iter()
6560
.map(|x| x.widget().preferred_width().1)
6661
.max()
6762
.unwrap_or(0);
68-
let natural_width = self
69-
.groups
70-
.chunks(3)
71-
.map(|row| {
72-
row.iter()
73-
.map(|x| x.widget().preferred_width().1)
74-
.sum::<i32>()
75-
})
76-
.max()
77-
.unwrap_or(0)
78-
+ 2 * HSPACING;
79-
(minimum_width, natural_width)
63+
(width, width)
8064
}
8165

8266
fn preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32) {
@@ -85,34 +69,6 @@ impl WidgetImpl for PickerGroupBoxInner {
8569
(height, height)
8670
}
8771

88-
fn adjust_size_allocation(
89-
&self,
90-
obj: &Self::Type,
91-
orientation: gtk::Orientation,
92-
minimum_size: &mut i32,
93-
natural_size: &mut i32,
94-
allocated_pos: &mut i32,
95-
allocated_size: &mut i32,
96-
) {
97-
// For centering to work, adjust natural width to be the portion of
98-
// allocated width that will actually be used after reflowing
99-
// children.
100-
if orientation == gtk::Orientation::Horizontal {
101-
let rows = obj.rows_for_width(*allocated_size);
102-
let total_width = max_width_for_rows(&rows);
103-
*natural_size = (*natural_size).min(total_width);
104-
}
105-
106-
self.parent_adjust_size_allocation(
107-
obj,
108-
orientation,
109-
minimum_size,
110-
natural_size,
111-
allocated_pos,
112-
allocated_size,
113-
);
114-
}
115-
11672
fn size_allocate(&self, obj: &Self::Type, allocation: &gtk::Allocation) {
11773
self.parent_size_allocate(obj, allocation);
11874

src/picker/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl ObjectImpl for PickerInner {
9696
cascade! {
9797
picker;
9898
..set_orientation(gtk::Orientation::Vertical);
99+
..set_halign(gtk::Align::Center);
99100
..add(&stack_switcher);
100101
..add(&stack);
101102
..show_all();

0 commit comments

Comments
 (0)