Introduce Program API

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 05:33:47 +01:00
parent 0524e9b457
commit c22269bff3
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
43 changed files with 1141 additions and 831 deletions

View file

@ -82,12 +82,10 @@ mod quad {
}
use iced::widget::{column, container, slider, text};
use iced::{
Alignment, Color, Element, Length, Sandbox, Settings, Shadow, Vector,
};
use iced::{Alignment, Color, Element, Length, Shadow, Vector};
pub fn main() -> iced::Result {
Example::run(Settings::default())
iced::run("Custom Quad - Iced", Example::update, Example::view)
}
struct Example {
@ -109,9 +107,7 @@ enum Message {
ShadowBlurRadiusChanged(f32),
}
impl Sandbox for Example {
type Message = Message;
impl Example {
fn new() -> Self {
Self {
radius: [50.0; 4],
@ -124,10 +120,6 @@ impl Sandbox for Example {
}
}
fn title(&self) -> String {
String::from("Custom widget - Iced")
}
fn update(&mut self, message: Message) {
let [tl, tr, br, bl] = self.radius;
match message {
@ -203,3 +195,9 @@ impl Sandbox for Example {
.into()
}
}
impl Default for Example {
fn default() -> Self {
Self::new()
}
}