summaryrefslogtreecommitdiffstats
path: root/src/sandbox.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sandbox.rs')
-rw-r--r--src/sandbox.rs70
1 files changed, 42 insertions, 28 deletions
diff --git a/src/sandbox.rs b/src/sandbox.rs
index 2306c650..bdb6ad5a 100644
--- a/src/sandbox.rs
+++ b/src/sandbox.rs
@@ -1,6 +1,5 @@
-use crate::{
- Application, Color, Command, Element, Error, Settings, Subscription,
-};
+use crate::theme::{self, Theme};
+use crate::{Application, Command, Element, Error, Settings, Subscription};
/// A sandboxed [`Application`].
///
@@ -35,19 +34,19 @@ use crate::{
/// - [`tour`], a simple UI tour that can run both on native platforms and the
/// web!
///
-/// [The repository has a bunch of examples]: https://github.com/hecrj/iced/tree/0.3/examples
-/// [`bezier_tool`]: https://github.com/hecrj/iced/tree/0.3/examples/bezier_tool
-/// [`counter`]: https://github.com/hecrj/iced/tree/0.3/examples/counter
-/// [`custom_widget`]: https://github.com/hecrj/iced/tree/0.3/examples/custom_widget
-/// [`geometry`]: https://github.com/hecrj/iced/tree/0.3/examples/geometry
-/// [`pane_grid`]: https://github.com/hecrj/iced/tree/0.3/examples/pane_grid
-/// [`progress_bar`]: https://github.com/hecrj/iced/tree/0.3/examples/progress_bar
-/// [`styling`]: https://github.com/hecrj/iced/tree/0.3/examples/styling
-/// [`svg`]: https://github.com/hecrj/iced/tree/0.3/examples/svg
-/// [`tour`]: https://github.com/hecrj/iced/tree/0.3/examples/tour
+/// [The repository has a bunch of examples]: https://github.com/iced-rs/iced/tree/0.4/examples
+/// [`bezier_tool`]: https://github.com/iced-rs/iced/tree/0.4/examples/bezier_tool
+/// [`counter`]: https://github.com/iced-rs/iced/tree/0.4/examples/counter
+/// [`custom_widget`]: https://github.com/iced-rs/iced/tree/0.4/examples/custom_widget
+/// [`geometry`]: https://github.com/iced-rs/iced/tree/0.4/examples/geometry
+/// [`pane_grid`]: https://github.com/iced-rs/iced/tree/0.4/examples/pane_grid
+/// [`progress_bar`]: https://github.com/iced-rs/iced/tree/0.4/examples/progress_bar
+/// [`styling`]: https://github.com/iced-rs/iced/tree/0.4/examples/styling
+/// [`svg`]: https://github.com/iced-rs/iced/tree/0.4/examples/svg
+/// [`tour`]: https://github.com/iced-rs/iced/tree/0.4/examples/tour
/// [`Canvas widget`]: crate::widget::Canvas
/// [the overview]: index.html#overview
-/// [`iced_wgpu`]: https://github.com/hecrj/iced/tree/0.3/wgpu
+/// [`iced_wgpu`]: https://github.com/iced-rs/iced/tree/0.4/wgpu
/// [`Svg` widget]: crate::widget::Svg
/// [Ghostscript Tiger]: https://commons.wikimedia.org/wiki/File:Ghostscript_Tiger.svg
///
@@ -57,7 +56,7 @@ use crate::{
/// says "Hello, world!":
///
/// ```no_run
-/// use iced::{Element, Sandbox, Settings, Text};
+/// use iced::{Element, Sandbox, Settings};
///
/// pub fn main() -> iced::Result {
/// Hello::run(Settings::default())
@@ -80,8 +79,8 @@ use crate::{
/// // This application has no interactions
/// }
///
-/// fn view(&mut self) -> Element<Self::Message> {
-/// Text::new("Hello, world!").into()
+/// fn view(&self) -> Element<Self::Message> {
+/// "Hello, world!".into()
/// }
/// }
/// ```
@@ -109,13 +108,23 @@ pub trait Sandbox {
/// Returns the widgets to display in the [`Sandbox`].
///
/// These widgets can produce __messages__ based on user interaction.
- fn view(&mut self) -> Element<'_, Self::Message>;
+ fn view(&self) -> Element<'_, Self::Message>;
- /// Returns the background color of the [`Sandbox`].
+ /// Returns the current [`Theme`] of the [`Sandbox`].
///
- /// By default, it returns [`Color::WHITE`].
- fn background_color(&self) -> Color {
- Color::WHITE
+ /// If you want to use your own custom theme type, you will have to use an
+ /// [`Application`].
+ ///
+ /// By default, it returns [`Theme::default`].
+ fn theme(&self) -> Theme {
+ Theme::default()
+ }
+
+ /// Returns the current style variant of [`theme::Application`].
+ ///
+ /// By default, it returns [`theme::Application::default`].
+ fn style(&self) -> theme::Application {
+ theme::Application::default()
}
/// Returns the scale factor of the [`Sandbox`].
@@ -159,6 +168,7 @@ where
type Executor = iced_futures::backend::null::Executor;
type Flags = ();
type Message = T::Message;
+ type Theme = Theme;
fn new(_flags: ()) -> (Self, Command<T::Message>) {
(T::new(), Command::none())
@@ -174,16 +184,20 @@ where
Command::none()
}
- fn subscription(&self) -> Subscription<T::Message> {
- Subscription::none()
+ fn view(&self) -> Element<'_, T::Message> {
+ T::view(self)
}
- fn view(&mut self) -> Element<'_, T::Message> {
- T::view(self)
+ fn theme(&self) -> Self::Theme {
+ T::theme(self)
+ }
+
+ fn style(&self) -> theme::Application {
+ T::style(self)
}
- fn background_color(&self) -> Color {
- T::background_color(self)
+ fn subscription(&self) -> Subscription<T::Message> {
+ Subscription::none()
}
fn scale_factor(&self) -> f64 {