diff --git a/Cargo.lock b/Cargo.lock
index e872cb2..707086b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -886,6 +886,30 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+[[package]]
+name = "hui"
+version = "0.0.2"
+source = "git+https://github.com/griffi-gh/hui?rev=1e1dccde0c#1e1dccde0c1f8ba8f4143a5a57d91cf923203508"
+dependencies = [
+ "fontdue",
+ "glam",
+ "hashbrown 0.14.3",
+ "log",
+ "nohash-hasher",
+ "rect_packer",
+]
+
+[[package]]
+name = "hui-glium"
+version = "0.0.2"
+source = "git+https://github.com/griffi-gh/hui?rev=1e1dccde0c#1e1dccde0c1f8ba8f4143a5a57d91cf923203508"
+dependencies = [
+ "glam",
+ "glium",
+ "hui",
+ "log",
+]
+
[[package]]
name = "humantime"
version = "2.1.0"
@@ -1073,11 +1097,11 @@ dependencies = [
"glutin",
"glutin-winit",
"hashbrown 0.14.3",
+ "hui",
+ "hui-glium",
"image",
"kubi-logging",
"kubi-shared",
- "kubi-ui",
- "kubi-ui-glium",
"log",
"lz4_flex",
"ndk",
@@ -1152,41 +1176,6 @@ dependencies = [
"strum",
]
-[[package]]
-name = "kubi-ui"
-version = "0.0.0"
-dependencies = [
- "fontdue",
- "glam",
- "hashbrown 0.14.3",
- "log",
- "nohash-hasher",
- "rect_packer",
-]
-
-[[package]]
-name = "kubi-ui-examples"
-version = "0.0.0"
-dependencies = [
- "glam",
- "glium",
- "kubi-logging",
- "kubi-ui",
- "kubi-ui-glium",
- "log",
- "winit",
-]
-
-[[package]]
-name = "kubi-ui-glium"
-version = "0.0.0"
-dependencies = [
- "glam",
- "glium",
- "kubi-ui",
- "log",
-]
-
[[package]]
name = "lazy_static"
version = "1.4.0"
diff --git a/Cargo.toml b/Cargo.toml
index e15ab38..caa0c27 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,10 +4,7 @@ members = [
"kubi-server",
"kubi-shared",
"kubi-logging",
- "kubi-pool",
- "kubi-ui",
- "kubi-ui-glium",
- "kubi-ui-examples"
+ "kubi-pool"
]
default-members = ["kubi"]
resolver = "2"
@@ -38,3 +35,6 @@ opt-level = 3
#enabling debug assertions here causes the game to abort
[profile.dev.package.android-activity]
debug-assertions = false
+
+[patch.crates-io]
+glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
diff --git a/README.md b/README.md
index c055bae..add1ce3 100644
--- a/README.md
+++ b/README.md
@@ -118,7 +118,7 @@ name = "Kubi Server" # server name
"In-house" libraries
-- [`kubi-ui`](kubi-ui): semi-imm.mode backend-agnostic ui system\
+- [`hui`](https://github.com/griffi-gh/hui): semi-imm.mode backend-agnostic ui system\
mostly ready to use, it has already replaced the Kubi legacy ui
- [`kubi-ui-glium`](kubi-ui-glium) Glium-based backend for `kubi-ui`
- [`kubi-pool`](kubi-pool): very early work-in-progress work-stealing threadpool system\
diff --git a/kubi-ui-examples/Cargo.toml b/kubi-ui-examples/Cargo.toml
deleted file mode 100644
index d191eeb..0000000
--- a/kubi-ui-examples/Cargo.toml
+++ /dev/null
@@ -1,16 +0,0 @@
-#created as a workaround for rust-analyzer dependency cycle (which should be allowed)
-
-[package]
-name = "kubi-ui-examples"
-version = "0.0.0"
-edition = "2021"
-publish = false
-
-[dev-dependencies]
-kubi-ui = { path = "../kubi-ui" }
-kubi-ui-glium = { path = "../kubi-ui-glium" }
-kubi-logging = { path = "../kubi-logging" }
-glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
-winit = "0.29"
-glam = "0.25"
-log = "0.4"
diff --git a/kubi-ui-examples/examples/mom_downloader.rs b/kubi-ui-examples/examples/mom_downloader.rs
deleted file mode 100644
index 2d6dcc6..0000000
--- a/kubi-ui-examples/examples/mom_downloader.rs
+++ /dev/null
@@ -1,111 +0,0 @@
-use std::time::Instant;
-use glam::{UVec2, vec4};
-use glium::{backend::glutin::SimpleWindowBuilder, Surface};
-use winit::{
- event::{Event, WindowEvent},
- event_loop::{EventLoopBuilder, ControlFlow}
-};
-use kubi_ui::{
- KubiUi,
- element::{
- progress_bar::ProgressBar,
- container::{Container, Sides, Alignment},
- text::Text
- },
- UiSize,
- elements,
-};
-use kubi_ui_glium::GliumUiRenderer;
-
-fn main() {
- kubi_logging::init();
-
- let event_loop = EventLoopBuilder::new().build().unwrap();
- let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
- window.set_title("Mom Downloader 2000");
-
- let mut kui = KubiUi::new();
- let mut backend = GliumUiRenderer::new(&display);
-
- let font_handle = kui.add_font_from_bytes(include_bytes!("../../assets/fonts/roboto/Roboto-Regular.ttf"));
-
- let instant = Instant::now();
-
- event_loop.run(|event, window_target| {
- window_target.set_control_flow(ControlFlow::Poll);
- match event {
- Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
- window_target.exit();
- },
- Event::AboutToWait => {
- let mut frame = display.draw();
- frame.clear_color_srgb(0., 0., 0., 1.);
-
- let resolution = UVec2::from(display.get_framebuffer_dimensions()).as_vec2();
-
- kui.begin();
-
- let mom_ratio = (instant.elapsed().as_secs_f32() / 60.).powf(0.5);
-
- kui.add(Container {
- align: (Alignment::Center, Alignment::Center),
- size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
- background: Some(vec4(0.1, 0.1, 0.1, 1.)),
- elements: vec![Box::new(Container {
- gap: 5.,
- padding: Sides::all(10.),
- align: (Alignment::Begin, Alignment::Begin),
- size: (UiSize::Pixels(450.), UiSize::Auto),
- background: Some(vec4(0.2, 0.2, 0.5, 1.)),
- elements: elements(|el| {
- if instant.elapsed().as_secs_f32() < 5. {
- el.add(Text {
- text: "Downloading your mom...".into(),
- font: font_handle,
- text_size: 32,
- ..Default::default()
- });
- el.add(ProgressBar {
- value: mom_ratio,
- ..Default::default()
- });
- el.add(Text {
- text: format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.).into(),
- font: font_handle,
- text_size: 24,
- ..Default::default()
- });
- } else if instant.elapsed().as_secs() < 10 {
- el.add(Text {
- text: "Error 413 Request Entity Too Large".into(),
- font: font_handle,
- color: vec4(1., 0.125, 0.125, 1.),
- text_size: 26,
- ..Default::default()
- });
- el.add(Text {
- text: format!("Exiting in {}...", 10 - instant.elapsed().as_secs()).into(),
- font: font_handle,
- text_size: 24,
- ..Default::default()
- })
- } else {
- window_target.exit();
- }
- }),
- ..Default::default()
- })],
- ..Default::default()
- }, resolution);
-
- kui.end();
-
- backend.update(&kui);
- backend.draw(&mut frame, resolution);
-
- frame.finish().unwrap();
- }
- _ => (),
- }
- }).unwrap();
-}
diff --git a/kubi-ui-examples/examples/stress.rs b/kubi-ui-examples/examples/stress.rs
deleted file mode 100644
index 52a1843..0000000
--- a/kubi-ui-examples/examples/stress.rs
+++ /dev/null
@@ -1,90 +0,0 @@
-use std::time::Instant;
-use glam::{Vec2, IVec2, UVec2};
-use glium::{backend::glutin::SimpleWindowBuilder, Surface};
-use winit::{
- event::{Event, WindowEvent},
- event_loop::{EventLoopBuilder, ControlFlow}
-};
-use kubi_ui::{
- KubiUi,
- element::{
- UiElement,
- progress_bar::ProgressBar,
- container::{Container, Sides}
- },
- UiSize
-};
-use kubi_ui_glium::GliumUiRenderer;
-
-fn main() {
- kubi_logging::init();
-
- let event_loop = EventLoopBuilder::new().build().unwrap();
- let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
-
- let mut kui = KubiUi::new();
- let mut backend = GliumUiRenderer::new(&display);
-
- let instant = Instant::now();
- let mut pcnt = 0;
- event_loop.run(|event, window_target| {
- window_target.set_control_flow(ControlFlow::Poll);
- match event {
- Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
- window_target.exit();
- },
- Event::AboutToWait => {
- let mut frame = display.draw();
- frame.clear_color_srgb(0.5, 0.5, 0.5, 0.);
-
- let resolution = UVec2::from(display.get_framebuffer_dimensions()).as_vec2();
-
- kui.begin();
-
- kui.add(Container {
- gap: 5.,
- padding: Sides::all(5.),
- elements: vec![
- Box::new(ProgressBar {
- value: 0.5,
- ..Default::default()
- }),
- Box::new(ProgressBar {
- value: instant.elapsed().as_secs_f32().sin().powi(2),
- ..Default::default()
- }),
- Box::new(Container {
- gap: 1.,
- elements: {
- let mut elements: Vec> = vec![];
- let cnt = instant.elapsed().as_secs() * 10000;
- if pcnt != cnt {
- log::info!("{cnt}");
- pcnt = cnt;
- }
- for i in 0..cnt {
- elements.push(Box::new(ProgressBar {
- value: (instant.elapsed().as_secs_f32() + (i as f32 / 10.)).sin().powi(2),
- size: (UiSize::Auto, UiSize::Pixels(5.)),
- ..Default::default()
- }));
- }
- elements
- },
- ..Default::default()
- })
- ],
- ..Default::default()
- }, resolution);
-
- kui.end();
-
- backend.update(&kui);
- backend.draw(&mut frame, resolution);
-
- frame.finish().unwrap();
- }
- _ => (),
- }
- }).unwrap();
-}
diff --git a/kubi-ui-examples/examples/test.rs b/kubi-ui-examples/examples/test.rs
deleted file mode 100644
index 8a289e7..0000000
--- a/kubi-ui-examples/examples/test.rs
+++ /dev/null
@@ -1,146 +0,0 @@
-use std::time::Instant;
-use glam::{UVec2, vec4};
-use glium::{backend::glutin::SimpleWindowBuilder, Surface};
-use winit::{
- event::{Event, WindowEvent},
- event_loop::{EventLoopBuilder, ControlFlow}
-};
-use kubi_ui::{
- KubiUi,
- element::{
- UiElement,
- progress_bar::ProgressBar,
- container::{Container, Sides, Alignment},
- rect::Rect
- },
- interaction::IntoInteractable,
- UiSize,
- UiDirection, IfModified,
-};
-use kubi_ui_glium::GliumUiRenderer;
-
-fn main() {
- kubi_logging::init();
-
- let event_loop = EventLoopBuilder::new().build().unwrap();
- let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
-
- let mut kui = KubiUi::new();
- let mut backend = GliumUiRenderer::new(&display);
-
- let instant = Instant::now();
- event_loop.run(|event, window_target| {
- window_target.set_control_flow(ControlFlow::Poll);
- match event {
- Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
- window_target.exit();
- },
- Event::AboutToWait => {
- let mut frame = display.draw();
- frame.clear_color_srgb(0.5, 0.5, 0.5, 0.);
-
- let resolution = UVec2::from(display.get_framebuffer_dimensions()).as_vec2();
-
- kui.begin();
-
- let z = instant.elapsed().as_secs_f32().sin().powi(2);
-
- kui.add(Container {
- gap: 5.,
- padding: Sides::all(5.),
- align: (Alignment::Begin, Alignment::Center),
- size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
- elements: vec![
- Box::new(ProgressBar {
- value: 0.5,
- ..Default::default()
- }),
- ],
- ..Default::default()
- }, resolution);
-
- kui.add(Container {
- gap: 5.,
- padding: Sides::all(5.),
- align: (Alignment::End, Alignment::Center),
- size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
- elements: vec![
- Box::new(ProgressBar {
- value: z,
- ..Default::default()
- }),
- Box::new(Container {
- size: (UiSize::Percentage(1.), UiSize::Auto),
- align: (Alignment::Center, Alignment::End),
- padding: Sides::all(5.),
- gap: 10.,
- elements: vec![
- Box::new(Rect {
- size: (UiSize::Percentage(0.5), UiSize::Pixels(30.)),
- color: Some(vec4(0.75, 0., 0., 1.))
- }),
- Box::new(Rect {
- size: (UiSize::Percentage(z / 2. + 0.5), UiSize::Pixels(30.)),
- color: Some(vec4(0., 0.75, 0., 1.))
- }),
- ],
- ..Default::default()
- }),
- Box::new(Rect {
- size: (UiSize::Percentage(z / 2. + 0.5), UiSize::Pixels(30.)),
- color: Some(vec4(0., 0.75, 0., 1.))
- }),
- Box::new(Container {
- gap: 5.,
- padding: Sides::all(5.),
- background: Some(vec4(0., 0., 0., 0.5)),
- direction: UiDirection::Horizontal,
- elements: {
- let mut x: Vec> = vec![];
- for i in 0..10 {
- x.push(Box::new(Rect {
- size: (UiSize::Pixels(50.), UiSize::Pixels(50.)),
- color: if i == 1 {
- Some(vec4(0.75, 0.75, 0.75, 0.75))
- } else {
- Some(vec4(0.5, 0.5, 0.5, 0.75))
- }
- }));
- }
- x
- },
- ..Default::default()
- }),
- Box::new(Container {
- background: Some(vec4(1., 0., 0., 1.)),
- padding: Sides {
- top: 10.,
- bottom: 20.,
- left: 30.,
- right: 40.,
- },
- elements: vec![
- Box::new(Rect {
- size: (UiSize::Pixels(50.), UiSize::Pixels(50.)),
- color: Some(vec4(1., 1., 1., 0.75))
- }.into_interactable().on_click(|| {
- println!("clicked");
- }))
- ],
- ..Default::default()
- })
- ],
- ..Default::default()
- }, resolution);
-
- kui.end();
-
- backend.update(&kui);
- backend.draw(&mut frame, resolution);
-
- frame.finish().unwrap();
- }
- _ => (),
- }
- }).unwrap();
-}
diff --git a/kubi-ui-examples/examples/text_weird.rs b/kubi-ui-examples/examples/text_weird.rs
deleted file mode 100644
index 2c64884..0000000
--- a/kubi-ui-examples/examples/text_weird.rs
+++ /dev/null
@@ -1,116 +0,0 @@
-use std::{time::Instant, vec};
-use glam::{UVec2, vec4};
-use glium::{backend::glutin::SimpleWindowBuilder, Surface};
-use winit::{
- event::{Event, WindowEvent},
- event_loop::{EventLoopBuilder, ControlFlow}
-};
-use kubi_ui::{
- KubiUi,
- element::{
- progress_bar::ProgressBar,
- container::{Container, Sides, Alignment},
- text::Text, rect::Rect, spacer::Spacer
- },
- UiSize,
- elements,
-};
-use kubi_ui_glium::GliumUiRenderer;
-
-fn main() {
- kubi_logging::init();
-
- let event_loop = EventLoopBuilder::new().build().unwrap();
- let (window, display) = SimpleWindowBuilder::new().build(&event_loop);
- window.set_title("Text rendering test");
-
- let mut kui = KubiUi::new();
- let mut backend = GliumUiRenderer::new(&display);
-
- let font_handle = kui.add_font_from_bytes(include_bytes!("../../assets/fonts/roboto/Roboto-Regular.ttf"));
- let instant = Instant::now();
-
- event_loop.run(|event, window_target| {
- window_target.set_control_flow(ControlFlow::Poll);
- match event {
- Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
- window_target.exit();
- },
- Event::AboutToWait => {
- let mut frame = display.draw();
- frame.clear_color_srgb(0., 0., 0., 1.);
-
- let resolution = UVec2::from(display.get_framebuffer_dimensions()).as_vec2();
-
- kui.begin();
-
- kui.add(Container {
- size: (UiSize::Percentage(1.), UiSize::Percentage(1.)),
- background: Some(vec4(0.1, 0.1, 0.1, 1.)),
- elements: elements(|elem| {
- elem.add(Text {
- text: "THIS LINE SHOULD BE SHARP!".into(),
- ..Default::default()
- });
- elem.add(Text {
- text: "THIS LINE SHOULD BE SHARP!".into(),
- text_size: 32,
- ..Default::default()
- });
- elem.add(Text {
- text: "All lines except 3 and 6 below will be blurry:".into(),
- ..Default::default()
- });
- for size in [9, 12, 16, 18, 24, 32] {
- elem.add(Text {
- text: "Testing default font, Proggy Tiny".into(),
- text_size: size,
- ..Default::default()
- });
- }
- elem.add(Rect {
- size: (UiSize::Percentage(1.), UiSize::Pixels(10.)),
- color: Some(vec4(0., 0., 1., 1.)),
- });
- elem.add(Rect {
- size: (UiSize::Percentage(1.), UiSize::Pixels(10.)),
- color: Some(vec4(1., 1., 0., 1.)),
- });
- elem.add(Text {
- text: "Hello, world!\nżółty liść. życie nie ma sensu i wszyscy zginemy;\nтест кирилиці їїїїїїїїїїї\njapanese text: テスト".into(),
- font: font_handle,
- text_size: 32,
- ..Default::default()
- });
- if instant.elapsed().as_secs() & 1 != 0 {
- elem.add(Rect {
- size: (UiSize::Percentage(1.), UiSize::Pixels(10.)),
- color: Some(vec4(1., 0., 0., 1.)),
- });
- elem.add(Rect {
- size: (UiSize::Percentage(1.), UiSize::Pixels(10.)),
- color: Some(vec4(0., 0., 0., 1.)),
- });
- elem.add(Spacer(100.));
- elem.add(Text {
- text: "FLAG SHOULD NOT OVERLAP WITH TEXT".into(),
- text_size: 64,
- color: vec4(1., 0., 1., 1.),
- ..Default::default()
- });
- }
- }),
- ..Default::default()
- }, resolution);
-
- kui.end();
-
- backend.update(&kui);
- backend.draw(&mut frame, resolution);
-
- frame.finish().unwrap();
- }
- _ => (),
- }
- }).unwrap();
-}
diff --git a/kubi-ui-glium/Cargo.toml b/kubi-ui-glium/Cargo.toml
deleted file mode 100644
index d4375de..0000000
--- a/kubi-ui-glium/Cargo.toml
+++ /dev/null
@@ -1,12 +0,0 @@
-[package]
-name = "kubi-ui-glium"
-version = "0.0.0"
-edition = "2021"
-publish = false
-
-[dependencies]
-kubi-ui = { path = "../kubi-ui", default-features = false }
-#kubi-ui = { path = "../kubi-ui" }
-glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
-glam = "0.25"
-log = "0.4"
diff --git a/kubi-ui-glium/shaders/fragment.frag b/kubi-ui-glium/shaders/fragment.frag
deleted file mode 100644
index 2f60ee9..0000000
--- a/kubi-ui-glium/shaders/fragment.frag
+++ /dev/null
@@ -1,12 +0,0 @@
-#version 300 es
-
-precision highp float;
-precision highp sampler2D;
-
-out vec4 out_color;
-in vec4 vtx_color;
-in vec2 vtx_uv;
-
-void main() {
- out_color = vtx_color;
-}
diff --git a/kubi-ui-glium/shaders/fragment_tex.frag b/kubi-ui-glium/shaders/fragment_tex.frag
deleted file mode 100644
index d4c5b82..0000000
--- a/kubi-ui-glium/shaders/fragment_tex.frag
+++ /dev/null
@@ -1,13 +0,0 @@
-#version 300 es
-
-precision highp float;
-precision highp sampler2D;
-
-out vec4 out_color;
-in vec4 vtx_color;
-in vec2 vtx_uv;
-uniform sampler2D tex;
-
-void main() {
- out_color = texture(tex, vtx_uv) * vtx_color;
-}
diff --git a/kubi-ui-glium/shaders/vertex.vert b/kubi-ui-glium/shaders/vertex.vert
deleted file mode 100644
index 6df175f..0000000
--- a/kubi-ui-glium/shaders/vertex.vert
+++ /dev/null
@@ -1,17 +0,0 @@
-#version 300 es
-
-precision highp float;
-
-uniform vec2 resolution;
-in vec2 uv;
-in vec4 color;
-in vec2 position;
-out vec4 vtx_color;
-out vec2 vtx_uv;
-
-void main() {
- vtx_color = color;
- vtx_uv = uv;
- vec2 pos2d = (vec2(2., -2.) * (position / resolution)) + vec2(-1, 1);
- gl_Position = vec4(pos2d, 0., 1.);
-}
diff --git a/kubi-ui-glium/src/lib.rs b/kubi-ui-glium/src/lib.rs
deleted file mode 100644
index 39d647e..0000000
--- a/kubi-ui-glium/src/lib.rs
+++ /dev/null
@@ -1,229 +0,0 @@
-use std::rc::Rc;
-use glam::Vec2;
-use glium::{
- Surface, DrawParameters, Blend,
- Program, VertexBuffer, IndexBuffer,
- backend::{Facade, Context},
- texture::{SrgbTexture2d, RawImage2d},
- index::PrimitiveType,
- implement_vertex,
- uniform, uniforms::{Sampler, SamplerBehavior, SamplerWrapFunction},
-};
-use kubi_ui::{
- KubiUi,
- draw::{UiDrawPlan, UiVertex, BindTexture},
- text::FontTextureInfo, IfModified,
-};
-
-const VERTEX_SHADER: &str = include_str!("../shaders/vertex.vert");
-const FRAGMENT_SHADER: &str = include_str!("../shaders/fragment.frag");
-const FRAGMENT_SHADER_TEX: &str = include_str!("../shaders/fragment_tex.frag");
-
-#[derive(Clone, Copy)]
-#[repr(C)]
-struct Vertex {
- position: [f32; 2],
- color: [f32; 4],
- uv: [f32; 2],
-}
-
-impl From for Vertex {
- fn from(v: UiVertex) -> Self {
- Self {
- position: v.position.to_array(),
- color: v.color.to_array(),
- uv: v.uv.to_array(),
- }
- }
-}
-
-implement_vertex!(Vertex, position, color, uv);
-
-struct BufferPair {
- pub vertex_buffer: glium::VertexBuffer,
- pub index_buffer: glium::IndexBuffer,
- pub vertex_count: usize,
- pub index_count: usize,
-}
-
-impl BufferPair {
- pub fn new(facade: &F) -> Self {
- log::debug!("init ui buffers...");
- Self {
- vertex_buffer: VertexBuffer::empty_dynamic(facade, 1024).unwrap(),
- index_buffer: IndexBuffer::empty_dynamic(facade, PrimitiveType::TrianglesList, 1024).unwrap(),
- vertex_count: 0,
- index_count: 0,
- }
- }
-
- pub fn ensure_buffer_size(&mut self, need_vtx: usize, need_idx: usize) {
- let current_vtx_size = self.vertex_buffer.get_size() / std::mem::size_of::();
- let current_idx_size = self.index_buffer.get_size() / std::mem::size_of::();
- //log::debug!("current vtx size: {}, current idx size: {}", current_vtx_size, current_idx_size);
- if current_vtx_size >= need_vtx && current_idx_size >= need_idx {
- return
- }
- let new_vtx_size = (need_vtx + 1).next_power_of_two();
- let new_idx_size = (need_idx + 1).next_power_of_two();
- log::debug!("resizing buffers: vtx {} -> {}, idx {} -> {}", current_vtx_size, new_vtx_size, current_idx_size, new_idx_size);
- if current_vtx_size != new_vtx_size {
- self.vertex_buffer = VertexBuffer::empty_dynamic(
- self.vertex_buffer.get_context(),
- new_vtx_size
- ).unwrap();
- }
- if current_idx_size != new_idx_size {
- self.index_buffer = IndexBuffer::empty_dynamic(
- self.index_buffer.get_context(),
- PrimitiveType::TrianglesList,
- new_idx_size
- ).unwrap();
- }
- }
-
- pub fn write_data(&mut self, vtx: &[Vertex], idx: &[u32]) {
- //log::trace!("uploading {} vertices and {} indices", vtx.len(), idx.len());
-
- self.vertex_count = vtx.len();
- self.index_count = idx.len();
-
- self.vertex_buffer.invalidate();
- self.index_buffer.invalidate();
-
- if self.vertex_count == 0 || self.index_count == 0 {
- return
- }
-
- self.ensure_buffer_size(self.vertex_count, self.index_count);
-
- self.vertex_buffer.slice_mut(0..self.vertex_count).unwrap().write(vtx);
- self.index_buffer.slice_mut(0..self.index_count).unwrap().write(idx);
- }
-
- pub fn is_empty(&self) -> bool {
- self.vertex_count == 0 || self.index_count == 0
- }
-}
-
-struct GlDrawCall {
- active: bool,
- buffer: BufferPair,
- bind_texture: Option>,
-}
-
-pub struct GliumUiRenderer {
- context: Rc,
- program: glium::Program,
- program_tex: glium::Program,
- font_texture: Option>,
- plan: Vec,
-}
-
-impl GliumUiRenderer {
- pub fn new(facade: &F) -> Self {
- log::info!("init glium backend for kui");
- Self {
- program: Program::from_source(facade, VERTEX_SHADER, FRAGMENT_SHADER, None).unwrap(),
- program_tex: Program::from_source(facade, VERTEX_SHADER, FRAGMENT_SHADER_TEX, None).unwrap(),
- context: Rc::clone(facade.get_context()),
- font_texture: None,
- plan: vec![]
- }
- }
-
- pub fn update_draw_plan(&mut self, plan: &UiDrawPlan) {
- if plan.calls.len() > self.plan.len() {
- self.plan.resize_with(plan.calls.len(), || {
- GlDrawCall {
- buffer: BufferPair::new(&self.context),
- bind_texture: None,
- active: false,
- }
- });
- } else {
- for step in &mut self.plan[plan.calls.len()..] {
- step.active = false;
- }
- }
- for (idx, call) in plan.calls.iter().enumerate() {
- let data_vtx = &call.vertices.iter().copied().map(Vertex::from).collect::>()[..];
- let data_idx = &call.indices[..];
- self.plan[idx].active = true;
- self.plan[idx].buffer.write_data(data_vtx, data_idx);
- self.plan[idx].bind_texture = match call.bind_texture {
- Some(BindTexture::FontTexture) => {
- const NO_FNT_TEX: &str = "Font texture exists in draw plan but not yet inited. Make sure to call update_font_texture() *before* update_draw_plan()";
- Some(Rc::clone(self.font_texture.as_ref().expect(NO_FNT_TEX)))
- },
- None => None,
- }
- }
- }
-
- pub fn update_font_texture(&mut self, font_texture: &FontTextureInfo) {
- log::debug!("updating font texture");
- self.font_texture = Some(Rc::new(SrgbTexture2d::new(
- &self.context,
- RawImage2d::from_raw_rgba(
- font_texture.data.to_owned(),
- (font_texture.size.x, font_texture.size.y)
- )
- ).unwrap()));
- }
-
- pub fn update(&mut self, kui: &KubiUi) {
- if let Some(texture) = kui.font_texture().if_modified() {
- self.update_font_texture(texture);
- }
- if let Some(plan) = kui.draw_plan().if_modified() {
- self.update_draw_plan(plan);
- }
- }
-
- pub fn draw(&self, frame: &mut glium::Frame, resolution: Vec2) {
- let params = DrawParameters {
- blend: Blend::alpha_blending(),
- ..Default::default()
- };
-
- for step in &self.plan {
- if !step.active {
- continue
- }
-
- if step.buffer.is_empty() {
- continue
- }
-
- let vtx_buffer = step.buffer.vertex_buffer.slice(0..step.buffer.vertex_count).unwrap();
- let idx_buffer = step.buffer.index_buffer.slice(0..step.buffer.index_count).unwrap();
-
- if let Some(bind_texture) = step.bind_texture.as_ref() {
- frame.draw(
- vtx_buffer,
- idx_buffer,
- &self.program_tex,
- &uniform! {
- resolution: resolution.to_array(),
- tex: Sampler(bind_texture.as_ref(), SamplerBehavior {
- wrap_function: (SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp),
- ..Default::default()
- }),
- },
- ¶ms,
- ).unwrap();
- } else {
- frame.draw(
- vtx_buffer,
- idx_buffer,
- &self.program,
- &uniform! {
- resolution: resolution.to_array(),
- },
- ¶ms,
- ).unwrap();
- }
- }
- }
-}
diff --git a/kubi-ui/Cargo.toml b/kubi-ui/Cargo.toml
deleted file mode 100644
index 887e1e8..0000000
--- a/kubi-ui/Cargo.toml
+++ /dev/null
@@ -1,19 +0,0 @@
-[package]
-name = "kubi-ui"
-version = "0.0.0"
-edition = "2021"
-publish = false
-
-[dependencies]
-hashbrown = "0.14"
-nohash-hasher = "0.2"
-glam = "0.25"
-fontdue = "0.8"
-rect_packer = "0.2"
-log = "0.4"
-
-[features]
-default = ["builtin_elements", "builtin_font"]
-builtin_font = []
-builtin_elements = []
-#parallel = ["dep:rayon", "fontdue/parallel"]
diff --git a/kubi-ui/assets/font/Licence.txt b/kubi-ui/assets/font/Licence.txt
deleted file mode 100644
index ad4a6b6..0000000
--- a/kubi-ui/assets/font/Licence.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-Copyright (c) 2004, 2005 Tristan Grimmer
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/kubi-ui/assets/font/ProggyTiny.ttf b/kubi-ui/assets/font/ProggyTiny.ttf
deleted file mode 100644
index 1c4312c..0000000
Binary files a/kubi-ui/assets/font/ProggyTiny.ttf and /dev/null differ
diff --git a/kubi-ui/src/draw.rs b/kubi-ui/src/draw.rs
deleted file mode 100644
index 610916b..0000000
--- a/kubi-ui/src/draw.rs
+++ /dev/null
@@ -1,220 +0,0 @@
-use crate::{IfModified, text::{TextRenderer, FontHandle}};
-
-use std::borrow::Cow;
-use fontdue::layout::{Layout, CoordinateSystem, TextStyle};
-use glam::{Vec2, Vec4, vec2};
-
-#[derive(Clone, Debug, PartialEq)]
-pub enum UiDrawCommand {
- ///Filled, colored rectangle
- Rectangle {
- ///Position in pixels
- position: Vec2,
- ///Size in pixels
- 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>,
- ///Font handle to use
- font: FontHandle,
- },
-}
-
-#[derive(Default)]
-pub struct UiDrawCommands {
- pub commands: Vec,
-}
-
-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 }
-// // self.commands.iter().zip(other.commands.iter()).all(|(a, b)| a == b)
-// }
-// }
-
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum BindTexture {
- FontTexture,
- //UserDefined(usize),
-}
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct UiVertex {
- pub position: Vec2,
- pub color: Vec4,
- pub uv: Vec2,
-}
-
-#[derive(Default)]
-pub struct UiDrawCall {
- pub vertices: Vec,
- pub indices: Vec,
- pub bind_texture: Option,
-}
-
-#[derive(Default)]
-pub struct UiDrawPlan {
- pub calls: Vec
-}
-
-struct CallSwapper {
- calls: Vec,
- call: UiDrawCall,
-}
-
-impl CallSwapper {
- pub fn new() -> Self {
- Self {
- calls: vec![],
- call: UiDrawCall::default(),
- }
- }
-
- pub fn current(&self) -> &UiDrawCall {
- &self.call
- }
-
- pub fn current_mut(&mut self) -> &mut UiDrawCall {
- &mut self.call
- }
-
- pub fn swap(&mut self) {
- self.calls.push(std::mem::replace(&mut self.call, UiDrawCall::default()));
- }
-
- pub fn finish(mut self) -> Vec {
- self.calls.push(self.call);
- self.calls
- }
-}
-
-impl UiDrawPlan {
- pub fn build(draw_commands: &UiDrawCommands, tr: &mut TextRenderer) -> Self {
- let mut swapper = CallSwapper::new();
- let mut prev_command = None;
- for command in &draw_commands.commands {
-
- let do_swap = if let Some(prev_command) = prev_command {
- std::mem::discriminant(prev_command) != std::mem::discriminant(command)
- } else {
- false
- };
-
- if do_swap {
- swapper.swap();
- }
-
- if do_swap || prev_command.is_none() {
- match command {
- UiDrawCommand::Rectangle { .. } => (),
- UiDrawCommand::Text { .. } => {
- swapper.current_mut().bind_texture = Some(BindTexture::FontTexture);
- }
- }
- }
-
- match command {
- UiDrawCommand::Rectangle { position, size, color } => {
- let vidx = swapper.current().vertices.len() as u32;
- swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]);
- swapper.current_mut().vertices.extend([
- UiVertex {
- position: *position,
- color: *color,
- uv: vec2(0.0, 0.0),
- },
- UiVertex {
- position: *position + vec2(size.x, 0.0),
- color: *color,
- uv: vec2(1.0, 0.0),
- },
- UiVertex {
- position: *position + *size,
- color: *color,
- uv: vec2(1.0, 1.0),
- },
- UiVertex {
- position: *position + vec2(0.0, size.y),
- color: *color,
- uv: vec2(0.0, 1.0),
- },
- ]);
- },
- UiDrawCommand::Text { position, size, color, text, font } => {
- //XXX: should we be doing this every time?
- let mut layout = Layout::new(CoordinateSystem::PositiveYDown);
- layout.append(
- &[tr.internal_font(*font)],
- &TextStyle::new(text, *size as f32, 0)
- );
- let glyphs = layout.glyphs();
-
- //let mut rpos_x = 0.;
- for layout_glyph in glyphs {
- if !layout_glyph.char_data.rasterize() {
- continue
- }
- let vidx = swapper.current().vertices.len() as u32;
- let glyph = tr.glyph(*font, layout_glyph.parent, layout_glyph.key.px as u8);
- //rpos_x += glyph.metrics.advance_width;//glyph.metrics.advance_width;
- swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]);
- let p0x = glyph.position.x as f32 / 1024.;
- let p1x = (glyph.position.x + glyph.size.x as i32) as f32 / 1024.;
- let p0y = glyph.position.y as f32 / 1024.;
- let p1y = (glyph.position.y + glyph.size.y as i32) as f32 / 1024.;
- swapper.current_mut().vertices.extend([
- UiVertex {
- position: *position + vec2(layout_glyph.x, layout_glyph.y),
- color: *color,
- uv: vec2(p0x, p0y),
- },
- UiVertex {
- position: *position + vec2(layout_glyph.x + glyph.metrics.width as f32, layout_glyph.y),
- color: *color,
- uv: vec2(p1x, p0y),
- },
- UiVertex {
- position: *position + vec2(layout_glyph.x + glyph.metrics.width as f32, layout_glyph.y + glyph.metrics.height as f32),
- color: *color,
- uv: vec2(p1x, p1y),
- },
- UiVertex {
- position: *position + vec2(layout_glyph.x, layout_glyph.y + glyph.metrics.height as f32),
- color: *color,
- uv: vec2(p0x, p1y),
- },
- ]);
- }
- }
- }
- prev_command = Some(command);
- }
- Self {
- calls: swapper.finish()
- }
- }
-}
-
-impl IfModified for (bool, &UiDrawPlan) {
- fn if_modified(&self) -> Option<&UiDrawPlan> {
- match self.0 {
- true => Some(self.1),
- false => None,
- }
- }
-}
diff --git a/kubi-ui/src/element.rs b/kubi-ui/src/element.rs
deleted file mode 100644
index 8e5edfa..0000000
--- a/kubi-ui/src/element.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-use std::any::Any;
-use crate::{
- LayoutInfo,
- draw::UiDrawCommands,
- measure::Response,
- state::StateRepo
-};
-
-#[cfg(feature = "builtin_elements")]
-mod builtin {
- pub mod rect;
- pub mod container;
- pub mod spacer;
- pub mod progress_bar;
- pub mod text;
-}
-
-#[cfg(feature = "builtin_elements")]
-pub use builtin::*;
-
-pub trait UiElement {
- fn name(&self) -> &'static str { "UiElement" }
- fn state_id(&self) -> Option { None }
- fn is_stateful(&self) -> bool { self.state_id().is_some() }
- fn is_stateless(&self) -> bool { self.state_id().is_none() }
- fn init_state(&self) -> Option> { None }
- fn measure(&self, state: &StateRepo, layout: &LayoutInfo) -> Response;
- fn process(&self, measure: &Response, state: &mut StateRepo, layout: &LayoutInfo, draw: &mut UiDrawCommands);
-}
diff --git a/kubi-ui/src/element/builtin/container.rs b/kubi-ui/src/element/builtin/container.rs
deleted file mode 100644
index a666425..0000000
--- a/kubi-ui/src/element/builtin/container.rs
+++ /dev/null
@@ -1,237 +0,0 @@
-use glam::{Vec2, vec2, Vec4};
-use crate::{
- UiDirection,
- UiSize,
- LayoutInfo,
- draw::{UiDrawCommand, UiDrawCommands},
- measure::{Response, Hints},
- state::StateRepo,
- element::UiElement
-};
-
-#[derive(Clone, Copy, PartialEq, Eq, Debug)]
-pub enum Alignment {
- Begin,
- Center,
- End,
-}
-
-pub struct Border {
- pub color: Vec4,
- pub width: f32,
-}
-
-#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
-pub struct Sides {
- pub top: T,
- pub bottom: T,
- pub left: T,
- pub right: T,
-}
-
-impl Sides {
- #[inline]
- pub fn all(value: T) -> Self {
- Self {
- top: value.clone(),
- bottom: value.clone(),
- left: value.clone(),
- right: value,
- }
- }
-
- #[inline]
- pub fn horizontal_vertical(horizontal: T, vertical: T) -> Self {
- Self {
- top: vertical.clone(),
- bottom: vertical,
- left: horizontal.clone(),
- right: horizontal,
- }
- }
-}
-
-pub struct Container {
- // pub min_size: (UiSize, UiSize),
- // pub max_size: (UiSize, UiSize),
- pub size: (UiSize, UiSize),
- pub direction: UiDirection,
- //pub reverse: bool,
- pub gap: f32,
- pub padding: Sides,
- ///Primary/secondary axis
- pub align: (Alignment, Alignment),
- pub background: Option,
- pub borders: Sides