use std::process::ExitCode;
use smudge_core::geometry::{Color, Size};
use smudge_core::reactive::RwSignal;
use smudge_core::reactive::prelude::*;
use smudge_core::style::{Align, Length, px};
use smudge_core::theme::Theme;
use smudge_core::widget::panel;
use smudge_platform::{WindowOptions, run_with};
use smudge_text::TextInputExt;
use smudge_text::label;
use smudge_text::text_input;
use smudge_widgets::ButtonExt;
use smudge_widgets::button;
use smudge_widgets::column;
use smudge_widgets::scroll;
const FIELD_HEIGHT: f32 = 32.0;
const VIEW_HEIGHT: f32 = 180.0;
fn main() -> ExitCode {
let build = || {
let clicks = RwSignal::new(0u32);
let typed = RwSignal::new(String::new());
let press_clicks = clicks.clone();
let reset_clicks = clicks.clone();
let read_clicks = clicks.clone();
let read_typed = typed.clone();
panel()
.padding(px(24.0))
.gap(Size {
width: 0.0,
height: 16.0,
})
.align_items(Align::Start)
.background(Color::rgb(24, 26, 32))
.child(
button("Press me")
.primary()
.on_press(move || press_clicks.update(|count| *count += 1)),
)
.child(button("Reset").on_press(move || reset_clicks.set(0)))
.child(label(move || format!("Clicks: {}", read_clicks.get())))
.child(
text_input(typed)
.width(Length::pct(100.0))
.height(px(FIELD_HEIGHT))
.placeholder("Type here")
.padding(px(8.0))
.border(1.0)
.border_color(Color::rgb(70, 74, 88)),
)
.child(label(move || {
if read_typed.get().is_empty() {
String::from("The field is empty")
} else {
format!("You typed: {}", read_typed.get())
}
}))
.child(
scroll(
column()
.gap(Size {
width: 0.0,
height: 4.0,
})
.children((1..=12).map(|index| {
label(move || format!("List item {index} of 12"))
.height(px(28.0))
.padding(px(4.0))
})),
)
.height(px(VIEW_HEIGHT))
.width(Length::pct(100.0)),
)
};
let result = run_with(
WindowOptions {
title: String::from("Smudge controls"),
size: Size {
width: 420.0,
height: 480.0,
},
clear_color: Color::rgb(16, 17, 21),
..WindowOptions::default()
},
build,
|app| app.set_theme(Theme::dark()),
);
match result {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
eprintln!("smudge: {error}");
ExitCode::FAILURE
}
}
}