mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
Vec<UiDrawCommand>
-> UiDrawCommands
This commit is contained in:
parent
eaf4d98d65
commit
491bb435cc
|
@ -33,6 +33,12 @@ pub struct UiDrawCommands {
|
||||||
pub commands: Vec<UiDrawCommand>,
|
pub commands: Vec<UiDrawCommand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UiDrawCommands {
|
||||||
|
pub fn add(&mut self, command: UiDrawCommand) {
|
||||||
|
self.commands.push(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// impl UiDrawCommands {
|
// impl UiDrawCommands {
|
||||||
// pub fn compare(&self, other: &Self) -> bool {
|
// pub fn compare(&self, other: &Self) -> bool {
|
||||||
// // if self.commands.len() != other.commands.len() { return false }
|
// // if self.commands.len() != other.commands.len() { return false }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use crate::{
|
use crate::{
|
||||||
LayoutInfo,
|
LayoutInfo,
|
||||||
draw::UiDrawCommand,
|
draw::UiDrawCommands,
|
||||||
measure::Response,
|
measure::Response,
|
||||||
state::StateRepo
|
state::StateRepo
|
||||||
};
|
};
|
||||||
|
@ -25,5 +25,5 @@ pub trait UiElement {
|
||||||
fn is_stateless(&self) -> bool { self.state_id().is_none() }
|
fn is_stateless(&self) -> bool { self.state_id().is_none() }
|
||||||
fn init_state(&self) -> Option<Box<dyn Any>> { None }
|
fn init_state(&self) -> Option<Box<dyn Any>> { None }
|
||||||
fn measure(&self, state: &StateRepo, layout: &LayoutInfo) -> Response;
|
fn measure(&self, state: &StateRepo, layout: &LayoutInfo) -> Response;
|
||||||
fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut Vec<UiDrawCommand>);
|
fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
UiDirection,
|
UiDirection,
|
||||||
UiSize,
|
UiSize,
|
||||||
LayoutInfo,
|
LayoutInfo,
|
||||||
draw::UiDrawCommand,
|
draw::{UiDrawCommand, UiDrawCommands},
|
||||||
measure::{Response, Hints},
|
measure::{Response, Hints},
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
element::UiElement
|
element::UiElement
|
||||||
|
@ -59,6 +59,7 @@ pub struct Container {
|
||||||
//pub reverse: bool,
|
//pub reverse: bool,
|
||||||
pub gap: f32,
|
pub gap: f32,
|
||||||
pub padding: Sides<f32>,
|
pub padding: Sides<f32>,
|
||||||
|
///Primary/secondary axis
|
||||||
pub align: (Alignment, Alignment),
|
pub align: (Alignment, Alignment),
|
||||||
pub background: Option<Vec4>,
|
pub background: Option<Vec4>,
|
||||||
pub borders: Sides<Option<Border>>,
|
pub borders: Sides<Option<Border>>,
|
||||||
|
@ -76,7 +77,6 @@ impl Default for Container {
|
||||||
//reverse: false,
|
//reverse: false,
|
||||||
gap: 0.,
|
gap: 0.,
|
||||||
padding: Sides::all(0.),
|
padding: Sides::all(0.),
|
||||||
///Primary/secondary axis
|
|
||||||
align: (Alignment::Begin, Alignment::Begin),
|
align: (Alignment::Begin, Alignment::Begin),
|
||||||
background: Default::default(),
|
background: Default::default(),
|
||||||
borders: Default::default(),
|
borders: Default::default(),
|
||||||
|
@ -150,12 +150,12 @@ impl UiElement for Container {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut Vec<UiDrawCommand>) {
|
fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands) {
|
||||||
let mut position = layout.position;
|
let mut position = layout.position;
|
||||||
|
|
||||||
//background
|
//background
|
||||||
if let Some(color) = self.background {
|
if let Some(color) = self.background {
|
||||||
draw.push(UiDrawCommand::Rectangle {
|
draw.add(UiDrawCommand::Rectangle {
|
||||||
position,
|
position,
|
||||||
size: measure.size,
|
size: measure.size,
|
||||||
color
|
color
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use glam::{vec2, Vec4, vec4};
|
use glam::{vec2, Vec4, vec4};
|
||||||
use crate::{
|
use crate::{
|
||||||
UiSize, LayoutInfo,
|
UiSize, LayoutInfo,
|
||||||
draw::UiDrawCommand,
|
draw::{UiDrawCommand, UiDrawCommands},
|
||||||
measure::Response,
|
measure::Response,
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
element::UiElement
|
element::UiElement
|
||||||
|
@ -50,17 +50,17 @@ impl UiElement for ProgressBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut Vec<UiDrawCommand>) {
|
fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands) {
|
||||||
let value = self.value.clamp(0., 1.);
|
let value = self.value.clamp(0., 1.);
|
||||||
if value < 1. {
|
if value < 1. {
|
||||||
draw.push(UiDrawCommand::Rectangle {
|
draw.add(UiDrawCommand::Rectangle {
|
||||||
position: layout.position,
|
position: layout.position,
|
||||||
size: measure.size,
|
size: measure.size,
|
||||||
color: self.color_background
|
color: self.color_background
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if value > 0. {
|
if value > 0. {
|
||||||
draw.push(UiDrawCommand::Rectangle {
|
draw.add(UiDrawCommand::Rectangle {
|
||||||
position: layout.position,
|
position: layout.position,
|
||||||
size: measure.size * vec2(value, 1.0),
|
size: measure.size * vec2(value, 1.0),
|
||||||
color: self.color_foreground
|
color: self.color_foreground
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
element::UiElement,
|
element::UiElement,
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
measure::Response,
|
measure::Response,
|
||||||
draw::UiDrawCommand
|
draw::{UiDrawCommand, UiDrawCommands}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
|
@ -42,9 +42,9 @@ impl UiElement for Rect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&self, measure: &Response, _state: &mut StateRepo, layout: &LayoutInfo, draw: &mut Vec<UiDrawCommand>) {
|
fn process(&self, measure: &Response, _state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands) {
|
||||||
if let Some(color) = self.color {
|
if let Some(color) = self.color {
|
||||||
draw.push(UiDrawCommand::Rectangle {
|
draw.add(UiDrawCommand::Rectangle {
|
||||||
position: layout.position,
|
position: layout.position,
|
||||||
size: measure.size,
|
size: measure.size,
|
||||||
color,
|
color,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
element::UiElement,
|
element::UiElement,
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
measure::Response,
|
measure::Response,
|
||||||
draw::UiDrawCommand
|
draw::{UiDrawCommand, UiDrawCommands}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Spacer(f32);
|
pub struct Spacer(f32);
|
||||||
|
@ -28,5 +28,5 @@ impl UiElement for Spacer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&self, _measure: &Response, _state: &mut StateRepo, _layout: &LayoutInfo, _draw: &mut Vec<UiDrawCommand>) {}
|
fn process(&self, _measure: &Response, _state: &mut StateRepo, _layout: &LayoutInfo, _draw: &mut UiDrawCommands) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
element::UiElement,
|
element::UiElement,
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
measure::Response,
|
measure::Response,
|
||||||
draw::UiDrawCommand, text::FontHandle
|
draw::{UiDrawCommand, UiDrawCommands}, text::FontHandle
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
|
@ -47,8 +47,8 @@ impl UiElement for Text {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&self, _measure: &Response, _state: &mut StateRepo, layout: &LayoutInfo, draw: &mut Vec<UiDrawCommand>) {
|
fn process(&self, _measure: &Response, _state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands) {
|
||||||
draw.push(UiDrawCommand::Text {
|
draw.add(UiDrawCommand::Text {
|
||||||
text: self.text.clone(),
|
text: self.text.clone(),
|
||||||
position: layout.position,
|
position: layout.position,
|
||||||
size: 32,
|
size: 32,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::element::UiElement;
|
use crate::{element::UiElement, draw::UiDrawCommands};
|
||||||
|
|
||||||
pub struct Interactable<T: UiElement> {
|
pub struct Interactable<T: UiElement> {
|
||||||
pub element: T,
|
pub element: T,
|
||||||
|
@ -35,7 +35,7 @@ impl<T: UiElement> UiElement for Interactable<T> {
|
||||||
self.element.measure(state, layout)
|
self.element.measure(state, layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&self, measure: &crate::measure::Response, state: &mut crate::state::StateRepo, layout: &crate::LayoutInfo, draw: &mut Vec<crate::draw::UiDrawCommand>) {
|
fn process(&self, measure: &crate::measure::Response, state: &mut crate::state::StateRepo, layout: &crate::LayoutInfo, draw: &mut UiDrawCommands) {
|
||||||
self.element.process(measure, state, layout, draw)
|
self.element.process(measure, state, layout, draw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl KubiUi {
|
||||||
direction: UiDirection::Vertical,
|
direction: UiDirection::Vertical,
|
||||||
};
|
};
|
||||||
let measure = element.measure(&self.stateful_state, &layout);
|
let measure = element.measure(&self.stateful_state, &layout);
|
||||||
element.process(&measure, &mut self.stateful_state, &layout, &mut self.draw_commands.commands);
|
element.process(&measure, &mut self.stateful_state, &layout, &mut self.draw_commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn begin(&mut self) {
|
pub fn begin(&mut self) {
|
||||||
|
|
Loading…
Reference in a new issue