Make sandbox helper take a title as well

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 16:12:07 +01:00
parent 3f81c524cc
commit bb71e8481e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
21 changed files with 64 additions and 58 deletions

View file

@ -7,8 +7,7 @@ use iced::widget::canvas::{
use iced::{Element, Length, Point, Rectangle, Renderer, Subscription, Theme}; use iced::{Element, Length, Point, Rectangle, Renderer, Subscription, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Arc::update, Arc::view) iced::sandbox("Arc - Iced", Arc::update, Arc::view)
.title("Arc - Iced")
.subscription(Arc::subscription) .subscription(Arc::subscription)
.theme(|_| Theme::Dark) .theme(|_| Theme::Dark)
.antialiased() .antialiased()

View file

@ -3,8 +3,7 @@ use iced::widget::{button, column, text};
use iced::{Alignment, Element, Length}; use iced::{Alignment, Element, Length};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Example::update, Example::view) iced::sandbox("Bezier Tool - Iced", Example::update, Example::view)
.title("Bezier tool - Iced")
.antialiased() .antialiased()
.run() .run()
} }

View file

@ -4,8 +4,7 @@ use iced::{Element, Font, Length};
const ICON_FONT: Font = Font::with_name("icons"); const ICON_FONT: Font = Font::with_name("icons");
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Example::update, Example::view) iced::sandbox("Checkbox - Iced", Example::update, Example::view)
.title("Checkbox - Iced")
.fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()]) .fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()])
.run() .run()
} }

View file

@ -6,8 +6,7 @@ use iced::{
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Clock::update, Clock::view) iced::sandbox("Clock - Iced", Clock::update, Clock::view)
.title("Clock - Iced")
.subscription(Clock::subscription) .subscription(Clock::subscription)
.theme(Clock::theme) .theme(Clock::theme)
.antialiased() .antialiased()

View file

@ -13,12 +13,15 @@ use std::marker::PhantomData;
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(ColorPalette::update, ColorPalette::view) iced::sandbox(
.theme(ColorPalette::theme) "Color Palette - Iced",
.title("Color Palette - Iced") ColorPalette::update,
.default_font(Font::MONOSPACE) ColorPalette::view,
.antialiased() )
.run() .theme(ColorPalette::theme)
.default_font(Font::MONOSPACE)
.antialiased()
.run()
} }
#[derive(Default)] #[derive(Default)]

View file

@ -9,9 +9,8 @@ use iced::window;
use iced::{Alignment, Color, Element, Length, Subscription}; use iced::{Alignment, Color, Element, Length, Subscription};
fn main() -> iced::Result { fn main() -> iced::Result {
iced::sandbox(IcedCubes::update, IcedCubes::view) iced::sandbox("Custom Shader - Iced", IcedCubes::update, IcedCubes::view)
.subscription(IcedCubes::subscription) .subscription(IcedCubes::subscription)
.title("Custom Shader - Iced")
.run() .run()
} }

View file

@ -4,9 +4,8 @@ use iced::widget::{button, column, container, progress_bar, text, Column};
use iced::{Alignment, Element, Length, Subscription}; use iced::{Alignment, Element, Length, Subscription};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Example::update, Example::view) iced::sandbox("Download Progress - Iced", Example::update, Example::view)
.subscription(Example::subscription) .subscription(Example::subscription)
.title("Download Progress - Iced")
.run() .run()
} }

View file

@ -10,8 +10,7 @@ use iced::{
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Layout::update, Layout::view) iced::sandbox(Layout::title, Layout::update, Layout::view)
.title(Layout::title)
.subscription(Layout::subscription) .subscription(Layout::subscription)
.theme(Layout::theme) .theme(Layout::theme)
.run() .run()

View file

@ -11,10 +11,13 @@ use circular::Circular;
use linear::Linear; use linear::Linear;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(LoadingSpinners::update, LoadingSpinners::view) iced::sandbox(
.title("Loading Spinners - Iced") "Loading Spinners - Iced",
.antialiased() LoadingSpinners::update,
.run() LoadingSpinners::view,
)
.antialiased()
.run()
} }
struct LoadingSpinners { struct LoadingSpinners {

View file

@ -13,8 +13,7 @@ use std::collections::HashMap;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
iced::sandbox(Multitouch::update, Multitouch::view) iced::sandbox("Multitouch - Iced", Multitouch::update, Multitouch::view)
.title("Multitouch - Iced")
.antialiased() .antialiased()
.centered() .centered()
.run() .run()

View file

@ -7,9 +7,8 @@ use iced::widget::{
use iced::{Color, Element, Length, Size, Subscription}; use iced::{Color, Element, Length, Size, Subscription};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Example::update, Example::view) iced::sandbox("Pane Grid - Iced", Example::update, Example::view)
.subscription(Example::subscription) .subscription(Example::subscription)
.title("Pane Grid - Iced")
.run() .run()
} }

View file

@ -4,10 +4,13 @@ use iced::widget::{
use iced::{Alignment, Element, Length, Theme}; use iced::{Alignment, Element, Length, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(QRGenerator::update, QRGenerator::view) iced::sandbox(
.title("QR Code Generator - Iced") "QR Code Generator - Iced",
.theme(QRGenerator::theme) QRGenerator::update,
.run() QRGenerator::view,
)
.theme(QRGenerator::theme)
.run()
} }
#[derive(Default)] #[derive(Default)]

View file

@ -8,10 +8,13 @@ use rand::Rng;
use std::fmt::Debug; use std::fmt::Debug;
fn main() -> iced::Result { fn main() -> iced::Result {
iced::sandbox(SierpinskiEmulator::update, SierpinskiEmulator::view) iced::sandbox(
.title("Sierpinski Triangle - Iced") "Sierpinski Triangle - Iced",
.antialiased() SierpinskiEmulator::update,
.run() SierpinskiEmulator::view,
)
.antialiased()
.run()
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]

View file

@ -22,11 +22,14 @@ use std::time::Instant;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
iced::sandbox(SolarSystem::update, SolarSystem::view) iced::sandbox(
.subscription(SolarSystem::subscription) "Solar System - Iced",
.theme(SolarSystem::theme) SolarSystem::update,
.title("Solar System - Iced") SolarSystem::view,
.run() )
.subscription(SolarSystem::subscription)
.theme(SolarSystem::theme)
.run()
} }
#[derive(Default)] #[derive(Default)]

View file

@ -7,10 +7,9 @@ use iced::{Alignment, Element, Length, Subscription, Theme};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Stopwatch::update, Stopwatch::view) iced::sandbox("Stopwatch - Iced", Stopwatch::update, Stopwatch::view)
.subscription(Stopwatch::subscription) .subscription(Stopwatch::subscription)
.theme(Stopwatch::theme) .theme(Stopwatch::theme)
.title("Stopwatch - Iced")
.run() .run()
} }

View file

@ -6,9 +6,8 @@ use iced::widget::{
use iced::{Alignment, Element, Length, Theme}; use iced::{Alignment, Element, Length, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(Styling::update, Styling::view) iced::sandbox("Styling - Iced", Styling::update, Styling::view)
.theme(Styling::theme) .theme(Styling::theme)
.title("Styling - Iced")
.run() .run()
} }

View file

@ -16,8 +16,7 @@ pub fn main() -> iced::Result {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
iced::sandbox(Tour::update, Tour::view) iced::sandbox(Tour::title, Tour::update, Tour::view)
.title(Tour::title)
.centered() .centered()
.run() .run()
} }

View file

@ -3,9 +3,8 @@ use iced::widget::{container, text};
use iced::{Element, Length, Subscription}; use iced::{Element, Length, Subscription};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(App::update, App::view) iced::sandbox("URL Handler - Iced", App::update, App::view)
.subscription(App::subscription) .subscription(App::subscription)
.title("URL Handler - Iced")
.run() .run()
} }

View file

@ -6,11 +6,14 @@ use iced::widget::{
use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector}; use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox(VectorialText::update, VectorialText::view) iced::sandbox(
.theme(|_| Theme::Dark) "Vectorial Text - Iced",
.title("Vectorial Text - Iced") VectorialText::update,
.antialiased() VectorialText::view,
.run() )
.theme(|_| Theme::Dark)
.antialiased()
.run()
} }
#[derive(Default)] #[derive(Default)]

View file

@ -370,7 +370,7 @@ where
State: Default + 'static, State: Default + 'static,
Message: std::fmt::Debug + Send + 'static, Message: std::fmt::Debug + Send + 'static,
{ {
sandbox(update, view).title(title).run() sandbox(title, update, view).run()
} }
#[doc(inline)] #[doc(inline)]

View file

@ -15,8 +15,7 @@
//! use iced::Theme; //! use iced::Theme;
//! //!
//! pub fn main() -> iced::Result { //! pub fn main() -> iced::Result {
//! iced::sandbox(update, view) //! iced::sandbox("A counter", update, view)
//! .title("A counter")
//! .theme(|_| Theme::Dark) //! .theme(|_| Theme::Dark)
//! .centered() //! .centered()
//! .run() //! .run()
@ -54,7 +53,7 @@ use std::borrow::Cow;
/// use iced::widget::{button, column, text, Column}; /// use iced::widget::{button, column, text, Column};
/// ///
/// pub fn main() -> iced::Result { /// pub fn main() -> iced::Result {
/// iced::sandbox(update, view).title("A counter").run() /// iced::sandbox("A counter", update, view).run()
/// } /// }
/// ///
/// #[derive(Debug, Clone)] /// #[derive(Debug, Clone)]
@ -76,6 +75,7 @@ use std::borrow::Cow;
/// } /// }
/// ``` /// ```
pub fn sandbox<State, Message>( pub fn sandbox<State, Message>(
title: impl Title<State>,
update: impl Fn(&mut State, Message), update: impl Fn(&mut State, Message),
view: impl for<'a> self::View<'a, State, Message>, view: impl for<'a> self::View<'a, State, Message>,
) -> Program< ) -> Program<
@ -138,6 +138,7 @@ where
}, },
settings: Settings::default(), settings: Settings::default(),
} }
.title(title)
} }
/// Creates a [`Program`] that can leverage the [`Command`] API for /// Creates a [`Program`] that can leverage the [`Command`] API for