onyx 0.2.0

A simple engine for simple minds
Documentation
extern crate onyx;

struct Scene1;
struct Scene2;
struct Scene3;

enum Action1 {
    Push2,
    Switch3,
    Quit,
}

enum Action2 {
    Pop,
}

enum Action3 {
    Switch1
}

impl onyx::Scene for Scene1 {
    type Action = Action1;

    fn new(state: &mut onyx::State<Self::Action>) -> Self {
        state.ui().build(onyx::ui::panel()
            .layout(onyx::ui::Layout::Vertical)
            .child(onyx::ui::button(|| Action1::Push2)
                .child(onyx::ui::label("Push 2"))
            )
            .child(onyx::ui::button(|| Action1::Switch3)
                .child(onyx::ui::label("Switch 3"))
            )
            .child(onyx::ui::button(|| Action1::Quit)
                .child(onyx::ui::label("Quit"))
            )
        );
        Scene1
    }

    fn action(&mut self, action: Self::Action, state: &mut onyx::State<Self::Action>) -> onyx::Transition {
        match action {
            Action1::Push2 => state.push::<Scene2>(),
            Action1::Switch3 => state.switch::<Scene3>(),
            Action1::Quit => state.quit(),
        }
    }
}

impl onyx::Scene for Scene2 {
    type Action = Action2;

    fn new(state: &mut onyx::State<Self::Action>) -> Self {
        state.ui().build(onyx::ui::panel()
            .layout(onyx::ui::Layout::Vertical)
            .child(onyx::ui::button(|| Action2::Pop)
                .child(onyx::ui::label("Pop"))
            )
        );
        Scene2
    }

    fn action(&mut self, action: Self::Action, state: &mut onyx::State<Self::Action>) -> onyx::Transition {
        match action {
            Action2::Pop => state.pop(),
        }
    }
}

impl onyx::Scene for Scene3 {
    type Action = Action3;

    fn new(state: &mut onyx::State<Self::Action>) -> Self {
        state.ui().build(onyx::ui::panel()
            .layout(onyx::ui::Layout::Vertical)
            .child(onyx::ui::button(|| Action3::Switch1)
                .child(onyx::ui::label("Switch 1"))
            )
        );
        Scene3
    }

    fn action(&mut self, action: Self::Action, state: &mut onyx::State<Self::Action>) -> onyx::Transition {
        match action {
            Action3::Switch1 => state.switch::<Scene1>(),
        }
    }
}

fn main() {
    onyx::run::<Scene1>("Transition", (800, 600))
}