mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
Compare commits
4 commits
bd327c86f3
...
2803ac03db
Author | SHA1 | Date | |
---|---|---|---|
griffi-gh | 2803ac03db | ||
griffi-gh | cab3f667e0 | ||
griffi-gh | 13516267cb | ||
griffi-gh | 4338c536ad |
|
@ -1,5 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging", "kubi-pool"]
|
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging", "kubi-pool"]
|
||||||
|
default-members = ["kubi"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[profile.release-with-debug]
|
[profile.release-with-debug]
|
||||||
|
|
19
README.md
19
README.md
|
@ -55,31 +55,32 @@ please note that android support is highly experimental!\
|
||||||
gamepad, mouse input is currently borked, and proper touch controls are not available.\
|
gamepad, mouse input is currently borked, and proper touch controls are not available.\
|
||||||
srgb and blending are broken too, which leads to many rendering issues
|
srgb and blending are broken too, which leads to many rendering issues
|
||||||
|
|
||||||
prerequisites: Android SDK, command line tools, NDK, platform-tools, latest JDK\
|
prerequisites: Android SDK, NDK, command line tools, platform-tools, latest JDK\
|
||||||
(make sure that your $PATH variable is configured properly)
|
(make sure that your `PATH`, `ANDROID_HOME` and `ANDROID_NDK_ROOT` variables are configured properly)
|
||||||
|
|
||||||
**Setup:**
|
**Setup:**
|
||||||
|
|
||||||
|
latest unpublished (git) version of cargo-apk is required
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo install cargo-apk
|
cargo install --git https://github.com/rust-mobile/cargo-apk cargo-apk
|
||||||
cargo target add aarch64-linux-android
|
rustup target add aarch64-linux-android
|
||||||
```
|
```
|
||||||
|
|
||||||
**Build:**
|
**Build:**
|
||||||
|
|
||||||
`--no-default-features` is required for keyboard input!\
|
`--no-default-features` is required for keyboard input!\
|
||||||
(`prefer-raw-events` feature *must* be disabled on android)
|
(`prefer-raw-events` feature *must* be disabled on android)\
|
||||||
|
|
||||||
Mouse input is not implemented, touch only!
|
Mouse input is not implemented, touch only!
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo apk build -p kubi --no-default-features
|
cargo apk build -p kubi --lib --no-default-features
|
||||||
```
|
```
|
||||||
|
|
||||||
**Run:**
|
**Run on device (using adb):**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo apk run -p kubi --no-default-features
|
cargo apk run -p kubi --lib --no-default-features
|
||||||
```
|
```
|
||||||
|
|
||||||
<h2>touch controls</h2>
|
<h2>touch controls</h2>
|
||||||
|
|
92
kubi/src/gui_v2.rs
Normal file
92
kubi/src/gui_v2.rs
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
use glam::{Vec2, vec2, Vec4};
|
||||||
|
use shipyard::Unique;
|
||||||
|
|
||||||
|
pub enum UiSize {
|
||||||
|
Auto,
|
||||||
|
Percentage(f32),
|
||||||
|
Pixels(f32),
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LayoutInfo {
|
||||||
|
position: Vec2,
|
||||||
|
max_preferred_size: Vec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Response {
|
||||||
|
size: Vec2
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait UiElement {
|
||||||
|
fn process(&self, layout: &LayoutInfo, draw: &mut Vec<UiDrawCall>) -> Response;
|
||||||
|
fn measure(&self, layout: &LayoutInfo) -> Option<Response> { None }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum LayoutDirection {
|
||||||
|
Horizontal,
|
||||||
|
Vertical
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LayoutBox {
|
||||||
|
pub direction: LayoutDirection,
|
||||||
|
pub gap: f32,
|
||||||
|
pub elements: Vec<Box<dyn UiElement>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ProgressBar {
|
||||||
|
size: (UiSize, UiSize),
|
||||||
|
value: f32,
|
||||||
|
color_foreground: Vec4,
|
||||||
|
color_background: Vec4,
|
||||||
|
}
|
||||||
|
|
||||||
|
const BAR_HEIGHT: f32 = 20.0;
|
||||||
|
|
||||||
|
impl UiElement for ProgressBar {
|
||||||
|
fn measure(&self, layout: &LayoutInfo) -> Option<Response> {
|
||||||
|
let width = match self.size.0 {
|
||||||
|
UiSize::Auto => layout.max_preferred_size.x,
|
||||||
|
UiSize::Percentage(p) => layout.max_preferred_size.x * p,
|
||||||
|
UiSize::Pixels(p) => p,
|
||||||
|
};
|
||||||
|
let height = match self.size.1 {
|
||||||
|
UiSize::Auto => BAR_HEIGHT,
|
||||||
|
UiSize::Percentage(p) => layout.max_preferred_size.y * p,
|
||||||
|
UiSize::Pixels(p) => p,
|
||||||
|
};
|
||||||
|
let size = Vec2::new(width, height);
|
||||||
|
Some(Response { size })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process(&self, layout: &LayoutInfo, draw: &mut Vec<UiDrawCall>) -> Response {
|
||||||
|
let measure = self.measure(layout).unwrap();
|
||||||
|
|
||||||
|
draw.push(UiDrawCall::Rectangle {
|
||||||
|
position: layout.position,
|
||||||
|
size: measure.size,
|
||||||
|
color: self.color_background
|
||||||
|
});
|
||||||
|
draw.push(UiDrawCall::Rectangle {
|
||||||
|
position: layout.position,
|
||||||
|
size: measure.size * vec2(self.value, 1.0),
|
||||||
|
color: self.color_foreground
|
||||||
|
});
|
||||||
|
|
||||||
|
measure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum UiDrawCall {
|
||||||
|
Rectangle {
|
||||||
|
///Position in pixels
|
||||||
|
position: Vec2,
|
||||||
|
///Size in pixels
|
||||||
|
size: Vec2,
|
||||||
|
///Color (RGBA)
|
||||||
|
color: Vec4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Unique)]
|
||||||
|
struct UiDrawCalls {
|
||||||
|
pub calls: Vec<UiDrawCall>,
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ pub(crate) mod cursor_lock;
|
||||||
pub(crate) mod control_flow;
|
pub(crate) mod control_flow;
|
||||||
pub(crate) mod state;
|
pub(crate) mod state;
|
||||||
pub(crate) mod gui;
|
pub(crate) mod gui;
|
||||||
|
pub(crate) mod gui_v2;
|
||||||
pub(crate) mod networking;
|
pub(crate) mod networking;
|
||||||
pub(crate) mod init;
|
pub(crate) mod init;
|
||||||
pub(crate) mod color;
|
pub(crate) mod color;
|
||||||
|
|
Loading…
Reference in a new issue