diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/gradient/Cargo.toml | 5 | ||||
| -rw-r--r-- | examples/gradient/src/main.rs | 55 | ||||
| -rw-r--r-- | examples/solar_system/src/main.rs | 2 | 
3 files changed, 55 insertions, 7 deletions
diff --git a/examples/gradient/Cargo.toml b/examples/gradient/Cargo.toml index 2dea2c4f..8102b866 100644 --- a/examples/gradient/Cargo.toml +++ b/examples/gradient/Cargo.toml @@ -5,4 +5,7 @@ edition = "2021"  publish = false  [dependencies] -iced = { path = "../.." } +iced.workspace = true +iced.features = ["debug"] + +tracing-subscriber = "0.3" diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 1bf5822d..32b2e4aa 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,11 +1,23 @@ -use iced::gradient; -use iced::widget::{column, container, horizontal_space, row, slider, text}; +use iced::application; +use iced::theme::{self, Theme}; +use iced::widget::{ +    checkbox, column, container, horizontal_space, row, slider, text, +}; +use iced::{gradient, window};  use iced::{      Alignment, Background, Color, Element, Length, Radians, Sandbox, Settings,  };  pub fn main() -> iced::Result { -    Gradient::run(Settings::default()) +    tracing_subscriber::fmt::init(); + +    Gradient::run(Settings { +        window: window::Settings { +            transparent: true, +            ..Default::default() +        }, +        ..Default::default() +    })  }  #[derive(Debug, Clone, Copy)] @@ -13,6 +25,7 @@ struct Gradient {      start: Color,      end: Color,      angle: Radians, +    transparent: bool,  }  #[derive(Debug, Clone, Copy)] @@ -20,6 +33,7 @@ enum Message {      StartChanged(Color),      EndChanged(Color),      AngleChanged(Radians), +    TransparentToggled(bool),  }  impl Sandbox for Gradient { @@ -30,6 +44,7 @@ impl Sandbox for Gradient {              start: Color::WHITE,              end: Color::new(0.0, 0.0, 1.0, 1.0),              angle: Radians(0.0), +            transparent: false,          }      } @@ -42,11 +57,19 @@ impl Sandbox for Gradient {              Message::StartChanged(color) => self.start = color,              Message::EndChanged(color) => self.end = color,              Message::AngleChanged(angle) => self.angle = angle, +            Message::TransparentToggled(transparent) => { +                self.transparent = transparent; +            }          }      }      fn view(&self) -> Element<Message> { -        let Self { start, end, angle } = *self; +        let Self { +            start, +            end, +            angle, +            transparent, +        } = *self;          let gradient_box = container(horizontal_space(Length::Fill))              .width(Length::Fill) @@ -72,14 +95,34 @@ impl Sandbox for Gradient {          .padding(8)          .align_items(Alignment::Center); +        let transparency_toggle = iced::widget::Container::new( +            checkbox("Transparent window", transparent) +                .on_toggle(Message::TransparentToggled), +        ) +        .padding(8); +          column![              color_picker("Start", self.start).map(Message::StartChanged),              color_picker("End", self.end).map(Message::EndChanged),              angle_picker, -            gradient_box +            transparency_toggle, +            gradient_box,          ]          .into()      } + +    fn style(&self) -> theme::Application { +        if self.transparent { +            theme::Application::custom(|theme: &Theme| { +                application::Appearance { +                    background_color: Color::TRANSPARENT, +                    text_color: theme.palette().text, +                } +            }) +        } else { +            theme::Application::Default +        } +    }  }  fn color_picker(label: &str, color: Color) -> Element<'_, Color> { @@ -91,6 +134,8 @@ fn color_picker(label: &str, color: Color) -> Element<'_, Color> {              .step(0.01),          slider(0.0..=1.0, color.b, move |b| { Color { b, ..color } })              .step(0.01), +        slider(0.0..=1.0, color.a, move |a| { Color { a, ..color } }) +            .step(0.01),      ]      .spacing(8)      .padding(8) diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 82421a86..a58ca683 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -88,7 +88,7 @@ impl Application for SolarSystem {              }          } -        theme::Application::from(dark_background as fn(&Theme) -> _) +        theme::Application::custom(dark_background)      }      fn subscription(&self) -> Subscription<Message> {  | 
