From cf56bf29fe11498f94e154a125dac8754a294213 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 23 Nov 2023 11:10:42 +0100 Subject: [PATCH] restructure stuff --- kubi-ui/src/backend/glium.rs | 12 +++++++----- kubi-ui/src/element.rs | 13 +++++++++---- kubi-ui/src/element/{ => builtin}/container.rs | 11 +++++++++-- kubi-ui/src/element/{ => builtin}/progress_bar.rs | 4 ++-- kubi-ui/src/element/{ => builtin}/rect.rs | 10 ++++++++-- kubi-ui/src/element/{ => builtin}/spacer.rs | 10 ++++++++-- 6 files changed, 43 insertions(+), 17 deletions(-) rename kubi-ui/src/element/{ => builtin}/container.rs (96%) rename kubi-ui/src/element/{ => builtin}/progress_bar.rs (97%) rename kubi-ui/src/element/{ => builtin}/rect.rs (90%) rename kubi-ui/src/element/{ => builtin}/spacer.rs (80%) diff --git a/kubi-ui/src/backend/glium.rs b/kubi-ui/src/backend/glium.rs index be55c95..8c886e4 100644 --- a/kubi-ui/src/backend/glium.rs +++ b/kubi-ui/src/backend/glium.rs @@ -48,8 +48,9 @@ impl BufferPair { } pub fn ensure_buffer_size(&mut self, need_vtx: usize, need_idx: usize) { - let current_vtx_size = self.vertex_buffer.get_size(); - let current_idx_size = self.index_buffer.get_size(); + let current_vtx_size = self.vertex_buffer.get_size() / std::mem::size_of::(); + let current_idx_size = self.index_buffer.get_size() / std::mem::size_of::(); + //log::debug!("current vtx size: {}, current idx size: {}", current_vtx_size, current_idx_size); if current_vtx_size >= need_vtx && current_idx_size >= need_idx { return } @@ -84,9 +85,10 @@ impl BufferPair { return } - self.ensure_buffer_size(vtx.len(), idx.len()); - self.vertex_buffer.slice_mut(0..vtx.len()).unwrap().write(vtx); - self.index_buffer.slice_mut(0..idx.len()).unwrap().write(idx); + self.ensure_buffer_size(self.vertex_count, self.index_count); + + self.vertex_buffer.slice_mut(0..self.vertex_count).unwrap().write(vtx); + self.index_buffer.slice_mut(0..self.index_count).unwrap().write(idx); } pub fn is_empty(&self) -> bool { diff --git a/kubi-ui/src/element.rs b/kubi-ui/src/element.rs index 14916e5..c5023fc 100644 --- a/kubi-ui/src/element.rs +++ b/kubi-ui/src/element.rs @@ -6,10 +6,15 @@ use crate::{ state::StateRepo }; -#[cfg(feature = "builtin_elements")] pub mod rect; -#[cfg(feature = "builtin_elements")] pub mod container; -#[cfg(feature = "builtin_elements")] pub mod spacer; -#[cfg(feature = "builtin_elements")] pub mod progress_bar; +#[cfg(feature = "builtin")] mod builtin { + pub mod rect; + pub mod container; + pub mod spacer; + pub mod progress_bar; +} + +#[cfg(feature = "builtin")] +pub use builtin::*; pub trait UiElement { fn name(&self) -> &'static str { "UiElement" } diff --git a/kubi-ui/src/element/container.rs b/kubi-ui/src/element/builtin/container.rs similarity index 96% rename from kubi-ui/src/element/container.rs rename to kubi-ui/src/element/builtin/container.rs index 3346ce9..565b633 100644 --- a/kubi-ui/src/element/container.rs +++ b/kubi-ui/src/element/builtin/container.rs @@ -1,6 +1,13 @@ use glam::{Vec2, vec2, Vec4}; -use crate::{UiDirection, LayoutInfo, draw::UiDrawCommand, measure::Response, state::StateRepo, UiSize}; -use super::UiElement; +use crate::{ + UiDirection, + UiSize, + LayoutInfo, + draw::UiDrawCommand, + measure::Response, + state::StateRepo, + element::UiElement +}; pub enum Alignment { Begin, diff --git a/kubi-ui/src/element/progress_bar.rs b/kubi-ui/src/element/builtin/progress_bar.rs similarity index 97% rename from kubi-ui/src/element/progress_bar.rs rename to kubi-ui/src/element/builtin/progress_bar.rs index 854ad0b..3d54f95 100644 --- a/kubi-ui/src/element/progress_bar.rs +++ b/kubi-ui/src/element/builtin/progress_bar.rs @@ -3,9 +3,9 @@ use crate::{ UiSize, LayoutInfo, draw::UiDrawCommand, measure::Response, - state::StateRepo + state::StateRepo, + element::UiElement }; -use super::UiElement; #[derive(Debug, Clone, Copy)] pub struct ProgressBar { diff --git a/kubi-ui/src/element/rect.rs b/kubi-ui/src/element/builtin/rect.rs similarity index 90% rename from kubi-ui/src/element/rect.rs rename to kubi-ui/src/element/builtin/rect.rs index b998530..9838a24 100644 --- a/kubi-ui/src/element/rect.rs +++ b/kubi-ui/src/element/builtin/rect.rs @@ -1,6 +1,12 @@ use glam::{vec2, Vec4}; -use crate::{state::StateRepo, LayoutInfo, measure::Response, draw::UiDrawCommand, UiSize}; -use super::UiElement; +use crate::{ + LayoutInfo, + UiSize, + element::UiElement, + state::StateRepo, + measure::Response, + draw::UiDrawCommand +}; pub struct Rect { pub size: (UiSize, UiSize), diff --git a/kubi-ui/src/element/spacer.rs b/kubi-ui/src/element/builtin/spacer.rs similarity index 80% rename from kubi-ui/src/element/spacer.rs rename to kubi-ui/src/element/builtin/spacer.rs index 5b3bd77..92c4d61 100644 --- a/kubi-ui/src/element/spacer.rs +++ b/kubi-ui/src/element/builtin/spacer.rs @@ -1,6 +1,12 @@ use glam::vec2; -use crate::{state::StateRepo, LayoutInfo, measure::Response, draw::UiDrawCommand, UiDirection}; -use super::UiElement; +use crate::{ + LayoutInfo, + UiDirection, + element::UiElement, + state::StateRepo, + measure::Response, + draw::UiDrawCommand +}; pub struct Spacer(f32);