codecraft 0.1.1

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, an immediate-mode UI, audio and gamepad haptics
Documentation
//! Whether a widget is drawn.
//!
//! A submenu exists for as long as the menu it belongs to does -- it is
//! spawned with its parent and hidden, rather than spawned on hover and
//! despawned on leave. Two reasons: a button carries a callback, which is not
//! something that can be cloned and re-made every time a pointer crosses it;
//! and a menu that builds itself on hover is a menu that allocates on hover.
//!
//! Hiding is a *field* and not a marker component, which is the other half of
//! the same argument. Adding and removing a marker moves the entity between
//! archetypes, so a pointer sliding along a menu would rebuild the table on
//! every frame it crossed a boundary -- and a queued insert can land after
//! the entity has been despawned, which is an error rather than a no-op.
//! A bool is neither of those things.
use bevy_ecs::prelude::*;

/// Whether the widget on this entity is drawn and can be interacted with.
///
/// Absent means visible: most widgets never hide, and should not have to say
/// so.
#[derive(Component, Clone, Copy, Debug, PartialEq, Eq)]
pub struct Visibility(pub bool);

impl Default for Visibility {
    fn default() -> Self {
        Self::VISIBLE
    }
}

impl Visibility {
    pub const VISIBLE: Self = Self(true);
    pub const HIDDEN: Self = Self(false);
}

/// Whether a widget with this (possibly absent) visibility is drawn.
pub fn visible(visibility: Option<&Visibility>) -> bool {
    visibility.is_none_or(|v| v.0)
}