Skip to content

Commit

Permalink
Add content_container flag to enable/disable wrapping content
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Dec 21, 2023
1 parent 18a5c67 commit b8f1a36
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/app/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Window {
/// Label to display as header bar title.
pub header_title: String,
pub use_template: bool,
pub content_container: bool,
pub can_fullscreen: bool,
pub sharp_corners: bool,
pub show_context: bool,
Expand Down Expand Up @@ -98,6 +99,7 @@ impl Default for Core {
context_title: String::new(),
header_title: String::new(),
use_template: true,
content_container: true,
can_fullscreen: false,
sharp_corners: false,
show_context: false,
Expand Down
74 changes: 40 additions & 34 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,45 @@ impl<App: Application> ApplicationExt for App {
let core = self.core();
let is_condensed = core.is_condensed();

let content_row = crate::widget::row::with_children({
let mut widgets = Vec::with_capacity(2);

// Insert nav bar onto the left side of the window.
if let Some(nav) = self.nav_bar() {
widgets.push(nav.debug(core.debug));
}

if self.nav_model().is_none() || core.show_content() {
let main_content = self.view().debug(core.debug).map(Message::App);

widgets.push(if let Some(context) = self.context_drawer() {
context_drawer(
&core.window.context_title,
Message::Cosmic(cosmic::Message::ContextDrawer(false)),
main_content,
context.map(Message::App),
)
.into()
} else {
main_content
});
}

widgets
})
.spacing(8);
let content: Element<_> = if core.window.content_container {
content_row
.apply(crate::widget::container)
.padding([0, 8, 8, 8])
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.style(crate::theme::Container::Background)
.into()
} else {
content_row.into()
};

crate::widget::column::with_capacity(2)
.push_maybe(if core.window.show_headerbar {
Some({
Expand Down Expand Up @@ -624,40 +663,7 @@ impl<App: Application> ApplicationExt for App {
None
})
// The content element contains every element beneath the header.
.push(
crate::widget::row::with_children({
let mut widgets = Vec::with_capacity(2);

// Insert nav bar onto the left side of the window.
if let Some(nav) = self.nav_bar() {
widgets.push(nav.debug(core.debug));
}

if self.nav_model().is_none() || core.show_content() {
let main_content = self.view().debug(core.debug).map(Message::App);

widgets.push(if let Some(context) = self.context_drawer() {
context_drawer(
&core.window.context_title,
Message::Cosmic(cosmic::Message::ContextDrawer(false)),
main_content,
context.map(Message::App),
)
.into()
} else {
main_content
});
}

widgets
})
.spacing(8)
.apply(crate::widget::container)
.padding([0, 8, 8, 8])
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.style(crate::theme::Container::Background),
)
.push(content)
.into()
}
}
Expand Down

0 comments on commit b8f1a36

Please sign in to comment.