mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08: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_vtx = &call.vertices.iter().copied().map(Vertex::from).collect::<Vec<_>>()[..];
|
||||||
let data_idx = &call.indices[..];
|
let data_idx = &call.indices[..];
|
||||||
if let Some(buffer) = &mut self.buffer_pair {
|
if let Some(buffer) = &mut self.buffer_pair {
|
||||||
|
@ -156,8 +156,8 @@ impl GliumUiRenderer {
|
||||||
if self.ui_texture.is_none() || hui.atlas().modified {
|
if self.ui_texture.is_none() || hui.atlas().modified {
|
||||||
self.update_texture_atlas(&hui.atlas());
|
self.update_texture_atlas(&hui.atlas());
|
||||||
}
|
}
|
||||||
if hui.draw_call().0 {
|
if self.buffer_pair.is_none() || hui.draw_call().0 {
|
||||||
self.update_draw_plan(hui.draw_call().1);
|
self.update_buffers(hui.draw_call().1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,33 @@
|
||||||
use glam::{vec4, Vec3, Vec4};
|
use glam::{vec4, Vec3, Vec4};
|
||||||
use crate::rectangle::Corners;
|
use crate::rectangle::Corners;
|
||||||
|
|
||||||
// #[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
//TODO: use this
|
||||||
// pub enum GradientDirection {
|
// pub struct Background {
|
||||||
// ToRight = 0b00,
|
// pub color: BackgroundColor,
|
||||||
// ToLeft = 0b01,
|
// pub texture: Option<TextureH>
|
||||||
// ToBottom = 0b10,
|
|
||||||
// ToTop = 0b11,
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Debug, PartialEq)]
|
#[derive(Clone, Copy, Default, Debug, PartialEq)]
|
||||||
pub enum Background {
|
pub enum BackgroundColor {
|
||||||
#[default]
|
#[default]
|
||||||
Transparent,
|
Transparent,
|
||||||
Solid(Vec4),
|
Solid(Vec4),
|
||||||
Gradient(Corners<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 {
|
fn from(color: (f32, f32, f32, f32)) -> Self {
|
||||||
Self::Solid(vec4(color.0, color.1, color.2, color.3))
|
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 {
|
fn from(corners: Corners<Vec4>) -> Self {
|
||||||
Self::Gradient(corners)
|
Self::Gradient(corners)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Option<Vec4>> for Background {
|
impl From<Option<Vec4>> for BackgroundColor {
|
||||||
fn from(color: Option<Vec4>) -> Self {
|
fn from(color: Option<Vec4>) -> Self {
|
||||||
match color {
|
match color {
|
||||||
Some(color) => Self::Solid(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 {
|
fn from(color: Vec4) -> Self {
|
||||||
Self::Solid(color)
|
Self::Solid(color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(f32, f32, f32)> for Background {
|
impl From<(f32, f32, f32)> for BackgroundColor {
|
||||||
fn from(color: (f32, f32, f32)) -> Self {
|
fn from(color: (f32, f32, f32)) -> Self {
|
||||||
Self::Solid(vec4(color.0, color.1, color.2, 1.))
|
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 {
|
fn from(corners: Corners<Vec3>) -> Self {
|
||||||
Self::Gradient(Corners {
|
Self::Gradient(Corners {
|
||||||
top_left: corners.top_left.extend(1.),
|
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 {
|
fn from(color: Option<Vec3>) -> Self {
|
||||||
match color {
|
match color {
|
||||||
Some(color) => Self::Solid(color.extend(1.)),
|
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 {
|
fn from(color: Vec3) -> Self {
|
||||||
Self::Solid(color.extend(1.))
|
Self::Solid(color.extend(1.))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Background {
|
impl BackgroundColor {
|
||||||
/// Currently, never returns None.\
|
/// Currently, never returns None.\
|
||||||
/// `Option` has been added in preparation for future changes.\
|
/// `Option` has been added in preparation for future changes.\
|
||||||
/// (`Background::Texture` etc)
|
/// (`Background::Texture` etc)
|
||||||
|
|
|
@ -8,8 +8,14 @@ const RGBA_CHANNEL_COUNT: u32 = 4;
|
||||||
const ALLOW_ROTATION: bool = false;
|
const ALLOW_ROTATION: bool = false;
|
||||||
|
|
||||||
pub struct TextureAtlasMeta<'a> {
|
pub struct TextureAtlasMeta<'a> {
|
||||||
|
/// Texture data\
|
||||||
|
/// The data is stored in RGBA format, with 1 byte (8 bits) per channel
|
||||||
pub data: &'a [u8],
|
pub data: &'a [u8],
|
||||||
|
/// Current size of the texture atlas\
|
||||||
|
/// Please note that this value might change
|
||||||
pub size: UVec2,
|
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,
|
pub modified: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,12 +215,6 @@ impl TextureAtlasManager {
|
||||||
self.modified = false;
|
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 {
|
pub fn meta(&self) -> TextureAtlasMeta {
|
||||||
TextureAtlasMeta {
|
TextureAtlasMeta {
|
||||||
data: &self.data,
|
data: &self.data,
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
use glam::{Vec2, vec2, Vec4};
|
use glam::{Vec2, vec2};
|
||||||
use crate::{
|
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 {
|
// pub struct Border {
|
||||||
|
@ -19,7 +24,7 @@ pub struct Container {
|
||||||
pub gap: f32,
|
pub gap: f32,
|
||||||
pub padding: Sides<f32>,
|
pub padding: Sides<f32>,
|
||||||
pub align: Alignment2d,
|
pub align: Alignment2d,
|
||||||
pub background: Background,
|
pub background: BackgroundColor,
|
||||||
pub corner_radius: Corners<f32>,
|
pub corner_radius: Corners<f32>,
|
||||||
pub elements: Vec<Box<dyn UiElement>>,
|
pub elements: Vec<Box<dyn UiElement>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
use glam::{vec2, Vec4};
|
use glam::{vec2, Vec4};
|
||||||
use crate::{
|
use crate::{
|
||||||
background::Background,
|
background::BackgroundColor,
|
||||||
draw::UiDrawCommand,
|
draw::UiDrawCommand,
|
||||||
element::{MeasureContext, ProcessContext, UiElement},
|
element::{MeasureContext, ProcessContext, UiElement},
|
||||||
layout::UiSize,
|
layout::UiSize,
|
||||||
measure::Response,
|
measure::Response
|
||||||
rectangle::Corners
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
pub size: (UiSize, UiSize),
|
pub size: (UiSize, UiSize),
|
||||||
pub color: Background,
|
pub color: BackgroundColor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Rect {
|
impl Default for Rect {
|
||||||
|
|
Loading…
Reference in a new issue