summaryrefslogtreecommitdiff
path: root/theme_test
diff options
context:
space:
mode:
Diffstat (limited to 'theme_test')
-rw-r--r--theme_test/src/main.rs284
1 files changed, 177 insertions, 107 deletions
diff --git a/theme_test/src/main.rs b/theme_test/src/main.rs
index d564ee5..b8653b5 100644
--- a/theme_test/src/main.rs
+++ b/theme_test/src/main.rs
@@ -1,7 +1,7 @@
use iced::Length::Fill;
use iced::widget::{
- button, center, checkbox, column, container, horizontal_rule, pick_list,
- radio, row, slider, text_input, toggler,
+ button, center, checkbox, column, container, horizontal_rule, pane_grid,
+ pick_list, radio, row, slider, text_input, toggler,
};
use iced::{Element, Length};
use iced_anim::{Animated, Animation, Event};
@@ -32,10 +32,11 @@ enum Message {
Bool(bool),
Radio(Choice),
Slider(f32),
+ Resize(pane_grid::ResizeEvent),
SwitchTheme(Event<Theme>),
}
-#[derive(Debug, Default)]
+#[derive(Debug)]
pub struct State {
theme: Animated<Theme>,
show_dialog: bool,
@@ -43,6 +44,28 @@ pub struct State {
is_checked: bool,
selection: Option<Choice>,
value: f32,
+ panes: pane_grid::State<Pane>,
+}
+
+impl Default for State {
+ fn default() -> Self {
+ Self {
+ theme: Default::default(),
+ show_dialog: Default::default(),
+ content: Default::default(),
+ is_checked: Default::default(),
+ selection: Default::default(),
+ value: Default::default(),
+ panes: pane_grid::State::with_configuration(
+ pane_grid::Configuration::Split {
+ axis: pane_grid::Axis::Vertical,
+ ratio: 0.5,
+ a: Box::new(pane_grid::Configuration::Pane(Pane::Left)),
+ b: Box::new(pane_grid::Configuration::Pane(Pane::Right)),
+ },
+ ),
+ }
+ }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -52,6 +75,12 @@ pub enum Choice {
C,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Pane {
+ Left,
+ Right,
+}
+
impl State {
fn update(&mut self, message: Message) {
match message {
@@ -66,118 +95,159 @@ impl State {
Message::Bool(is_checked) => self.is_checked = is_checked,
Message::Radio(choice) => self.selection = Some(choice),
Message::Slider(value) => self.value = value,
+ Message::Resize(pane_grid::ResizeEvent { split, ratio }) => {
+ self.panes.resize(split, ratio);
+ }
Message::SwitchTheme(event) => {
self.theme.update(event);
}
}
}
fn view(&self) -> Element<'_, Message, Theme> {
- let base = container(
- row![
- column![
- button("Disabled"),
- button("Filled").on_press(Message::Noop),
- button("Filled Tonal")
- .on_press(Message::Noop)
- .style(filled_tonal),
- button("Elevated").on_press(Message::Noop).style(elevated),
- button("Outlined").on_press(Message::Noop).style(outlined),
- button("Text").on_press(Message::Noop).style(text),
- button("Text Disabled").style(text),
- ]
- .spacing(10),
- column![
- container("None").padding(8),
- container("Primary").padding(8).style(primary),
- container("Primary Container")
- .padding(8)
- .style(primary_container),
- container("Secondary").padding(8).style(secondary),
- container("Secondary Container")
- .padding(8)
- .style(secondary_container),
- container("Tertiary").padding(8).style(tertiary),
- container("Tertiary Container")
- .padding(8)
- .style(tertiary_container),
- container("Error").padding(8).style(error),
- container("Error Container")
- .padding(8)
- .style(error_container),
- container("Surface").padding(8).style(surface),
- container(
- iced::widget::text("Surface Variant")
- .style(surface_variant)
+ let base: pane_grid::PaneGrid<'_, Message, Theme> =
+ pane_grid(&self.panes, |_pane, state, _is_maximized| {
+ pane_grid::Content::new(match state {
+ Pane::Left => container(
+ row![
+ column![
+ button("Disabled"),
+ button("Filled").on_press(Message::Noop),
+ button("Filled Tonal")
+ .on_press(Message::Noop)
+ .style(filled_tonal),
+ button("Elevated")
+ .on_press(Message::Noop)
+ .style(elevated),
+ button("Outlined")
+ .on_press(Message::Noop)
+ .style(outlined),
+ button("Text")
+ .on_press(Message::Noop)
+ .style(text),
+ button("Text Disabled").style(text),
+ ]
+ .spacing(10),
+ column![
+ container("None").padding(8),
+ container("Primary").padding(8).style(primary),
+ container("Primary Container")
+ .padding(8)
+ .style(primary_container),
+ container("Secondary")
+ .padding(8)
+ .style(secondary),
+ container("Secondary Container")
+ .padding(8)
+ .style(secondary_container),
+ container("Tertiary")
+ .padding(8)
+ .style(tertiary),
+ container("Tertiary Container")
+ .padding(8)
+ .style(tertiary_container),
+ container("Error").padding(8).style(error),
+ container("Error Container")
+ .padding(8)
+ .style(error_container),
+ container("Surface").padding(8).style(surface),
+ container(
+ iced::widget::text("Surface Variant")
+ .style(surface_variant)
+ )
+ .padding(8)
+ .style(surface),
+ container("Inverse Surface")
+ .padding(8)
+ .style(inverse_surface),
+ container("Surface Container Lowest")
+ .padding(8)
+ .style(surface_container_lowest),
+ container("Surface Container Low")
+ .padding(8)
+ .style(surface_container_low),
+ container("Surface Container")
+ .padding(8)
+ .style(surface_container),
+ container("Surface Container High")
+ .padding(8)
+ .style(surface_container_high),
+ container("Surface Container Highest")
+ .padding(8)
+ .style(surface_container_highest),
+ ]
+ .spacing(10),
+ ]
+ .spacing(10),
)
- .padding(8)
- .style(surface),
- container("Inverse Surface")
- .padding(8)
- .style(inverse_surface),
- container("Surface Container Lowest")
- .padding(8)
- .style(surface_container_lowest),
- container("Surface Container Low")
- .padding(8)
- .style(surface_container_low),
- container("Surface Container")
- .padding(8)
- .style(surface_container),
- container("Surface Container High")
- .padding(8)
- .style(surface_container_high),
- container("Surface Container Highest")
- .padding(8)
- .style(surface_container_highest),
- ]
- .spacing(10),
- column![
- // Pick List
- pick_list(
- [LIGHT.clone(), DARK.clone()],
- Some(self.theme.target()),
- |theme| Message::SwitchTheme(theme.into())
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .padding(12),
+
+ Pane::Right => container(
+ column![
+ // Pick List
+ pick_list(
+ [LIGHT.clone(), DARK.clone()],
+ Some(self.theme.target()),
+ |theme| Message::SwitchTheme(theme.into())
+ )
+ .placeholder("Select a theme..."),
+ horizontal_rule(1),
+ // Button
+ button("Open Dialog").on_press(Message::OpenDialog),
+ horizontal_rule(1),
+ // Text Input
+ text_input("Type something here...", &self.content)
+ .on_input(Message::Input),
+ horizontal_rule(1),
+ // Checkbox
+ checkbox("Normal", self.is_checked)
+ .on_toggle(Message::Bool),
+ checkbox("Error", self.is_checked)
+ .on_toggle(Message::Bool)
+ .style(material_theme::checkbox::error),
+ checkbox("Disabled", self.is_checked),
+ horizontal_rule(1),
+ // Radio
+ radio(
+ "A",
+ Choice::A,
+ self.selection,
+ Message::Radio,
+ ),
+ radio(
+ "B",
+ Choice::B,
+ self.selection,
+ Message::Radio,
+ ),
+ radio(
+ "C",
+ Choice::C,
+ self.selection,
+ Message::Radio,
+ ),
+ horizontal_rule(1),
+ // Slider
+ center(iced::widget::text!("{:.1}", self.value))
+ .width(Length::Fill)
+ .height(Length::Shrink),
+ slider(0.0..=100.0, self.value, Message::Slider)
+ .step(0.1),
+ horizontal_rule(1),
+ // Toggler
+ toggler(self.is_checked)
+ .on_toggle(Message::Bool)
+ .size(24.0)
+ ]
+ .spacing(10),
)
- .placeholder("Select a theme..."),
- horizontal_rule(1),
- // Button
- button("Open Dialog").on_press(Message::OpenDialog),
- horizontal_rule(1),
- // Text Input
- text_input("Type something here...", &self.content)
- .on_input(Message::Input),
- horizontal_rule(1),
- // Checkbox
- checkbox("Normal", self.is_checked)
- .on_toggle(Message::Bool),
- checkbox("Error", self.is_checked)
- .on_toggle(Message::Bool)
- .style(material_theme::checkbox::error),
- checkbox("Disabled", self.is_checked),
- horizontal_rule(1),
- // Radio
- radio("A", Choice::A, self.selection, Message::Radio,),
- radio("B", Choice::B, self.selection, Message::Radio,),
- radio("C", Choice::C, self.selection, Message::Radio,),
- horizontal_rule(1),
- // Slider
- center(iced::widget::text!("{:.1}", self.value))
- .width(Length::Fill)
- .height(Length::Shrink),
- slider(0.0..=100.0, self.value, Message::Slider).step(0.1),
- horizontal_rule(1),
- // Toggler
- toggler(self.is_checked)
- .on_toggle(Message::Bool)
- .size(24.0)
- ]
- .spacing(10)
- ]
- .spacing(20),
- )
- .width(Fill)
- .height(Fill)
- .padding(12);
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .padding(12),
+ })
+ })
+ .on_resize(10, Message::Resize);
let dialog =
dialog(self.show_dialog, base, iced::widget::text("Say Hi!"))