use crate::vdom::{Event, VElement};
pub const DEFAULT_BACKGROUND: u32 = 0xF7_F8_FA_FF;
pub const fn background_rgba(color: u32) -> (u8, u8, u8, u8) {
(
(color >> 24) as u8,
(color >> 16) as u8,
(color >> 8) as u8,
color as u8,
)
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WindowConfig {
pub title: String,
pub width: u32,
pub height: u32,
pub background: u32,
pub resizable: bool,
pub transparent: bool,
pub min_width: Option<u32>,
pub min_height: Option<u32>,
pub max_width: Option<u32>,
pub max_height: Option<u32>,
pub modal: bool,
pub visible: bool,
pub id: Option<String>,
pub parent: Option<String>,
}
impl WindowConfig {
pub const fn background_rgba(&self) -> (u8, u8, u8, u8) {
background_rgba(self.background)
}
}
impl Default for WindowConfig {
fn default() -> Self {
Self {
title: String::from("Light"),
width: 640,
height: 480,
background: DEFAULT_BACKGROUND,
resizable: true,
transparent: false,
min_width: None,
min_height: None,
max_width: None,
max_height: None,
modal: false,
visible: true,
id: None,
parent: None,
}
}
}
pub trait Component {
fn render(&self) -> VElement;
fn dispatch(&self, key: &str, event: Event) -> bool {
let _ = (key, event);
false
}
fn validate_field(&self, field: &str, value: &str) -> Result<(), String> {
let _ = (field, value);
Ok(())
}
fn validate_form(&self, form: &str) -> Option<Vec<(String, String)>> {
let _ = form;
None
}
fn is_maximized(&self) -> bool {
crate::control::is_maximized()
}
fn close(&self) {
crate::control::request(crate::control::WindowCommand::Close);
}
fn minimize(&self) {
crate::control::request(crate::control::WindowCommand::Minimize);
}
fn toggle_maximize(&self) {
crate::control::request(crate::control::WindowCommand::ToggleMaximize);
}
fn window_config(&self) -> Option<WindowConfig> {
self.render().window_config().cloned()
}
fn modal(&self) -> Option<Box<dyn Component>> {
None
}
fn window_factory(&self) -> Option<Box<dyn Component>> {
None
}
fn windows(&self) -> Vec<fn() -> Box<dyn Component>> {
Vec::new()
}
}