use teksilo_canvas::{Path, Point};
use teksilo_core::widget::Widget;
use teksilo_tokens::TextRole;
use crate::primitives::IconWidget;
const SZ: f32 = 16.0;
fn rect(p: &mut Path, x: f32, y: f32, w: f32, h: f32) {
p.move_to(Point::new(x, y));
p.line_to(Point::new(x + w, y));
p.line_to(Point::new(x + w, y + h));
p.line_to(Point::new(x, y + h));
p.close();
}
fn frame(p: &mut Path, x: f32, y: f32, w: f32, h: f32, t: f32) {
rect(p, x, y, w, t); rect(p, x, y + h - t, w, t); rect(p, x, y, t, h); rect(p, x + w - t, y, t, h); }
fn down_tri(p: &mut Path, cx: f32, cy: f32, s: f32) {
p.move_to(Point::new(cx - s, cy - s * 0.5));
p.line_to(Point::new(cx + s, cy - s * 0.5));
p.line_to(Point::new(cx, cy + s * 0.5));
p.close();
}
fn glyph(build: impl FnOnce(&mut Path)) -> Box<dyn Widget> {
let mut p = Path::new();
build(&mut p);
Box::new(IconWidget::from_path(p, SZ).color(TextRole::Secondary))
}
pub fn generic_widget_icon() -> Box<dyn Widget> {
glyph(|p| rect(p, 3.0, 3.0, 10.0, 10.0))
}
pub fn vstack() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 3.0, 3.0, 10.0, 2.5);
rect(p, 3.0, 6.75, 10.0, 2.5);
rect(p, 3.0, 10.5, 10.0, 2.5);
})
}
pub fn hstack() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 3.0, 3.0, 2.5, 10.0);
rect(p, 6.75, 3.0, 2.5, 10.0);
rect(p, 10.5, 3.0, 2.5, 10.0);
})
}
pub fn zstack() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 3.0, 3.0, 8.0, 8.0, 1.5);
frame(p, 5.0, 5.0, 8.0, 8.0, 1.5);
})
}
pub fn grid() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 3.0, 3.0, 4.5, 4.5);
rect(p, 8.5, 3.0, 4.5, 4.5);
rect(p, 3.0, 8.5, 4.5, 4.5);
rect(p, 8.5, 8.5, 4.5, 4.5);
})
}
pub fn padding() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 2.0, 12.0, 12.0, 1.5);
frame(p, 5.5, 5.5, 5.0, 5.0, 1.0);
})
}
pub fn expand() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 4.0, 7.0, 8.0, 2.0);
rect(p, 2.0, 4.0, 2.0, 8.0);
rect(p, 12.0, 4.0, 2.0, 8.0);
})
}
pub fn center() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 2.0, 12.0, 12.0, 1.0);
rect(p, 6.0, 6.0, 4.0, 4.0);
})
}
pub fn spacer() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 2.0, 7.0, 4.5, 2.0);
rect(p, 9.5, 7.0, 4.5, 2.0);
})
}
pub fn button() -> Box<dyn Widget> {
glyph(|p| rect(p, 2.0, 5.5, 12.0, 5.0))
}
pub fn text_widget() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 3.0, 4.0, 10.0, 1.6);
rect(p, 3.0, 7.2, 10.0, 1.6);
rect(p, 3.0, 10.4, 6.0, 1.6);
})
}
pub fn checkbox() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 3.0, 3.0, 10.0, 10.0, 1.5);
rect(p, 6.0, 6.0, 4.0, 4.0);
})
}
pub fn text_input() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 5.0, 12.0, 6.0, 1.2);
rect(p, 4.0, 6.5, 1.4, 3.0);
})
}
pub fn toggle() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 5.5, 12.0, 5.0, 1.2);
rect(p, 9.5, 6.5, 3.0, 3.0);
})
}
pub fn combo_box() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 5.0, 12.0, 6.0, 1.2);
down_tri(p, 11.0, 8.0, 2.0);
})
}
pub fn slider() -> Box<dyn Widget> {
glyph(|p| {
rect(p, 2.0, 7.2, 12.0, 1.6);
rect(p, 6.5, 5.0, 3.0, 6.0);
})
}
pub fn card() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 2.0, 12.0, 12.0, 1.2);
rect(p, 2.0, 2.0, 12.0, 3.0);
})
}
pub fn panel() -> Box<dyn Widget> {
glyph(|p| frame(p, 2.0, 2.0, 12.0, 12.0, 1.4))
}
pub fn scroll_area() -> Box<dyn Widget> {
glyph(|p| {
frame(p, 2.0, 2.0, 9.5, 12.0, 1.2);
rect(p, 12.5, 3.0, 1.6, 6.0);
})
}