fix: condense navbar if window is too narrow
This commit is contained in:
parent
ed625deb0b
commit
753f0f67b3
1 changed files with 73 additions and 74 deletions
|
|
@ -53,7 +53,6 @@ pub struct SettingsApp {
|
||||||
pub active_page: page::Entity,
|
pub active_page: page::Entity,
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub is_condensed: bool,
|
|
||||||
pub nav_bar_toggled_condensed: bool,
|
pub nav_bar_toggled_condensed: bool,
|
||||||
pub nav_bar_toggled: bool,
|
pub nav_bar_toggled: bool,
|
||||||
pub nav_bar: segmented_button::SingleSelectModel,
|
pub nav_bar: segmented_button::SingleSelectModel,
|
||||||
|
|
@ -103,7 +102,6 @@ impl Application for SettingsApp {
|
||||||
active_page: page::Entity::default(),
|
active_page: page::Entity::default(),
|
||||||
config: Config::new(),
|
config: Config::new(),
|
||||||
debug: false,
|
debug: false,
|
||||||
is_condensed: false,
|
|
||||||
nav_bar: segmented_button::Model::default(),
|
nav_bar: segmented_button::Model::default(),
|
||||||
nav_bar_toggled: true,
|
nav_bar_toggled: true,
|
||||||
nav_bar_toggled_condensed: false,
|
nav_bar_toggled_condensed: false,
|
||||||
|
|
@ -208,12 +206,7 @@ impl Application for SettingsApp {
|
||||||
fn update(&mut self, message: Message) -> iced::Command<Self::Message> {
|
fn update(&mut self, message: Message) -> iced::Command<Self::Message> {
|
||||||
let mut ret = Command::none();
|
let mut ret = Command::none();
|
||||||
match message {
|
match message {
|
||||||
Message::WindowResize(width, _height) => {
|
Message::WindowResize(_width, _height) => {}
|
||||||
tracing::debug!(width, "new window width");
|
|
||||||
let break_point = (600.0 * self.scaling_factor) as u32;
|
|
||||||
self.window_width = width;
|
|
||||||
self.is_condensed = self.window_width < break_point;
|
|
||||||
}
|
|
||||||
Message::KeyboardNav(message) => match message {
|
Message::KeyboardNav(message) => match message {
|
||||||
keyboard_nav::Message::Unfocus => ret = keyboard_nav::unfocus(),
|
keyboard_nav::Message::Unfocus => ret = keyboard_nav::unfocus(),
|
||||||
keyboard_nav::Message::FocusNext => ret = widget::focus_next(),
|
keyboard_nav::Message::FocusNext => ret = widget::focus_next(),
|
||||||
|
|
@ -334,7 +327,11 @@ impl Application for SettingsApp {
|
||||||
return page.add_applet_view();
|
return page.add_applet_view();
|
||||||
}
|
}
|
||||||
|
|
||||||
let (nav_bar_message, nav_bar_toggled) = if self.is_condensed {
|
cosmic::iced::widget::responsive(|size| {
|
||||||
|
let is_condensed = (600.0 * self.scaling_factor) > size.width;
|
||||||
|
let narrow_navbar = (700.0 * self.scaling_factor) > size.width;
|
||||||
|
|
||||||
|
let (nav_bar_message, nav_bar_toggled) = if is_condensed {
|
||||||
(
|
(
|
||||||
Message::ToggleNavBarCondensed,
|
Message::ToggleNavBarCondensed,
|
||||||
self.nav_bar_toggled_condensed,
|
self.nav_bar_toggled_condensed,
|
||||||
|
|
@ -373,15 +370,15 @@ impl Application for SettingsApp {
|
||||||
if nav_bar_toggled {
|
if nav_bar_toggled {
|
||||||
let mut nav_bar = nav_bar(&self.nav_bar, Message::NavBar);
|
let mut nav_bar = nav_bar(&self.nav_bar, Message::NavBar);
|
||||||
|
|
||||||
if !self.is_condensed {
|
if !is_condensed {
|
||||||
nav_bar = nav_bar.max_width(300);
|
nav_bar = nav_bar.max_width(if narrow_navbar { 200 } else { 300 });
|
||||||
}
|
}
|
||||||
|
|
||||||
let nav_bar: Element<_> = nav_bar.into();
|
let nav_bar: Element<_> = nav_bar.into();
|
||||||
widgets.push(nav_bar.debug(self.debug));
|
widgets.push(nav_bar.debug(self.debug));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(self.is_condensed && nav_bar_toggled) {
|
if !(is_condensed && nav_bar_toggled) {
|
||||||
widgets.push(
|
widgets.push(
|
||||||
scrollable(row![
|
scrollable(row![
|
||||||
horizontal_space(Length::Fill),
|
horizontal_space(Length::Fill),
|
||||||
|
|
@ -409,6 +406,8 @@ impl Application for SettingsApp {
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
column(vec![header, content]).into()
|
column(vec![header, content]).into()
|
||||||
|
})
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn theme(&self) -> Theme {
|
fn theme(&self) -> Theme {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue