This commit is contained in:
griffi-gh 2023-11-26 01:47:48 +01:00
parent 16ffb6f786
commit 0af548320b
3 changed files with 32 additions and 9 deletions

View file

@ -1,6 +1,8 @@
use std::borrow::Cow;
use glam::{Vec2, Vec4, vec2};
use crate::text::TextRenderer;
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum UiDrawCommand {
///Filled, colored rectangle
Rectangle {
@ -10,7 +12,17 @@ pub enum UiDrawCommand {
size: Vec2,
///Color (RGBA)
color: Vec4,
}
},
Text {
///Position in pixels
position: Vec2,
///Font size
size: u8,
///Color (RGBA)
color: Vec4,
///Text to draw
text: Cow<'static, str>,
},
}
#[derive(Default)]
@ -25,6 +37,11 @@ pub struct UiDrawCommands {
// }
// }
pub enum BindTexture {
FontTexture,
//UserDefined(usize),
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct UiVertex {
pub position: Vec2,
@ -45,7 +62,7 @@ pub struct UiDrawPlan {
}
impl UiDrawPlan {
pub fn build(calls: &UiDrawCommands) -> Self {
pub fn build(calls: &UiDrawCommands, tr: &mut TextRenderer) -> Self {
let mut call = UiDrawCall::default();
for command in &calls.commands {
match command {
@ -74,6 +91,9 @@ impl UiDrawPlan {
uv: vec2(0.0, 1.0),
},
]);
},
UiDrawCommand::Text { position, size, color, text } => {
todo!()
}
}
}

View file

@ -15,11 +15,11 @@ use event::UiEvent;
use draw::{UiDrawCommands, UiDrawPlan};
use text::TextRenderer;
pub struct ElementContext<'a> {
pub state: &'a mut StateRepo,
pub draw: &'a mut UiDrawCommands,
pub text: &'a mut TextRenderer,
}
// pub struct ElementContext<'a> {
// pub state: &'a mut StateRepo,
// pub draw: &'a mut UiDrawCommands,
// pub text: &'a mut TextRenderer,
// }
pub struct KubiUi {
mouse_position: Vec2,
@ -67,7 +67,7 @@ impl KubiUi {
if self.draw_commands.commands == self.prev_draw_commands.commands {
return
}
self.draw_plan = UiDrawPlan::build(&self.draw_commands);
self.draw_plan = UiDrawPlan::build(&self.draw_commands, &mut self.font_renderer);
self.draw_plan_modified = true;
}

View file

@ -10,6 +10,9 @@ const BIN_FONT: &[u8] = include_bytes!("../assets/font/ProggyTiny.ttf");
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct FontHandle(pub(crate) usize);
#[cfg(feature = "builtin_font")]
pub const BUILTIN_FONT: FontHandle = FontHandle(0);
#[derive(PartialEq, Eq, Hash)]
struct GlyphCacheKey {
font_index: usize,