mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 03:48:21 -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>,
|
||||
}
|
||||
|
||||
impl UiDrawCommands {
|
||||
pub fn add(&mut self, command: UiDrawCommand) {
|
||||
self.commands.push(command);
|
||||
}
|
||||
}
|
||||
|
||||
// impl UiDrawCommands {
|
||||
// pub fn compare(&self, other: &Self) -> bool {
|
||||
// // if self.commands.len() != other.commands.len() { return false }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::any::Any;
|
||||
use crate::{
|
||||
LayoutInfo,
|
||||
draw::UiDrawCommand,
|
||||
draw::UiDrawCommands,
|
||||
measure::Response,
|
||||
state::StateRepo
|
||||
};
|
||||
|
@ -25,5 +25,5 @@ pub trait UiElement {
|
|||
fn is_stateless(&self) -> bool { self.state_id().is_none() }
|
||||
fn init_state(&self) -> Option<Box<dyn Any>> { None }
|
||||
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,
|
||||
UiSize,
|
||||
LayoutInfo,
|
||||
draw::UiDrawCommand,
|
||||
draw::{UiDrawCommand, UiDrawCommands},
|
||||
measure::{Response, Hints},
|
||||
state::StateRepo,
|
||||
element::UiElement
|
||||
|
@ -59,6 +59,7 @@ pub struct Container {
|
|||
//pub reverse: bool,
|
||||
pub gap: f32,
|
||||
pub padding: Sides<f32>,
|
||||
///Primary/secondary axis
|
||||
pub align: (Alignment, Alignment),
|
||||
pub background: Option<Vec4>,
|
||||
pub borders: Sides<Option<Border>>,
|
||||
|
@ -76,7 +77,6 @@ impl Default for Container {
|
|||
//reverse: false,
|
||||
gap: 0.,
|
||||
padding: Sides::all(0.),
|
||||
///Primary/secondary axis
|
||||
align: (Alignment::Begin, Alignment::Begin),
|
||||
background: 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;
|
||||
|
||||
//background
|
||||
if let Some(color) = self.background {
|
||||
draw.push(UiDrawCommand::Rectangle {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position,
|
||||
size: measure.size,
|
||||
color
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use glam::{vec2, Vec4, vec4};
|
||||
use crate::{
|
||||
UiSize, LayoutInfo,
|
||||
draw::UiDrawCommand,
|
||||
draw::{UiDrawCommand, UiDrawCommands},
|
||||
measure::Response,
|
||||
state::StateRepo,
|
||||
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.);
|
||||
if value < 1. {
|
||||
draw.push(UiDrawCommand::Rectangle {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position: layout.position,
|
||||
size: measure.size,
|
||||
color: self.color_background
|
||||
});
|
||||
}
|
||||
if value > 0. {
|
||||
draw.push(UiDrawCommand::Rectangle {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position: layout.position,
|
||||
size: measure.size * vec2(value, 1.0),
|
||||
color: self.color_foreground
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
element::UiElement,
|
||||
state::StateRepo,
|
||||
measure::Response,
|
||||
draw::UiDrawCommand
|
||||
draw::{UiDrawCommand, UiDrawCommands}
|
||||
};
|
||||
|
||||
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 {
|
||||
draw.push(UiDrawCommand::Rectangle {
|
||||
draw.add(UiDrawCommand::Rectangle {
|
||||
position: layout.position,
|
||||
size: measure.size,
|
||||
color,
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
element::UiElement,
|
||||
state::StateRepo,
|
||||
measure::Response,
|
||||
draw::UiDrawCommand
|
||||
draw::{UiDrawCommand, UiDrawCommands}
|
||||
};
|
||||
|
||||
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,
|
||||
state::StateRepo,
|
||||
measure::Response,
|
||||
draw::UiDrawCommand, text::FontHandle
|
||||
draw::{UiDrawCommand, UiDrawCommands}, text::FontHandle
|
||||
};
|
||||
|
||||
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>) {
|
||||
draw.push(UiDrawCommand::Text {
|
||||
fn process(&self, _measure: &Response, _state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands) {
|
||||
draw.add(UiDrawCommand::Text {
|
||||
text: self.text.clone(),
|
||||
position: layout.position,
|
||||
size: 32,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::element::UiElement;
|
||||
use crate::{element::UiElement, draw::UiDrawCommands};
|
||||
|
||||
pub struct Interactable<T: UiElement> {
|
||||
pub element: T,
|
||||
|
@ -35,7 +35,7 @@ impl<T: UiElement> UiElement for Interactable<T> {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ impl KubiUi {
|
|||
direction: UiDirection::Vertical,
|
||||
};
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue