pub mod prelude {
pub use super::{
Board, Card, CENTER, MIDDLE, Row, Text, TextTimer, VIEWPORT_HEIGHT, VIEWPORT_WIDTH, World,
Widget, IntoWidget, Girl, HairColor, SkinColor, BodyType, Appearance, GirlActions,
HAlign, VAlign,
};
pub use snow_ui_macros::IntoWidget;
#[allow(dead_code)]
pub fn default<T: Default>() -> T {
T::default()
}
}
pub fn launch<F: FnOnce() -> World>(builder: F) {
let world = builder();
println!("Launching snow_ui with world:\n{:#?}", world);
}
#[allow(dead_code)]
#[derive(Debug)]
pub struct World {
pub root: Widget,
}
impl Default for World {
fn default() -> Self {
Self {
root: Widget::Board(Board::default()),
}
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub struct Board {
pub width: Size,
pub height: Size,
pub h_align: HAlign,
pub v_align: VAlign,
pub children: Vec<Card>,
}
impl Default for Board {
fn default() -> Self {
Self {
width: VIEWPORT_WIDTH,
height: VIEWPORT_HEIGHT,
h_align: HAlign::Center,
v_align: VAlign::Middle,
children: vec![],
}
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub struct Card {
pub children: Vec<Row>,
}
impl Default for Card {
fn default() -> Self {
Self { children: vec![] }
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub struct Row {
pub children: Vec<Element>,
}
impl Default for Row {
fn default() -> Self {
Self { children: vec![] }
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub enum Element {
Text(Text),
TextTimer(TextTimer),
}
#[allow(dead_code)]
#[derive(Debug)]
pub struct Text {
pub text: &'static str,
}
impl Text {
pub fn from_str(s: &'static str) -> Element {
Element::Text(Text { text: s })
}
}
impl Default for Text {
fn default() -> Self {
Self { text: "" }
}
}
impl From<Text> for Element {
fn from(t: Text) -> Self {
Element::Text(t)
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub struct TextTimer {
pub format: &'static str,
}
impl From<TextTimer> for Element {
fn from(t: TextTimer) -> Self {
Element::TextTimer(t)
}
}
impl TextTimer {
pub fn with_format(format: &'static str) -> Element {
Element::TextTimer(TextTimer { format })
}
}
impl Default for TextTimer {
fn default() -> Self {
Self { format: "" }
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum Size {
ViewportWidth,
ViewportHeight,
}
pub const VIEWPORT_WIDTH: Size = Size::ViewportWidth;
pub const VIEWPORT_HEIGHT: Size = Size::ViewportHeight;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum HAlign {
Left,
Center,
Right,
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum VAlign {
Top,
Middle,
Bottom,
}
pub const CENTER: HAlign = HAlign::Center;
pub const MIDDLE: VAlign = VAlign::Middle;
#[allow(dead_code)]
#[derive(Debug)]
pub enum Widget {
Board(Board),
Girl(Girl),
}
impl From<Board> for Widget {
fn from(b: Board) -> Self {
Widget::Board(b)
}
}
impl From<Girl> for Widget {
fn from(g: Girl) -> Self {
Widget::Girl(g)
}
}
pub trait IntoWidget {
fn into_widget(self) -> Widget;
}
impl<T: IntoWidget> From<T> for Widget {
fn from(t: T) -> Self {
t.into_widget()
}
}
#[allow(dead_code)]
#[derive(Debug, Default)]
pub struct Girl {
pub hair_color: HairColor,
pub skin_color: SkinColor,
pub body_type: BodyType,
pub appearance: Appearance,
pub every_morning: Vec<GirlActions>,
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum HairColor {
Black,
Brown,
Blonde,
Red,
}
impl Default for HairColor {
fn default() -> Self {
HairColor::Brown
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum SkinColor {
Yellow,
Light,
Dark,
}
impl Default for SkinColor {
fn default() -> Self {
SkinColor::Light
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum BodyType {
Slim,
Average,
Curvy,
}
impl Default for BodyType {
fn default() -> Self {
BodyType::Average
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum Appearance {
Beautiful,
Cute,
Plain,
}
impl Default for Appearance {
fn default() -> Self {
Appearance::Cute
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub enum GirlActions {
SayHi,
PrepareBreakfast,
}