vert 0.1.1

The 51th Rust Game Engine, to write the 6th Game in Rust
Documentation
use crate::modules::input::PressState;

use super::board::{Board, ContainerId, HotActive, Id};

mod button;
pub use button::Button;

mod fill;
pub use fill::{h_fill, v_fill};

mod slider;
pub use slider::Slider;

pub trait Widget {
    /// lifetime to allow mutable entries inserted into the hashmap be returned.
    /// allows editing of e.g. a widgets style based on the response in the same frame.
    type Response<'a>;

    /// this is an immediate mode API, so this function just adds some divs containing other divs or text to the Board.
    fn add_to_board(
        self,
        board: &mut Board,
        id: Id,
        parent: Option<ContainerId>,
    ) -> Self::Response<'_>;
}

/// Shout out to Casey Muratori, our lord and savior. (See this Video as well for an exmplanation: https://www.youtube.com/watch?v=geZwWo-qNR4)
pub fn next_hot_active(
    hot_active: HotActive,
    mouse_in_rect: bool,
    button_press: PressState,
) -> HotActive {
    use HotActive::*;

    match hot_active {
        Nil => {
            if mouse_in_rect {
                Hot
            } else {
                Nil
            }
        }
        Hot => {
            if mouse_in_rect {
                if button_press.just_pressed() {
                    Active
                } else {
                    Hot
                }
            } else {
                Nil
            }
        }
        Active => {
            if button_press.just_released() {
                if mouse_in_rect {
                    Hot
                } else {
                    Nil
                }
            } else {
                Active
            }
        }
    }
}