mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 14:48:42 -06:00
minor changes
This commit is contained in:
parent
b064a2cb2b
commit
23dc81a921
|
@ -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::<Vec<_>>()[..];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TextureH>
|
||||
// }
|
||||
|
||||
#[derive(Clone, Copy, Default, Debug, PartialEq)]
|
||||
pub enum Background {
|
||||
pub enum BackgroundColor {
|
||||
#[default]
|
||||
Transparent,
|
||||
Solid(Vec4),
|
||||
Gradient(Corners<Vec4>),
|
||||
}
|
||||
|
||||
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<Corners<Vec4>> for Background {
|
||||
impl From<Corners<Vec4>> for BackgroundColor {
|
||||
fn from(corners: Corners<Vec4>) -> Self {
|
||||
Self::Gradient(corners)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Option<Vec4>> for Background {
|
||||
impl From<Option<Vec4>> for BackgroundColor {
|
||||
fn from(color: Option<Vec4>) -> Self {
|
||||
match color {
|
||||
Some(color) => Self::Solid(color),
|
||||
|
@ -38,19 +36,19 @@ impl From<Option<Vec4>> for Background {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Vec4> for Background {
|
||||
impl From<Vec4> 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<Corners<Vec3>> for Background {
|
||||
impl From<Corners<Vec3>> for BackgroundColor {
|
||||
fn from(corners: Corners<Vec3>) -> Self {
|
||||
Self::Gradient(Corners {
|
||||
top_left: corners.top_left.extend(1.),
|
||||
|
@ -61,7 +59,7 @@ impl From<Corners<Vec3>> for Background {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Option<Vec3>> for Background {
|
||||
impl From<Option<Vec3>> for BackgroundColor {
|
||||
fn from(color: Option<Vec3>) -> Self {
|
||||
match color {
|
||||
Some(color) => Self::Solid(color.extend(1.)),
|
||||
|
@ -70,13 +68,13 @@ impl From<Option<Vec3>> for Background {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Vec3> for Background {
|
||||
impl From<Vec3> 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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<f32>,
|
||||
pub align: Alignment2d,
|
||||
pub background: Background,
|
||||
pub background: BackgroundColor,
|
||||
pub corner_radius: Corners<f32>,
|
||||
pub elements: Vec<Box<dyn UiElement>>,
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue