mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
major ui restructure, wip interactable api
This commit is contained in:
parent
2e91b3a9ee
commit
a5612d965f
49
Cargo.lock
generated
49
Cargo.lock
generated
|
@ -543,12 +543,12 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fontdue"
|
name = "fontdue"
|
||||||
version = "0.7.3"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0793f5137567643cf65ea42043a538804ff0fbf288649e2141442b602d81f9bc"
|
checksum = "9099a2f86b8e674b75d03ff154b3fe4c5208ed249ced8d69cc313a9fa40bb488"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown 0.13.2",
|
"hashbrown",
|
||||||
"ttf-parser 0.15.2",
|
"ttf-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -766,15 +766,6 @@ dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.13.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
|
|
||||||
dependencies = [
|
|
||||||
"ahash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.2"
|
version = "0.14.2"
|
||||||
|
@ -850,7 +841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
|
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown 0.14.2",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -958,11 +949,12 @@ dependencies = [
|
||||||
"glium",
|
"glium",
|
||||||
"glutin",
|
"glutin",
|
||||||
"glutin-winit",
|
"glutin-winit",
|
||||||
"hashbrown 0.14.2",
|
"hashbrown",
|
||||||
"image",
|
"image",
|
||||||
"kubi-logging",
|
"kubi-logging",
|
||||||
"kubi-shared",
|
"kubi-shared",
|
||||||
"kubi-ui",
|
"kubi-ui",
|
||||||
|
"kubi-ui-glium",
|
||||||
"log",
|
"log",
|
||||||
"lz4_flex",
|
"lz4_flex",
|
||||||
"ndk",
|
"ndk",
|
||||||
|
@ -1000,7 +992,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"flume",
|
"flume",
|
||||||
"glam",
|
"glam",
|
||||||
"hashbrown 0.14.2",
|
"hashbrown",
|
||||||
"kubi-logging",
|
"kubi-logging",
|
||||||
"kubi-shared",
|
"kubi-shared",
|
||||||
"log",
|
"log",
|
||||||
|
@ -1023,7 +1015,7 @@ dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"bracket-noise",
|
"bracket-noise",
|
||||||
"glam",
|
"glam",
|
||||||
"hashbrown 0.14.2",
|
"hashbrown",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"nz",
|
"nz",
|
||||||
|
@ -1043,14 +1035,25 @@ dependencies = [
|
||||||
"fontdue",
|
"fontdue",
|
||||||
"glam",
|
"glam",
|
||||||
"glium",
|
"glium",
|
||||||
"hashbrown 0.14.2",
|
"hashbrown",
|
||||||
"kubi-logging",
|
"kubi-logging",
|
||||||
|
"kubi-ui-glium",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"rect_packer",
|
"rect_packer",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kubi-ui-glium"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"glam",
|
||||||
|
"glium",
|
||||||
|
"kubi-ui",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -1384,7 +1387,7 @@ version = "0.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d4586edfe4c648c71797a74c84bacb32b52b212eff5dfe2bb9f2c599844023e7"
|
checksum = "d4586edfe4c648c71797a74c84bacb32b52b212eff5dfe2bb9f2c599844023e7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ttf-parser 0.20.0",
|
"ttf-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1766,7 +1769,7 @@ name = "shipyard"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/leudz/shipyard?rev=8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49#8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49"
|
source = "git+https://github.com/leudz/shipyard?rev=8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49#8ef90ea6c4d1eb6c9cb0988f0d2f873f75044d49"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown 0.14.2",
|
"hashbrown",
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"rayon",
|
"rayon",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -2035,12 +2038,6 @@ version = "0.1.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ttf-parser"
|
|
||||||
version = "0.15.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttf-parser"
|
name = "ttf-parser"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging", "kubi-pool", "kubi-ui"]
|
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging", "kubi-pool", "kubi-ui", "kubi-ui-glium"]
|
||||||
default-members = ["kubi"]
|
default-members = ["kubi"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ name = "Kubi Server" # server name
|
||||||
|
|
||||||
- [`kubi-ui`](kubi-ui): semi-imm.mode backend-agnostic ui system\
|
- [`kubi-ui`](kubi-ui): semi-imm.mode backend-agnostic ui system\
|
||||||
mostly ready to use, it has already replaced the Kubi legacy ui
|
mostly ready to use, it has already replaced the Kubi legacy ui
|
||||||
|
- [`kubi-ui-glium`](kubi-ui-backend-glium) Glium-based backend for `kubi-ui`
|
||||||
- [`kubi-pool`](kubi-pool): very early work-in-progress work-stealing threadpool system\
|
- [`kubi-pool`](kubi-pool): very early work-in-progress work-stealing threadpool system\
|
||||||
aiming to replace `rayon` threadpool that's currently used inside the kubi client (for more control over task priority)
|
aiming to replace `rayon` threadpool that's currently used inside the kubi client (for more control over task priority)
|
||||||
- [`kubi-logging`](kubi-logging) fancy-ass custom formatter for `env-logger`
|
- [`kubi-logging`](kubi-logging) fancy-ass custom formatter for `env-logger`
|
||||||
|
|
11
kubi-ui-glium/Cargo.toml
Normal file
11
kubi-ui-glium/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "kubi-ui-glium"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
||||||
|
kubi-ui = { path = "../kubi-ui", no-default-features = true }
|
||||||
|
glam = "0.24"
|
||||||
|
log = "0.4"
|
|
@ -6,11 +6,10 @@ use glium::{
|
||||||
index::PrimitiveType,
|
index::PrimitiveType,
|
||||||
implement_vertex, uniform,
|
implement_vertex, uniform,
|
||||||
};
|
};
|
||||||
|
use kubi_ui::draw::{UiDrawPlan, UiVertex};
|
||||||
|
|
||||||
use crate::draw::{UiDrawPlan, UiVertex};
|
const VERTEX_SHADER: &str = include_str!("../shaders/vertex.vert");
|
||||||
|
const FRAGMENT_SHADER: &str = include_str!("../shaders/fragment.frag");
|
||||||
const VERTEX_SHADER: &str = include_str!("../../shaders/vertex.vert");
|
|
||||||
const FRAGMENT_SHADER: &str = include_str!("../../shaders/fragment.frag");
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
|
@ -8,19 +8,18 @@ publish = false
|
||||||
hashbrown = "0.14"
|
hashbrown = "0.14"
|
||||||
nohash-hasher = "0.2"
|
nohash-hasher = "0.2"
|
||||||
glam = "0.24"
|
glam = "0.24"
|
||||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf", optional = true }
|
fontdue = "0.8"
|
||||||
fontdue = "0.7"
|
|
||||||
rect_packer = "0.2"
|
rect_packer = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
kubi-logging = { path = "../kubi-logging" }
|
kubi-logging = { path = "../kubi-logging" }
|
||||||
|
kubi-ui-glium = { path = "../kubi-ui-glium" }
|
||||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
||||||
winit = "0.29"
|
winit = "0.29"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["builtin_elements", "builtin_font", "backend_glium"]
|
default = ["builtin_elements", "builtin_font"]
|
||||||
backend_glium = ["dep:glium"]
|
|
||||||
builtin_font = []
|
builtin_font = []
|
||||||
builtin_elements = []
|
builtin_elements = []
|
||||||
#parallel = ["dep:rayon", "fontdue/parallel"]
|
#parallel = ["dep:rayon", "fontdue/parallel"]
|
||||||
|
|
|
@ -7,8 +7,14 @@ use winit::{
|
||||||
};
|
};
|
||||||
use kubi_ui::{
|
use kubi_ui::{
|
||||||
KubiUi,
|
KubiUi,
|
||||||
backend::glium::GliumUiRenderer, element::{progress_bar::ProgressBar, container::{Container, Sides}, UiElement}, UiSize
|
element::{
|
||||||
|
UiElement,
|
||||||
|
progress_bar::ProgressBar,
|
||||||
|
container::{Container, Sides}
|
||||||
|
},
|
||||||
|
UiSize
|
||||||
};
|
};
|
||||||
|
use kubi_ui_glium::GliumUiRenderer;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
kubi_logging::init();
|
kubi_logging::init();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use glam::{Vec2, IVec2, UVec2, vec4};
|
use glam::{UVec2, vec4};
|
||||||
use glium::{backend::glutin::SimpleWindowBuilder, Surface};
|
use glium::{backend::glutin::SimpleWindowBuilder, Surface};
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{Event, WindowEvent},
|
event::{Event, WindowEvent},
|
||||||
|
@ -7,8 +7,17 @@ use winit::{
|
||||||
};
|
};
|
||||||
use kubi_ui::{
|
use kubi_ui::{
|
||||||
KubiUi,
|
KubiUi,
|
||||||
backend::glium::GliumUiRenderer, element::{progress_bar::ProgressBar, container::{Container, Sides, Alignment}, UiElement, rect::Rect}, UiSize, UiDirection
|
element::{
|
||||||
|
UiElement,
|
||||||
|
progress_bar::ProgressBar,
|
||||||
|
container::{Container, Sides, Alignment},
|
||||||
|
rect::Rect
|
||||||
|
},
|
||||||
|
interaction::IntoInteractable,
|
||||||
|
UiSize,
|
||||||
|
UiDirection,
|
||||||
};
|
};
|
||||||
|
use kubi_ui_glium::GliumUiRenderer;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
kubi_logging::init();
|
kubi_logging::init();
|
||||||
|
@ -109,7 +118,9 @@ fn main() {
|
||||||
Box::new(Rect {
|
Box::new(Rect {
|
||||||
size: (UiSize::Pixels(50.), UiSize::Pixels(50.)),
|
size: (UiSize::Pixels(50.), UiSize::Pixels(50.)),
|
||||||
color: Some(vec4(1., 1., 1., 0.75))
|
color: Some(vec4(1., 1., 1., 0.75))
|
||||||
})
|
}.into_interactable().on_click(|| {
|
||||||
|
println!("clicked");
|
||||||
|
}))
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
#[cfg(feature = "backend_glium")]
|
|
||||||
pub mod glium;
|
|
51
kubi-ui/src/interaction.rs
Normal file
51
kubi-ui/src/interaction.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
use crate::element::UiElement;
|
||||||
|
|
||||||
|
pub struct Interactable<T: UiElement> {
|
||||||
|
pub element: T,
|
||||||
|
pub hovered: Option<Box<dyn FnOnce()>>,
|
||||||
|
pub clicked: Option<Box<dyn FnOnce()>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: UiElement> Interactable<T> {
|
||||||
|
pub fn new(element: T) -> Self {
|
||||||
|
Self {
|
||||||
|
element,
|
||||||
|
hovered: None,
|
||||||
|
clicked: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn on_click(self, clicked: impl FnOnce() + 'static) -> Self {
|
||||||
|
Self {
|
||||||
|
clicked: Some(Box::new(clicked)),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn on_hover(self, clicked: impl FnOnce() + 'static) -> Self {
|
||||||
|
Self {
|
||||||
|
clicked: Some(Box::new(clicked)),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: UiElement> UiElement for Interactable<T> {
|
||||||
|
fn measure(&self, state: &crate::state::StateRepo, layout: &crate::LayoutInfo) -> crate::measure::Response {
|
||||||
|
self.element.measure(state, layout)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process(&self, measure: &crate::measure::Response, state: &mut crate::state::StateRepo, layout: &crate::LayoutInfo, draw: &mut Vec<crate::draw::UiDrawCommand>) {
|
||||||
|
self.element.process(measure, state, layout, draw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait IntoInteractable<T: UiElement>: UiElement {
|
||||||
|
fn into_interactable(self) -> Interactable<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: UiElement> IntoInteractable<T> for T {
|
||||||
|
fn into_interactable(self) -> Interactable<Self> {
|
||||||
|
Interactable::new(self)
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,10 @@ use glam::Vec2;
|
||||||
pub mod element;
|
pub mod element;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod draw;
|
pub mod draw;
|
||||||
pub mod backend;
|
|
||||||
pub mod measure;
|
pub mod measure;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
pub mod interaction;
|
||||||
|
|
||||||
use element::UiElement;
|
use element::UiElement;
|
||||||
use state::StateRepo;
|
use state::StateRepo;
|
||||||
|
|
|
@ -12,6 +12,7 @@ crate-type = ["lib", "cdylib"]
|
||||||
kubi-shared = { path = "../kubi-shared" }
|
kubi-shared = { path = "../kubi-shared" }
|
||||||
kubi-logging = { path = "../kubi-logging" }
|
kubi-logging = { path = "../kubi-logging" }
|
||||||
kubi-ui = { path = "../kubi-ui" }
|
kubi-ui = { path = "../kubi-ui" }
|
||||||
|
kubi-ui-glium = { path = "../kubi-ui-glium" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
||||||
glutin = "0.31"
|
glutin = "0.31"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use kubi_ui::{KubiUi, backend::glium::GliumUiRenderer};
|
use kubi_ui::KubiUi;
|
||||||
|
use kubi_ui_glium::GliumUiRenderer;
|
||||||
use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut};
|
use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut};
|
||||||
use crate::rendering::{Renderer, RenderTarget, WindowSize};
|
use crate::rendering::{Renderer, RenderTarget, WindowSize};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue