feat(scrollable): add helper for horizontal scrollables

Adds a helper function to get horizontal scrollables with COSMIC styling.
This commit is contained in:
Vukašin Vojinović 2025-04-04 17:18:13 +02:00 committed by Michael Murphy
parent 1509163230
commit dd1b16a353
5 changed files with 42 additions and 33 deletions

View file

@ -546,7 +546,6 @@ impl<App: Application> ApplicationExt for App {
let sharp_corners = core.window.sharp_corners;
let content_container = core.window.content_container;
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 focused = core
.focused_window()
@ -557,11 +556,7 @@ impl<App: Application> ApplicationExt for App {
let main_content_padding = if !content_container {
[0, 0, 0, 0]
} else {
let right_padding = if show_context && !context_is_overlay {
0
} else {
border_padding
};
let right_padding = if show_context { 0 } else { border_padding };
let left_padding = if nav_bar_active { 0 } else { border_padding };
[0, right_padding, 0, left_padding]
@ -595,7 +590,7 @@ impl<App: Application> ApplicationExt for App {
//TODO: reduce duplication
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() {
widgets.push(
crate::widget::context_drawer(
@ -615,17 +610,11 @@ impl<App: Application> ApplicationExt for App {
))
})
.apply(container)
.padding(if content_container {
[0, border_padding, border_padding, border_padding]
} else {
[0, 0, 0, 0]
})
.padding([0, border_padding, 0, 0])
.apply(Element::from)
.map(crate::Action::App),
);
} else {
//TODO: container and padding are temporary, until
//the `resize_border` is moved to not cover window content
widgets.push(
container(main_content.map(crate::Action::App))
.padding(main_content_padding)
@ -634,8 +623,6 @@ impl<App: Application> ApplicationExt for App {
}
} else {
//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(
container(main_content.map(crate::Action::App))
.padding(main_content_padding)

View file

@ -308,10 +308,9 @@ pub mod row {
}
}
mod scrollable;
pub mod scrollable;
#[doc(inline)]
pub use scrollable::*;
pub use scrollable::scrollable;
pub mod segmented_button;
pub mod segmented_control;

View file

@ -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)
}

View 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};

View 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)
}