summaryrefslogtreecommitdiffstats
path: root/widget/src/pane_grid
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/pane_grid')
-rw-r--r--widget/src/pane_grid/content.rs59
-rw-r--r--widget/src/pane_grid/state.rs8
-rw-r--r--widget/src/pane_grid/title_bar.rs64
3 files changed, 70 insertions, 61 deletions
diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs
index 98f4f99a..30ad52ca 100644
--- a/widget/src/pane_grid/content.rs
+++ b/widget/src/pane_grid/content.rs
@@ -6,7 +6,7 @@ use crate::core::overlay;
use crate::core::renderer;
use crate::core::widget::{self, Tree};
use crate::core::{
- Clipboard, Element, Layout, Point, Rectangle, Shell, Size, Vector,
+ self, Clipboard, Element, Layout, Point, Rectangle, Shell, Size, Vector,
};
use crate::pane_grid::{Draggable, TitleBar};
@@ -20,30 +20,29 @@ pub struct Content<
Theme = crate::Theme,
Renderer = crate::Renderer,
> where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
title_bar: Option<TitleBar<'a, Message, Theme, Renderer>>,
body: Element<'a, Message, Theme, Renderer>,
- style: container::Style<'a, Theme>,
+ class: Theme::Class<'a>,
}
impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer>
where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
/// Creates a new [`Content`] with the provided body.
- pub fn new(body: impl Into<Element<'a, Message, Theme, Renderer>>) -> Self
- where
- Theme: container::DefaultStyle + 'a,
- {
+ pub fn new(body: impl Into<Element<'a, Message, Theme, Renderer>>) -> Self {
Self {
title_bar: None,
body: body.into(),
- style: Box::new(Theme::default_style),
+ class: Theme::default(),
}
}
- /// Sets the [`TitleBar`] of this [`Content`].
+ /// Sets the [`TitleBar`] of the [`Content`].
pub fn title_bar(
mut self,
title_bar: TitleBar<'a, Message, Theme, Renderer>,
@@ -53,18 +52,31 @@ where
}
/// Sets the style of the [`Content`].
+ #[must_use]
pub fn style(
mut self,
- style: impl Fn(&Theme, container::Status) -> container::Appearance + 'a,
- ) -> Self {
- self.style = Box::new(style);
+ style: impl Fn(&Theme) -> container::Style + 'a,
+ ) -> Self
+ where
+ Theme::Class<'a>: From<container::StyleFn<'a, Theme>>,
+ {
+ self.class = (Box::new(style) as container::StyleFn<'a, Theme>).into();
+ self
+ }
+
+ /// Sets the style class of the [`Content`].
+ #[cfg(feature = "advanced")]
+ #[must_use]
+ pub fn class(mut self, class: impl Into<Theme::Class<'a>>) -> Self {
+ self.class = class.into();
self
}
}
impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer>
where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
pub(super) fn state(&self) -> Tree {
let children = if let Some(title_bar) = self.title_bar.as_ref() {
@@ -93,7 +105,7 @@ where
/// Draws the [`Content`] with the provided [`Renderer`] and [`Layout`].
///
- /// [`Renderer`]: crate::core::Renderer
+ /// [`Renderer`]: core::Renderer
pub fn draw(
&self,
tree: &Tree,
@@ -107,15 +119,7 @@ where
let bounds = layout.bounds();
{
- let style = {
- let status = if cursor.is_over(bounds) {
- container::Status::Hovered
- } else {
- container::Status::Idle
- };
-
- (self.style)(theme, status)
- };
+ let style = theme.style(&self.class);
container::draw_background(renderer, &style, bounds);
}
@@ -381,7 +385,8 @@ where
impl<'a, Message, Theme, Renderer> Draggable
for &Content<'a, Message, Theme, Renderer>
where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
fn can_be_dragged_at(
&self,
@@ -403,8 +408,8 @@ impl<'a, T, Message, Theme, Renderer> From<T>
for Content<'a, Message, Theme, Renderer>
where
T: Into<Element<'a, Message, Theme, Renderer>>,
- Theme: container::DefaultStyle + 'a,
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog + 'a,
+ Renderer: core::Renderer,
{
fn from(element: T) -> Self {
Self::new(element)
diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs
index 481cd770..c20c3b9c 100644
--- a/widget/src/pane_grid/state.rs
+++ b/widget/src/pane_grid/state.rs
@@ -6,7 +6,7 @@ use crate::pane_grid::{
Axis, Configuration, Direction, Edge, Node, Pane, Region, Split, Target,
};
-use std::collections::HashMap;
+use rustc_hash::FxHashMap;
/// The state of a [`PaneGrid`].
///
@@ -25,7 +25,7 @@ pub struct State<T> {
/// The panes of the [`PaneGrid`].
///
/// [`PaneGrid`]: super::PaneGrid
- pub panes: HashMap<Pane, T>,
+ pub panes: FxHashMap<Pane, T>,
/// The internal state of the [`PaneGrid`].
///
@@ -52,7 +52,7 @@ impl<T> State<T> {
/// Creates a new [`State`] with the given [`Configuration`].
pub fn with_configuration(config: impl Into<Configuration<T>>) -> Self {
- let mut panes = HashMap::new();
+ let mut panes = FxHashMap::default();
let internal =
Internal::from_configuration(&mut panes, config.into(), 0);
@@ -353,7 +353,7 @@ impl Internal {
///
/// [`PaneGrid`]: super::PaneGrid
pub fn from_configuration<T>(
- panes: &mut HashMap<Pane, T>,
+ panes: &mut FxHashMap<Pane, T>,
content: Configuration<T>,
next_id: usize,
) -> Self {
diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs
index 8dfea6e3..c2eeebb7 100644
--- a/widget/src/pane_grid/title_bar.rs
+++ b/widget/src/pane_grid/title_bar.rs
@@ -6,7 +6,8 @@ use crate::core::overlay;
use crate::core::renderer;
use crate::core::widget::{self, Tree};
use crate::core::{
- Clipboard, Element, Layout, Padding, Point, Rectangle, Shell, Size, Vector,
+ self, Clipboard, Element, Layout, Padding, Point, Rectangle, Shell, Size,
+ Vector,
};
/// The title bar of a [`Pane`].
@@ -19,32 +20,31 @@ pub struct TitleBar<
Theme = crate::Theme,
Renderer = crate::Renderer,
> where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
content: Element<'a, Message, Theme, Renderer>,
controls: Option<Element<'a, Message, Theme, Renderer>>,
padding: Padding,
always_show_controls: bool,
- style: container::Style<'a, Theme>,
+ class: Theme::Class<'a>,
}
impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer>
where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
/// Creates a new [`TitleBar`] with the given content.
pub fn new(
content: impl Into<Element<'a, Message, Theme, Renderer>>,
- ) -> Self
- where
- Theme: container::DefaultStyle + 'a,
- {
+ ) -> Self {
Self {
content: content.into(),
controls: None,
padding: Padding::ZERO,
always_show_controls: false,
- style: Box::new(Theme::default_style),
+ class: Theme::default(),
}
}
@@ -63,15 +63,6 @@ where
self
}
- /// Sets the style of the [`TitleBar`].
- pub fn style(
- mut self,
- style: impl Fn(&Theme, container::Status) -> container::Appearance + 'a,
- ) -> Self {
- self.style = Box::new(style);
- self
- }
-
/// Sets whether or not the [`controls`] attached to this [`TitleBar`] are
/// always visible.
///
@@ -84,11 +75,33 @@ where
self.always_show_controls = true;
self
}
+
+ /// Sets the style of the [`TitleBar`].
+ #[must_use]
+ pub fn style(
+ mut self,
+ style: impl Fn(&Theme) -> container::Style + 'a,
+ ) -> Self
+ where
+ Theme::Class<'a>: From<container::StyleFn<'a, Theme>>,
+ {
+ self.class = (Box::new(style) as container::StyleFn<'a, Theme>).into();
+ self
+ }
+
+ /// Sets the style class of the [`TitleBar`].
+ #[cfg(feature = "advanced")]
+ #[must_use]
+ pub fn class(mut self, class: impl Into<Theme::Class<'a>>) -> Self {
+ self.class = class.into();
+ self
+ }
}
impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer>
where
- Renderer: crate::core::Renderer,
+ Theme: container::Catalog,
+ Renderer: core::Renderer,
{
pub(super) fn state(&self) -> Tree {
let children = if let Some(controls) = self.controls.as_ref() {
@@ -117,7 +130,7 @@ where
/// Draws the [`TitleBar`] with the provided [`Renderer`] and [`Layout`].
///
- /// [`Renderer`]: crate::core::Renderer
+ /// [`Renderer`]: core::Renderer
pub fn draw(
&self,
tree: &Tree,
@@ -130,16 +143,7 @@ where
show_controls: bool,
) {
let bounds = layout.bounds();
-
- let style = {
- let status = if cursor.is_over(bounds) {
- container::Status::Hovered
- } else {
- container::Status::Idle
- };
-
- (self.style)(theme, status)
- };
+ let style = theme.style(&self.class);
let inherited_style = renderer::Style {
text_color: style.text_color.unwrap_or(inherited_style.text_color),