feat(scrollable): add helper for horizontal scrollables
Adds a helper function to get horizontal scrollables with COSMIC styling.
This commit is contained in:
parent
1509163230
commit
dd1b16a353
5 changed files with 42 additions and 33 deletions
|
|
@ -546,7 +546,6 @@ impl<App: Application> ApplicationExt for App {
|
||||||
let sharp_corners = core.window.sharp_corners;
|
let sharp_corners = core.window.sharp_corners;
|
||||||
let content_container = core.window.content_container;
|
let content_container = core.window.content_container;
|
||||||
let show_context = core.window.show_context;
|
let show_context = core.window.show_context;
|
||||||
let context_is_overlay = core.window.context_is_overlay;
|
|
||||||
let nav_bar_active = core.nav_bar_active();
|
let nav_bar_active = core.nav_bar_active();
|
||||||
let focused = core
|
let focused = core
|
||||||
.focused_window()
|
.focused_window()
|
||||||
|
|
@ -557,11 +556,7 @@ impl<App: Application> ApplicationExt for App {
|
||||||
let main_content_padding = if !content_container {
|
let main_content_padding = if !content_container {
|
||||||
[0, 0, 0, 0]
|
[0, 0, 0, 0]
|
||||||
} else {
|
} else {
|
||||||
let right_padding = if show_context && !context_is_overlay {
|
let right_padding = if show_context { 0 } else { border_padding };
|
||||||
0
|
|
||||||
} else {
|
|
||||||
border_padding
|
|
||||||
};
|
|
||||||
let left_padding = if nav_bar_active { 0 } else { border_padding };
|
let left_padding = if nav_bar_active { 0 } else { border_padding };
|
||||||
|
|
||||||
[0, right_padding, 0, left_padding]
|
[0, right_padding, 0, left_padding]
|
||||||
|
|
@ -595,7 +590,7 @@ impl<App: Application> ApplicationExt for App {
|
||||||
|
|
||||||
//TODO: reduce duplication
|
//TODO: reduce duplication
|
||||||
let context_width = core.context_width(has_nav);
|
let context_width = core.context_width(has_nav);
|
||||||
if context_is_overlay && show_context {
|
if core.window.context_is_overlay && show_context {
|
||||||
if let Some(context) = self.context_drawer() {
|
if let Some(context) = self.context_drawer() {
|
||||||
widgets.push(
|
widgets.push(
|
||||||
crate::widget::context_drawer(
|
crate::widget::context_drawer(
|
||||||
|
|
@ -615,17 +610,11 @@ impl<App: Application> ApplicationExt for App {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.apply(container)
|
.apply(container)
|
||||||
.padding(if content_container {
|
.padding([0, border_padding, 0, 0])
|
||||||
[0, border_padding, border_padding, border_padding]
|
|
||||||
} else {
|
|
||||||
[0, 0, 0, 0]
|
|
||||||
})
|
|
||||||
.apply(Element::from)
|
.apply(Element::from)
|
||||||
.map(crate::Action::App),
|
.map(crate::Action::App),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//TODO: container and padding are temporary, until
|
|
||||||
//the `resize_border` is moved to not cover window content
|
|
||||||
widgets.push(
|
widgets.push(
|
||||||
container(main_content.map(crate::Action::App))
|
container(main_content.map(crate::Action::App))
|
||||||
.padding(main_content_padding)
|
.padding(main_content_padding)
|
||||||
|
|
@ -634,8 +623,6 @@ impl<App: Application> ApplicationExt for App {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//TODO: hide content when out of space
|
//TODO: hide content when out of space
|
||||||
//TODO: container and padding are temporary, until
|
|
||||||
//the `resize_border` is moved to not cover window content
|
|
||||||
widgets.push(
|
widgets.push(
|
||||||
container(main_content.map(crate::Action::App))
|
container(main_content.map(crate::Action::App))
|
||||||
.padding(main_content_padding)
|
.padding(main_content_padding)
|
||||||
|
|
|
||||||
|
|
@ -308,10 +308,9 @@ pub mod row {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod scrollable;
|
pub mod scrollable;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use scrollable::*;
|
pub use scrollable::scrollable;
|
||||||
|
|
||||||
pub mod segmented_button;
|
pub mod segmented_button;
|
||||||
pub mod segmented_control;
|
pub mod segmented_control;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// Copyright 2022 System76 <info@system76.com>
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
use crate::{Element, Renderer};
|
|
||||||
use iced::widget;
|
|
||||||
|
|
||||||
pub fn scrollable<'a, Message>(
|
|
||||||
element: impl Into<Element<'a, Message>>,
|
|
||||||
) -> widget::Scrollable<'a, Message, crate::Theme, Renderer> {
|
|
||||||
widget::scrollable(element)
|
|
||||||
.scroller_width(8.0)
|
|
||||||
.scrollbar_width(8.0)
|
|
||||||
.scrollbar_padding(8.0)
|
|
||||||
}
|
|
||||||
6
src/widget/scrollable/mod.rs
Normal file
6
src/widget/scrollable/mod.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// Copyright 2022 System76 <info@system76.com>
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
mod scrollable;
|
||||||
|
|
||||||
|
pub use scrollable::{horizontal, scrollable, vertical};
|
||||||
31
src/widget/scrollable/scrollable.rs
Normal file
31
src/widget/scrollable/scrollable.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright 2022 System76 <info@system76.com>
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
use crate::{Element, Renderer};
|
||||||
|
use iced::widget;
|
||||||
|
|
||||||
|
pub fn scrollable<'a, Message>(
|
||||||
|
element: impl Into<Element<'a, Message>>,
|
||||||
|
) -> widget::Scrollable<'a, Message, crate::Theme, Renderer> {
|
||||||
|
vertical(element)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vertical<'a, Message>(
|
||||||
|
element: impl Into<Element<'a, Message>>,
|
||||||
|
) -> widget::Scrollable<'a, Message, crate::Theme, Renderer> {
|
||||||
|
widget::scrollable(element)
|
||||||
|
.scroller_width(8.0)
|
||||||
|
.scrollbar_width(8.0)
|
||||||
|
.scrollbar_padding(8.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn horizontal<'a, Message>(
|
||||||
|
element: impl Into<Element<'a, Message>>,
|
||||||
|
) -> widget::Scrollable<'a, Message, crate::Theme, Renderer> {
|
||||||
|
widget::scrollable(element)
|
||||||
|
.direction(widget::scrollable::Direction::Horizontal(
|
||||||
|
widget::scrollable::Scrollbar::new(),
|
||||||
|
))
|
||||||
|
.scroller_width(8.0)
|
||||||
|
.scrollbar_width(8.0)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue