1
1
Fork 0
mirror of https://github.com/griffi-gh/kubi.git synced 2025-03-16 11:56:27 -05:00
kubi/kubi-ui/src/lib.rs

86 lines
1.8 KiB
Rust
Raw Normal View History

2023-11-21 07:08:22 -06:00
use std::collections::VecDeque;
use glam::Vec2;
pub mod element;
pub mod event;
pub mod draw;
pub mod backend;
pub mod measure;
pub mod state;
2023-11-22 04:56:46 -06:00
use element::UiElement;
2023-11-21 07:08:22 -06:00
use state::StateRepo;
2023-11-22 04:56:46 -06:00
use event::UiEvent;
use draw::{UiDrawCommands, UiDrawPlan};
2023-11-21 07:08:22 -06:00
pub struct KubiUi {
mouse_position: Vec2,
stateful_state: StateRepo,
2023-11-22 04:56:46 -06:00
event_queue: VecDeque<UiEvent>,
prev_draw_commands: UiDrawCommands,
draw_commands: UiDrawCommands,
draw_plan: UiDrawPlan,
draw_plan_modified: bool,
2023-11-21 07:08:22 -06:00
}
impl KubiUi {
pub fn new() -> Self {
KubiUi {
mouse_position: Vec2::ZERO,
stateful_state: StateRepo::default(),
event_queue: VecDeque::new(),
2023-11-22 04:56:46 -06:00
// root_elements: Vec::new(),
prev_draw_commands: UiDrawCommands::default(),
draw_commands: UiDrawCommands::default(),
draw_plan: UiDrawPlan::default(),
draw_plan_modified: false,
2023-11-21 07:08:22 -06:00
}
}
2023-11-22 04:56:46 -06:00
pub fn begin(&mut self) {
std::mem::swap(&mut self.prev_draw_commands, &mut self.draw_commands);
self.draw_plan_modified = false;
self.draw_commands.commands.clear();
}
pub fn end(&mut self) {
if self.draw_commands.commands == self.prev_draw_commands.commands {
return
}
self.draw_plan = UiDrawPlan::build(&self.draw_commands);
self.draw_plan_modified = true;
}
pub fn draw_plan(&self) -> (bool, &UiDrawPlan) {
(self.draw_plan_modified, &self.draw_plan)
}
2023-11-21 07:08:22 -06:00
}
impl Default for KubiUi {
fn default() -> Self {
Self::new()
}
}
2023-11-21 09:14:26 -06:00
#[derive(Default)]
2023-11-21 07:08:22 -06:00
pub enum UiSize {
2023-11-21 09:14:26 -06:00
#[default]
2023-11-21 07:08:22 -06:00
Auto,
Percentage(f32),
Pixels(f32),
}
2023-11-21 09:14:26 -06:00
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
2023-11-21 07:08:22 -06:00
pub enum UiDirection {
#[default]
Vertical,
Horizontal,
}
struct LayoutInfo {
2023-11-21 09:14:26 -06:00
///Not availabe during measuring step
2023-11-21 07:08:22 -06:00
position: Vec2,
max_size: Vec2,
direction: UiDirection,
}