restructure stuff

This commit is contained in:
griffi-gh 2023-11-23 11:10:42 +01:00
parent fef14911d5
commit cf56bf29fe
6 changed files with 43 additions and 17 deletions

View file

@ -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::<Vertex>();
let current_idx_size = self.index_buffer.get_size() / std::mem::size_of::<u32>();
//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 {

View file

@ -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" }

View file

@ -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,

View file

@ -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 {

View file

@ -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),

View file

@ -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);