Compare commits

..

4 commits

Author SHA1 Message Date
griffi-gh 2803ac03db wip new gui 2023-11-21 01:03:04 +01:00
griffi-gh cab3f667e0 update readme 2023-11-21 00:01:52 +01:00
griffi-gh 13516267cb fix readme with up-to-date info 2023-11-20 23:56:42 +01:00
griffi-gh 4338c536ad add default-members 2023-11-20 23:53:51 +01:00
4 changed files with 104 additions and 9 deletions

View file

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

View file

@ -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
View 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>,
}

View file

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