diff --git a/kubi-ui/src/draw.rs b/kubi-ui/src/draw.rs index b5ade1e..2b539b0 100644 --- a/kubi-ui/src/draw.rs +++ b/kubi-ui/src/draw.rs @@ -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!() } } } diff --git a/kubi-ui/src/lib.rs b/kubi-ui/src/lib.rs index c7e8f76..7505eaa 100644 --- a/kubi-ui/src/lib.rs +++ b/kubi-ui/src/lib.rs @@ -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; } diff --git a/kubi-ui/src/text.rs b/kubi-ui/src/text.rs index 5e42d93..a47b984 100644 --- a/kubi-ui/src/text.rs +++ b/kubi-ui/src/text.rs @@ -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,