From 23dc81a9214cca52303170c9f7680bdb26b5b645 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sun, 25 Feb 2024 15:59:12 +0100 Subject: [PATCH] minor changes --- hui-glium/src/lib.rs | 6 +++--- hui/src/background.rs | 30 +++++++++++++--------------- hui/src/draw/atlas.rs | 12 +++++------ hui/src/element/builtin/container.rs | 11 +++++++--- hui/src/element/builtin/rect.rs | 7 +++---- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/hui-glium/src/lib.rs b/hui-glium/src/lib.rs index 7b33b5c..f652ca2 100644 --- a/hui-glium/src/lib.rs +++ b/hui-glium/src/lib.rs @@ -131,7 +131,7 @@ impl GliumUiRenderer { } } - pub fn update_draw_plan(&mut self, call: &UiDrawCall) { + pub fn update_buffers(&mut self, call: &UiDrawCall) { let data_vtx = &call.vertices.iter().copied().map(Vertex::from).collect::>()[..]; let data_idx = &call.indices[..]; if let Some(buffer) = &mut self.buffer_pair { @@ -156,8 +156,8 @@ impl GliumUiRenderer { if self.ui_texture.is_none() || hui.atlas().modified { self.update_texture_atlas(&hui.atlas()); } - if hui.draw_call().0 { - self.update_draw_plan(hui.draw_call().1); + if self.buffer_pair.is_none() || hui.draw_call().0 { + self.update_buffers(hui.draw_call().1); } } diff --git a/hui/src/background.rs b/hui/src/background.rs index 764f055..f6614ca 100644 --- a/hui/src/background.rs +++ b/hui/src/background.rs @@ -1,35 +1,33 @@ use glam::{vec4, Vec3, Vec4}; use crate::rectangle::Corners; -// #[derive(Clone, Copy, PartialEq, Eq, Debug)] -// pub enum GradientDirection { -// ToRight = 0b00, -// ToLeft = 0b01, -// ToBottom = 0b10, -// ToTop = 0b11, +//TODO: use this +// pub struct Background { +// pub color: BackgroundColor, +// pub texture: Option // } #[derive(Clone, Copy, Default, Debug, PartialEq)] -pub enum Background { +pub enum BackgroundColor { #[default] Transparent, Solid(Vec4), Gradient(Corners), } -impl From<(f32, f32, f32, f32)> for Background { +impl From<(f32, f32, f32, f32)> for BackgroundColor { fn from(color: (f32, f32, f32, f32)) -> Self { Self::Solid(vec4(color.0, color.1, color.2, color.3)) } } -impl From> for Background { +impl From> for BackgroundColor { fn from(corners: Corners) -> Self { Self::Gradient(corners) } } -impl From> for Background { +impl From> for BackgroundColor { fn from(color: Option) -> Self { match color { Some(color) => Self::Solid(color), @@ -38,19 +36,19 @@ impl From> for Background { } } -impl From for Background { +impl From for BackgroundColor { fn from(color: Vec4) -> Self { Self::Solid(color) } } -impl From<(f32, f32, f32)> for Background { +impl From<(f32, f32, f32)> for BackgroundColor { fn from(color: (f32, f32, f32)) -> Self { Self::Solid(vec4(color.0, color.1, color.2, 1.)) } } -impl From> for Background { +impl From> for BackgroundColor { fn from(corners: Corners) -> Self { Self::Gradient(Corners { top_left: corners.top_left.extend(1.), @@ -61,7 +59,7 @@ impl From> for Background { } } -impl From> for Background { +impl From> for BackgroundColor { fn from(color: Option) -> Self { match color { Some(color) => Self::Solid(color.extend(1.)), @@ -70,13 +68,13 @@ impl From> for Background { } } -impl From for Background { +impl From for BackgroundColor { fn from(color: Vec3) -> Self { Self::Solid(color.extend(1.)) } } -impl Background { +impl BackgroundColor { /// Currently, never returns None.\ /// `Option` has been added in preparation for future changes.\ /// (`Background::Texture` etc) diff --git a/hui/src/draw/atlas.rs b/hui/src/draw/atlas.rs index 2c5d657..d097e20 100644 --- a/hui/src/draw/atlas.rs +++ b/hui/src/draw/atlas.rs @@ -8,8 +8,14 @@ const RGBA_CHANNEL_COUNT: u32 = 4; const ALLOW_ROTATION: bool = false; pub struct TextureAtlasMeta<'a> { + /// Texture data\ + /// The data is stored in RGBA format, with 1 byte (8 bits) per channel pub data: &'a [u8], + /// Current size of the texture atlas\ + /// Please note that this value might change pub size: UVec2, + /// True if the atlas has been modified since the beginning of the current frame\ + /// If this function returns true, the texture atlas should be re-uploaded to the GPU before rendering\ pub modified: bool, } @@ -209,12 +215,6 @@ impl TextureAtlasManager { self.modified = false; } - /// Returns true if the atlas has been modified since the beginning of the current frame\ - /// If this function returns true, the texture atlas should be re-uploaded to the GPU before rendering\ - pub fn is_modified(&self) -> bool { - self.modified - } - pub fn meta(&self) -> TextureAtlasMeta { TextureAtlasMeta { data: &self.data, diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index 6598cf1..7af761b 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -1,6 +1,11 @@ -use glam::{Vec2, vec2, Vec4}; +use glam::{Vec2, vec2}; use crate::{ - background::Background, draw::{RoundedCorners, UiDrawCommand}, element::{MeasureContext, ProcessContext, UiElement}, layout::{Alignment, Alignment2d, LayoutInfo, UiDirection, UiSize}, measure::{Hints, Response}, rectangle::{Corners, Sides} + background::BackgroundColor, + draw::{RoundedCorners, UiDrawCommand}, + element::{MeasureContext, ProcessContext, UiElement}, + layout::{Alignment, Alignment2d, LayoutInfo, UiDirection, UiSize}, + measure::{Hints, Response}, + rectangle::{Corners, Sides} }; // pub struct Border { @@ -19,7 +24,7 @@ pub struct Container { pub gap: f32, pub padding: Sides, pub align: Alignment2d, - pub background: Background, + pub background: BackgroundColor, pub corner_radius: Corners, pub elements: Vec>, } diff --git a/hui/src/element/builtin/rect.rs b/hui/src/element/builtin/rect.rs index 9032a2e..a974634 100644 --- a/hui/src/element/builtin/rect.rs +++ b/hui/src/element/builtin/rect.rs @@ -1,16 +1,15 @@ use glam::{vec2, Vec4}; use crate::{ - background::Background, + background::BackgroundColor, draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, layout::UiSize, - measure::Response, - rectangle::Corners + measure::Response }; pub struct Rect { pub size: (UiSize, UiSize), - pub color: Background, + pub color: BackgroundColor, } impl Default for Rect {