Skip to content

Commit 5bd6ca7

Browse files
committed
fix(display): snap display arrangement scrollable to center
1 parent 219cb36 commit 5bd6ca7

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

app/src/pages/display/mod.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::{app, pages};
99
use apply::Apply;
1010
use arrangement::Arrangement;
1111
use cosmic::iced::Length;
12-
use cosmic::iced_core::Alignment;
13-
use cosmic::iced_widget::scrollable::{Direction, Properties};
12+
use cosmic::iced_widget::scrollable::{Direction, Properties, RelativeOffset};
1413
use cosmic::prelude::CollectionWidget;
1514
use cosmic::widget::{
1615
column, container, dropdown, list_column, segmented_button, toggler, view_switcher,
@@ -116,14 +115,28 @@ enum Randr {
116115
}
117116

118117
/// The page struct for the display settings page.
119-
#[derive(Default)]
120118
pub struct Page {
121119
list: List,
122120
display_tabs: segmented_button::SingleSelectModel,
123121
active_display: OutputKey,
124122
config: Config,
125123
cache: ViewCache,
126124
context: Option<ContextDrawer>,
125+
display_arrangement_scrollable: cosmic::widget::Id,
126+
}
127+
128+
impl Default for Page {
129+
fn default() -> Self {
130+
Self {
131+
list: List::default(),
132+
display_tabs: segmented_button::SingleSelectModel::default(),
133+
active_display: OutputKey::default(),
134+
config: Config::default(),
135+
cache: ViewCache::default(),
136+
context: None,
137+
display_arrangement_scrollable: cosmic::widget::Id::unique(),
138+
}
139+
}
127140
}
128141

129142
#[derive(Default)]
@@ -360,7 +373,10 @@ impl Page {
360373
}
361374
}
362375

363-
Command::none()
376+
cosmic::iced::widget::scrollable::snap_to(
377+
self.display_arrangement_scrollable.clone(),
378+
RelativeOffset { x: 0.5, y: 0.5 },
379+
)
364380
}
365381

366382
/// View for the display arrangement section.
@@ -379,6 +395,7 @@ impl Page {
379395
.on_select(|id| pages::Message::Displays(Message::Display(id)))
380396
.on_placement(|id, x, y| pages::Message::Displays(Message::Position(id, x, y)))
381397
.apply(cosmic::widget::scrollable)
398+
.id(self.display_arrangement_scrollable.clone())
382399
.width(Length::Shrink)
383400
.direction(Direction::Horizontal(Properties::new()))
384401
.apply(container)

0 commit comments

Comments
 (0)