Commit e5bad6d2 authored by Florian Blasius's avatar Florian Blasius 🤘

OrbTk update.

parent 9e8e3eba
Pipeline #6576 failed with stages
in 14 minutes and 46 seconds
......@@ -302,9 +302,9 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
name = "euclid"
version = "0.20.4"
version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eeaa189ab5e5b393b765ff1ca754d88f3180d16260f1a5b39156c7b16159cce"
checksum = "a8813df82772c5ef4c2e9cd4a986773c125ffeafdc08204c9d5c2f06e0abdc17"
dependencies = [
"num-traits",
]
......@@ -614,7 +614,7 @@ dependencies = [
[[package]]
name = "orbtk"
version = "0.3.1-alpha1"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"dces",
"orbtk-api",
......@@ -631,7 +631,7 @@ dependencies = [
[[package]]
name = "orbtk-api"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"dces",
"derive_more",
......@@ -650,7 +650,7 @@ dependencies = [
[[package]]
name = "orbtk-css-engine"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"cssparser",
"orbtk-utils",
......@@ -659,7 +659,7 @@ dependencies = [
[[package]]
name = "orbtk-proc-macros"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"quote 1.0.2",
"syn 1.0.8",
......@@ -668,7 +668,7 @@ dependencies = [
[[package]]
name = "orbtk-render"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"image",
"orbtk-utils",
......@@ -680,7 +680,7 @@ dependencies = [
[[package]]
name = "orbtk-shell"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"image",
"lazy_static",
......@@ -695,7 +695,7 @@ dependencies = [
[[package]]
name = "orbtk-theme"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"lazy_static",
"orbtk-css-engine",
......@@ -704,7 +704,7 @@ dependencies = [
[[package]]
name = "orbtk-tree"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"dces",
]
......@@ -712,15 +712,16 @@ dependencies = [
[[package]]
name = "orbtk-utils"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
[[package]]
name = "orbtk-widgets"
version = "0.3.1-alpha2"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#1ae7e453c94d89b904af4f27b030ce48ca96d59b"
source = "git+https://gitlab.redox-os.org/redox-os/orbtk.git?branch=develop#9d023863cea98e30aca574b06766c065a81b6d7f"
dependencies = [
"dces",
"orbtk-api",
"orbtk-proc-macros",
"orbtk-render",
"orbtk-shell",
"orbtk-theme",
......@@ -948,9 +949,9 @@ dependencies = [
[[package]]
name = "raqote"
version = "0.7.5"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03ba207d0c548140f12785ed81e27210642e0c5a2af603d42b09c62a2e3214b6"
checksum = "0f27d82619ea8f582769fdc422bcbbb8517e1c7fc7b170d4191dd1e2a5d8decb"
dependencies = [
"euclid",
"lyon_geom",
......@@ -1118,18 +1119,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.102"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0"
checksum = "1217f97ab8e8904b57dd22eb61cde455fa7446a9c1cf43966066da047c1f3702"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.102"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca13fc1a832f793322228923fbb3aba9f3f44444898f835d31ad1b74fa0a2bf8"
checksum = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0"
dependencies = [
"proc-macro2 1.0.6",
"quote 1.0.2",
......@@ -1138,9 +1139,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.41"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
checksum = "1a3351dcbc1f067e2c92ab7c3c1f288ad1a4cffc470b5aaddb4c2e0a3ae80043"
dependencies = [
"itoa",
"ryu",
......
......@@ -137,7 +137,9 @@ impl Map {
for o in 0..offset {
for l in 0..self.layer_count {
if let Some(layer) = self.layers.get_mut(l) {
layer.tiles.insert(self.column_count + o + r * column_count, -1);
layer
.tiles
.insert(self.column_count + o + r * column_count, -1);
}
}
}
......
use orbgame::prelude::*;
use orbgame::theme::DEFAULT_THEME_CSS;
use orbgame::{prelude::*, shell::KeyEvent};
use std::{
cell::{Cell, RefCell},
cell::RefCell,
rc::Rc,
};
......@@ -18,25 +18,25 @@ pub enum MapViewAction {
OpenMenu,
}
#[derive(Default, Clone)]
#[derive(AsAny, Default, Clone)]
pub struct MapViewState {
action: Cell<Option<MapViewAction>>,
action: Option<MapViewAction>,
}
impl MapViewState {
fn action(&self, action: MapViewAction) {
self.action.set(Some(action));
fn action(&mut self, action: MapViewAction) {
self.action = Some(action);
}
}
impl State for MapViewState {
fn init(&self, _: &mut Registry, ctx: &mut Context<'_>) {
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
// workaround
ctx.window().get_mut::<Global>("global").focused_widget = Some(ctx.entity);
}
fn update(&self, _: &mut Registry, ctx: &mut Context<'_>) {
if let Some(action) = self.action.get() {
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
if let Some(action) = self.action {
if let Some(window_id) = ctx.parent_entity_by_element("window") {
match action {
MapViewAction::OpenMenu => {
......@@ -45,7 +45,7 @@ impl State for MapViewState {
}
}
self.action.set(None);
self.action = None;
}
}
}
......@@ -55,9 +55,7 @@ widget!(MapView<MapViewState> : KeyDownHandler {
});
impl Template for MapView {
fn template(self, _: Entity, ctx: &mut BuildContext) -> Self {
let state = self.clone_state();
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
self.name("MapView")
.child(
Container::create()
......@@ -91,35 +89,37 @@ impl Template for MapView {
)
.build(ctx),
)
.on_key_down(move |event: KeyEvent| -> bool {
.on_key_down(move |states, event| -> bool {
if event.key == Key::Escape {
state.action(MapViewAction::OpenMenu);
states
.get_mut::<MapViewState>(id)
.action(MapViewAction::OpenMenu);
}
true
})
}
}
#[derive(Copy, Clone)]
#[derive(AsAny, Copy, Clone)]
pub enum MenuAction {
Start,
Quit,
}
#[derive(Default)]
#[derive(AsAny, Default)]
pub struct MenuViewState {
action: Cell<Option<MenuAction>>,
action: Option<MenuAction>,
}
impl MenuViewState {
fn action(&self, action: MenuAction) {
self.action.set(Some(action));
fn action(&mut self, action: MenuAction) {
self.action = Some(action);
}
}
impl State for MenuViewState {
fn update(&self, _: &mut Registry, ctx: &mut Context<'_>) {
if let Some(action) = self.action.get() {
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
if let Some(action) = self.action {
if let Some(window_id) = ctx.parent_entity_by_element("window") {
match action {
MenuAction::Start => {
......@@ -131,7 +131,7 @@ impl State for MenuViewState {
}
}
self.action.set(None);
self.action = None;
}
}
}
......@@ -143,11 +143,7 @@ widget!(
);
impl Template for MenuView {
fn template(self, _: Entity, ctx: &mut BuildContext) -> Self {
let state = self.clone_state();
let ng_state = state.clone();
let q_state = state.clone();
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
self.name("MenuView").child(
Grid::create()
.selector(Selector::from("grid").class("start"))
......@@ -170,8 +166,10 @@ impl Template for MenuView {
Button::create()
.margin((0.0, 16.0, 0.0, 0.0))
.text("Start Game")
.on_click(move |_| {
ng_state.action(MenuAction::Start);
.on_click(move |states, _| {
states
.get_mut::<MenuViewState>(id)
.action(MenuAction::Start);
true
})
.build(ctx),
......@@ -180,8 +178,10 @@ impl Template for MenuView {
Button::create()
.margin((0.0, 8.0, 0.0, 0.0))
.text("Quit")
.on_click(move |_| {
q_state.action(MenuAction::Quit);
.on_click(move |states, _| {
states
.get_mut::<MenuViewState>(id)
.action(MenuAction::Quit);
true
})
.build(ctx),
......@@ -202,7 +202,7 @@ pub enum GameEvent {
Quit,
}
pub type GameHandlerFn = dyn Fn(&GameEvent) -> bool + 'static;
pub type GameHandlerFn = dyn Fn(&mut StatesContext, &GameEvent) -> bool + 'static;
pub struct GameEventHandler {
handler: Rc<GameHandlerFn>,
......@@ -215,9 +215,9 @@ impl Into<Rc<dyn EventHandler>> for GameEventHandler {
}
impl EventHandler for GameEventHandler {
fn handle_event(&self, event: &EventBox) -> bool {
fn handle_event(&self, states: &mut StatesContext, event: &EventBox) -> bool {
if let Ok(event) = event.downcast_ref::<GameEvent>() {
return (self.handler)(event);
return (self.handler)(states, event);
}
return false;
......@@ -230,20 +230,20 @@ impl EventHandler for GameEventHandler {
impl Event for GameEvent {}
#[derive(Default, Clone)]
#[derive(AsAny, Default, Clone)]
pub struct GameViewState {
event: Cell<Option<GameEvent>>,
event: Option<GameEvent>,
}
impl GameViewState {
fn game_event(&self, event: &GameEvent) {
self.event.set(Some(*event));
fn game_event(&mut self, event: &GameEvent) {
self.event = Some(*event);
}
}
impl State for GameViewState {
fn update(&self, _: &mut Registry, ctx: &mut Context<'_>) {
if let Some(event) = self.event.get() {
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
if let Some(event) = self.event {
match event {
GameEvent::OpenMenu => {
ctx.child("map_view")
......@@ -262,7 +262,7 @@ impl State for GameViewState {
}
}
self.event.set(None);
self.event = None;
}
}
}
......@@ -270,7 +270,10 @@ impl State for GameViewState {
widget!(GameView<GameViewState> { selector: Selector });
impl GameView {
fn on_game_event<H: Fn(&GameEvent) -> bool + 'static>(self, handler: H) -> Self {
fn on_game_event<H: Fn(&mut StatesContext, &GameEvent) -> bool + 'static>(
self,
handler: H,
) -> Self {
self.insert_handler(GameEventHandler {
handler: Rc::new(handler),
})
......@@ -278,8 +281,7 @@ impl GameView {
}
impl Template for GameView {
fn template(self, _: Entity, ctx: &mut BuildContext) -> Self {
let state = self.clone_state();
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
self.name("GameView")
.selector(Selector::default().id("game_view"))
.child(
......@@ -297,8 +299,8 @@ impl Template for GameView {
)
.build(ctx),
)
.on_game_event(move |e| {
state.game_event(e);
.on_game_event(move |states, e| {
states.get_mut::<GameViewState>(id).game_event(e);
true
})
}
......
......@@ -2,6 +2,7 @@ pub use orbgame_api::prelude as api;
pub use orbgame_utils::prelude as utils;
pub use orbgame_widgets::prelude as widgets;
pub use orbtk::css_engine;
pub use orbtk::proc_macros;
pub use orbtk::render;
pub use orbtk::shell;
pub use orbtk::theme;
......
......@@ -9,6 +9,7 @@ pub use std::{
pub use crate::{
api::*,
css_engine::{Selector as SelectorValue, SelectorRelation, Theme as ThemeValue, ThemeBuilder},
proc_macros::*,
render,
shell::Key,
theme::{colors, default_theme, fonts, light_theme, vector_graphics::material_font_icons},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment