mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 16:28:42 -06:00
owo
This commit is contained in:
parent
16ffb6f786
commit
0af548320b
|
@ -1,6 +1,8 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
use glam::{Vec2, Vec4, vec2};
|
use glam::{Vec2, Vec4, vec2};
|
||||||
|
use crate::text::TextRenderer;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum UiDrawCommand {
|
pub enum UiDrawCommand {
|
||||||
///Filled, colored rectangle
|
///Filled, colored rectangle
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
@ -10,7 +12,17 @@ pub enum UiDrawCommand {
|
||||||
size: Vec2,
|
size: Vec2,
|
||||||
///Color (RGBA)
|
///Color (RGBA)
|
||||||
color: Vec4,
|
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)]
|
#[derive(Default)]
|
||||||
|
@ -25,6 +37,11 @@ pub struct UiDrawCommands {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
pub enum BindTexture {
|
||||||
|
FontTexture,
|
||||||
|
//UserDefined(usize),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct UiVertex {
|
pub struct UiVertex {
|
||||||
pub position: Vec2,
|
pub position: Vec2,
|
||||||
|
@ -45,7 +62,7 @@ pub struct UiDrawPlan {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UiDrawPlan {
|
impl UiDrawPlan {
|
||||||
pub fn build(calls: &UiDrawCommands) -> Self {
|
pub fn build(calls: &UiDrawCommands, tr: &mut TextRenderer) -> Self {
|
||||||
let mut call = UiDrawCall::default();
|
let mut call = UiDrawCall::default();
|
||||||
for command in &calls.commands {
|
for command in &calls.commands {
|
||||||
match command {
|
match command {
|
||||||
|
@ -74,6 +91,9 @@ impl UiDrawPlan {
|
||||||
uv: vec2(0.0, 1.0),
|
uv: vec2(0.0, 1.0),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
},
|
||||||
|
UiDrawCommand::Text { position, size, color, text } => {
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ use event::UiEvent;
|
||||||
use draw::{UiDrawCommands, UiDrawPlan};
|
use draw::{UiDrawCommands, UiDrawPlan};
|
||||||
use text::TextRenderer;
|
use text::TextRenderer;
|
||||||
|
|
||||||
pub struct ElementContext<'a> {
|
// pub struct ElementContext<'a> {
|
||||||
pub state: &'a mut StateRepo,
|
// pub state: &'a mut StateRepo,
|
||||||
pub draw: &'a mut UiDrawCommands,
|
// pub draw: &'a mut UiDrawCommands,
|
||||||
pub text: &'a mut TextRenderer,
|
// pub text: &'a mut TextRenderer,
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub struct KubiUi {
|
pub struct KubiUi {
|
||||||
mouse_position: Vec2,
|
mouse_position: Vec2,
|
||||||
|
@ -67,7 +67,7 @@ impl KubiUi {
|
||||||
if self.draw_commands.commands == self.prev_draw_commands.commands {
|
if self.draw_commands.commands == self.prev_draw_commands.commands {
|
||||||
return
|
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;
|
self.draw_plan_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ const BIN_FONT: &[u8] = include_bytes!("../assets/font/ProggyTiny.ttf");
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct FontHandle(pub(crate) usize);
|
pub struct FontHandle(pub(crate) usize);
|
||||||
|
|
||||||
|
#[cfg(feature = "builtin_font")]
|
||||||
|
pub const BUILTIN_FONT: FontHandle = FontHandle(0);
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash)]
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
struct GlyphCacheKey {
|
struct GlyphCacheKey {
|
||||||
font_index: usize,
|
font_index: usize,
|
||||||
|
|
Loading…
Reference in a new issue