Compare commits

..

No commits in common. "cc32082c211e8ddd79f4ba6294ada89bdfec4486" and "0b210eac5dd2afd356b1e510e27383464cdb32ed" have entirely different histories.

11 changed files with 42 additions and 227 deletions

60
Cargo.lock generated
View file

@ -112,6 +112,15 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]]
name = "arrayref"
version = "0.3.7"
@ -541,17 +550,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fontdue"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0793f5137567643cf65ea42043a538804ff0fbf288649e2141442b602d81f9bc"
dependencies = [
"hashbrown 0.13.2",
"rayon",
"ttf-parser 0.15.2",
]
[[package]]
name = "foreign-types"
version = "0.5.0"
@ -672,6 +670,7 @@ version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945"
dependencies = [
"approx",
"serde",
]
@ -767,16 +766,6 @@ dependencies = [
"byteorder",
]
[[package]]
name = "hashbrown"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [
"ahash",
"rayon",
]
[[package]]
name = "hashbrown"
version = "0.14.2"
@ -852,7 +841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown 0.14.2",
"hashbrown",
]
[[package]]
@ -960,7 +949,7 @@ dependencies = [
"glium",
"glutin",
"glutin-winit",
"hashbrown 0.14.2",
"hashbrown",
"image",
"kubi-logging",
"kubi-shared",
@ -1002,7 +991,7 @@ dependencies = [
"anyhow",
"flume",
"glam",
"hashbrown 0.14.2",
"hashbrown",
"kubi-logging",
"kubi-shared",
"log",
@ -1025,7 +1014,7 @@ dependencies = [
"bincode",
"bracket-noise",
"glam",
"hashbrown 0.14.2",
"hashbrown",
"nohash-hasher",
"num_enum",
"postcard",
@ -1041,15 +1030,12 @@ dependencies = [
name = "kubi-ui"
version = "0.0.0"
dependencies = [
"fontdue",
"glam",
"glium",
"hashbrown 0.14.2",
"hashbrown",
"kubi-logging",
"log",
"nohash-hasher",
"rayon",
"rect_packer",
"winit",
]
@ -1380,7 +1366,7 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4586edfe4c648c71797a74c84bacb32b52b212eff5dfe2bb9f2c599844023e7"
dependencies = [
"ttf-parser 0.20.0",
"ttf-parser",
]
[[package]]
@ -1573,12 +1559,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "rect_packer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8ffb4dfda4b01cc420847665dc480760d596ce186f2772a66ed32fe9acb1c45"
[[package]]
name = "redox_syscall"
version = "0.3.5"
@ -1762,7 +1742,7 @@ name = "shipyard"
version = "0.6.0"
source = "git+https://github.com/leudz/shipyard?rev=8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49#8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49"
dependencies = [
"hashbrown 0.14.2",
"hashbrown",
"lock_api",
"rayon",
"serde",
@ -2031,12 +2011,6 @@ version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
[[package]]
name = "ttf-parser"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
[[package]]
name = "ttf-parser"
version = "0.20.0"

View file

@ -7,12 +7,9 @@ publish = false
[dependencies]
hashbrown = "0.14"
nohash-hasher = "0.2"
glam = "0.24"
glam = { version = "0.24", features = ["approx"] }
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf", optional = true }
fontdue = "0.7"
rect_packer = { version = "0.2.1", optional = true }
log = "0.4"
rayon = { version = "1.8", optional = true }
[dev-dependencies]
kubi-logging = { path = "../kubi-logging" }
@ -20,8 +17,6 @@ glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
winit = "0.29"
[features]
default = ["builtin_elements", "builtin_font", "backend_glium", "parallel"]
default = ["backend_glium", "builtin"]
backend_glium = ["dep:glium"]
builtin_font = []
builtin_elements = []
parallel = ["dep:rayon", "fontdue/parallel"]
builtin = []

View file

@ -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.

Binary file not shown.

View file

@ -1,87 +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,
backend::glium::GliumUiRenderer, element::{progress_bar::ProgressBar, container::{Container, Sides}, UiElement}, UiSize
};
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<Box<dyn UiElement>> = 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();
let plan = kui.draw_plan();
if plan.0 {
backend.update(plan.1);
}
backend.draw(&mut frame, resolution);
frame.finish().unwrap();
}
_ => (),
}
}).unwrap();
}

View file

@ -20,6 +20,7 @@ fn main() {
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 {
@ -46,6 +47,21 @@ fn main() {
value: instant.elapsed().as_secs_f32().sin().powi(2),
..Default::default()
}),
Box::new(Container {
gap: 1.,
elements: {
let mut elements: Vec<Box<dyn UiElement>> = vec![];
for i in 0..10000 {
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);

View file

@ -13,11 +13,9 @@ const VERTEX_SHADER: &str = include_str!("../../shaders/vertex.vert");
const FRAGMENT_SHADER: &str = include_str!("../../shaders/fragment.frag");
#[derive(Clone, Copy)]
#[repr(C)]
struct Vertex {
position: [f32; 2],
color: [f32; 4],
uv: [f32; 2],
}
impl From<UiVertex> for Vertex {
@ -25,12 +23,11 @@ impl From<UiVertex> for Vertex {
Self {
position: v.position.to_array(),
color: v.color.to_array(),
uv: v.uv.to_array(),
}
}
}
implement_vertex!(Vertex, position, color, uv);
implement_vertex!(Vertex, position, color);
struct BufferPair {
vertex_buffer: glium::VertexBuffer<Vertex>,
@ -76,7 +73,7 @@ impl BufferPair {
}
pub fn write_data(&mut self, vtx: &[Vertex], idx: &[u32]) {
//log::trace!("uploading {} vertices and {} indices", vtx.len(), idx.len());
log::debug!("uploading {} vertices and {} indices", vtx.len(), idx.len());
self.vertex_count = vtx.len();
self.index_count = idx.len();

View file

@ -1,4 +1,5 @@
use glam::{Vec2, Vec4, vec2};
use std::num::NonZeroU16;
use glam::{Vec2, Vec4};
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum UiDrawCommand {
@ -29,7 +30,6 @@ pub struct UiDrawCommands {
pub struct UiVertex {
pub position: Vec2,
pub color: Vec4,
pub uv: Vec2,
//pub texture: Option<NonZeroU16>,
}
@ -56,22 +56,18 @@ impl UiDrawPlan {
UiVertex {
position: *position,
color: *color,
uv: vec2(0.0, 0.0),
},
UiVertex {
position: *position + Vec2::new(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::new(0.0, size.y),
color: *color,
uv: vec2(0.0, 1.0),
},
]);
}

View file

@ -6,7 +6,7 @@ use crate::{
state::StateRepo
};
#[cfg(feature = "builtin_elements")]
#[cfg(feature = "builtin")]
mod builtin {
pub mod rect;
pub mod container;
@ -14,7 +14,7 @@ mod builtin {
pub mod progress_bar;
}
#[cfg(feature = "builtin_elements")]
#[cfg(feature = "builtin")]
pub use builtin::*;
pub trait UiElement {

View file

@ -7,19 +7,11 @@ pub mod draw;
pub mod backend;
pub mod measure;
pub mod state;
pub mod text;
use element::UiElement;
use state::StateRepo;
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 KubiUi {
mouse_position: Vec2,
@ -29,7 +21,6 @@ pub struct KubiUi {
draw_commands: UiDrawCommands,
draw_plan: UiDrawPlan,
draw_plan_modified: bool,
font_renderer: TextRenderer,
}
impl KubiUi {
@ -43,7 +34,6 @@ impl KubiUi {
draw_commands: UiDrawCommands::default(),
draw_plan: UiDrawPlan::default(),
draw_plan_modified: false,
font_renderer: TextRenderer::new(),
}
}

View file

@ -1,59 +0,0 @@
use fontdue::{Font, Metrics};
use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
#[cfg(feature = "builtin_font")]
const BIN_FONT: &[u8] = include_bytes!("../assets/font/ProggyTiny.ttf");
// pub struct Glyph {
// pub metrics: Metrics,
// pub data: Box<[u8]>
// }
// pub struct FontData {
// font: Font,
// cache: HashMap<(u8, char), Glyph, BuildNoHashHasher<u8>>
// }
// impl FontData {
// pub fn new() -> Self {
// FontData {
// font: Font::from_bytes(BIN_FONT, fontdue::FontSettings::default()).unwrap(),
// cache: HashMap::default()
// }
// }
// fn prebake(&mut self, size: u8) {
// self.cache = (33..=126).par_bridge().map(|c| {
// let (metrics, data) = self.font.rasterize(
// char::from(c),
// c as f32,
// );
// Glyph { metrics, data: data.into_boxed_slice() }
// }).collect();
// }
// }
pub struct TextRenderer {
font_stack: Vec<Font>,
cache: ()
}
impl TextRenderer {
pub fn new() -> Self {
let font = Font::from_bytes(BIN_FONT, fontdue::FontSettings::default()).unwrap();
TextRenderer {
font_stack: vec![font],
cache: ()
}
}
}
impl Default for TextRenderer {
fn default() -> Self {
Self::new()
}
}