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};
pub fn main() -> iced::Result {
iced::sandbox(Arc::update, Arc::view)
.title("Arc - Iced")
iced::sandbox("Arc - Iced", Arc::update, Arc::view)
.subscription(Arc::subscription)
.theme(|_| Theme::Dark)
.antialiased()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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