mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 11:58:21 -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]]
|
||||
name = "fontdue"
|
||||
version = "0.7.3"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0793f5137567643cf65ea42043a538804ff0fbf288649e2141442b602d81f9bc"
|
||||
checksum = "9099a2f86b8e674b75d03ff154b3fe4c5208ed249ced8d69cc313a9fa40bb488"
|
||||
dependencies = [
|
||||
"hashbrown 0.13.2",
|
||||
"ttf-parser 0.15.2",
|
||||
"hashbrown",
|
||||
"ttf-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -766,15 +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",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.2"
|
||||
|
@ -850,7 +841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.14.2",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -958,11 +949,12 @@ dependencies = [
|
|||
"glium",
|
||||
"glutin",
|
||||
"glutin-winit",
|
||||
"hashbrown 0.14.2",
|
||||
"hashbrown",
|
||||
"image",
|
||||
"kubi-logging",
|
||||
"kubi-shared",
|
||||
"kubi-ui",
|
||||
"kubi-ui-glium",
|
||||
"log",
|
||||
"lz4_flex",
|
||||
"ndk",
|
||||
|
@ -1000,7 +992,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"flume",
|
||||
"glam",
|
||||
"hashbrown 0.14.2",
|
||||
"hashbrown",
|
||||
"kubi-logging",
|
||||
"kubi-shared",
|
||||
"log",
|
||||
|
@ -1023,7 +1015,7 @@ dependencies = [
|
|||
"bincode",
|
||||
"bracket-noise",
|
||||
"glam",
|
||||
"hashbrown 0.14.2",
|
||||
"hashbrown",
|
||||
"nohash-hasher",
|
||||
"num_enum",
|
||||
"nz",
|
||||
|
@ -1043,14 +1035,25 @@ dependencies = [
|
|||
"fontdue",
|
||||
"glam",
|
||||
"glium",
|
||||
"hashbrown 0.14.2",
|
||||
"hashbrown",
|
||||
"kubi-logging",
|
||||
"kubi-ui-glium",
|
||||
"log",
|
||||
"nohash-hasher",
|
||||
"rect_packer",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kubi-ui-glium"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"glam",
|
||||
"glium",
|
||||
"kubi-ui",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
|
@ -1384,7 +1387,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]]
|
||||
|
@ -1766,7 +1769,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",
|
||||
|
@ -2035,12 +2038,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"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[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"]
|
||||
resolver = "2"
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ name = "Kubi Server" # server name
|
|||
|
||||
- [`kubi-ui`](kubi-ui): semi-imm.mode backend-agnostic ui system\
|
||||
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\
|
||||
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`
|
||||
|
|
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,
|
||||
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)]
|
||||
#[repr(C)]
|
|
@ -8,19 +8,18 @@ publish = false
|
|||
hashbrown = "0.14"
|
||||
nohash-hasher = "0.2"
|
||||
glam = "0.24"
|
||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf", optional = true }
|
||||
fontdue = "0.7"
|
||||
fontdue = "0.8"
|
||||
rect_packer = "0.2"
|
||||
log = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
kubi-logging = { path = "../kubi-logging" }
|
||||
kubi-ui-glium = { path = "../kubi-ui-glium" }
|
||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
||||
winit = "0.29"
|
||||
|
||||
[features]
|
||||
default = ["builtin_elements", "builtin_font", "backend_glium"]
|
||||
backend_glium = ["dep:glium"]
|
||||
default = ["builtin_elements", "builtin_font"]
|
||||
builtin_font = []
|
||||
builtin_elements = []
|
||||
#parallel = ["dep:rayon", "fontdue/parallel"]
|
||||
|
|
|
@ -7,8 +7,14 @@ use winit::{
|
|||
};
|
||||
use kubi_ui::{
|
||||
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() {
|
||||
kubi_logging::init();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::time::Instant;
|
||||
use glam::{Vec2, IVec2, UVec2, vec4};
|
||||
use glam::{UVec2, vec4};
|
||||
use glium::{backend::glutin::SimpleWindowBuilder, Surface};
|
||||
use winit::{
|
||||
event::{Event, WindowEvent},
|
||||
|
@ -7,8 +7,17 @@ use winit::{
|
|||
};
|
||||
use kubi_ui::{
|
||||
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() {
|
||||
kubi_logging::init();
|
||||
|
@ -109,7 +118,9 @@ fn main() {
|
|||
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()
|
||||
})
|
||||
|
|
|
@ -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 event;
|
||||
pub mod draw;
|
||||
pub mod backend;
|
||||
pub mod measure;
|
||||
pub mod state;
|
||||
pub mod text;
|
||||
pub mod interaction;
|
||||
|
||||
use element::UiElement;
|
||||
use state::StateRepo;
|
||||
|
|
|
@ -12,6 +12,7 @@ crate-type = ["lib", "cdylib"]
|
|||
kubi-shared = { path = "../kubi-shared" }
|
||||
kubi-logging = { path = "../kubi-logging" }
|
||||
kubi-ui = { path = "../kubi-ui" }
|
||||
kubi-ui-glium = { path = "../kubi-ui-glium" }
|
||||
log = "0.4"
|
||||
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
|
||||
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 crate::rendering::{Renderer, RenderTarget, WindowSize};
|
||||
|
||||
|
|
Loading…
Reference in a new issue