Compare commits
1 commit
540b3b8165
...
b13253ecbc
Author | SHA1 | Date | |
---|---|---|---|
b13253ecbc |
18 changed files with 251 additions and 549 deletions
|
@ -23,11 +23,7 @@ pub struct GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiBuilder {
|
impl GuiBuilder {
|
||||||
pub fn new(
|
pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result<Arc<Self>> {
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
path: &AssetPath,
|
|
||||||
) -> Result<Arc<Self>> {
|
|
||||||
let validator = Validator::new(
|
let validator = Validator::new(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
gui_handler,
|
||||||
|
@ -35,28 +31,22 @@ impl GuiBuilder {
|
||||||
)
|
)
|
||||||
.with_context(|| format!("validator for {}", path.full_path()))?;
|
.with_context(|| format!("validator for {}", path.full_path()))?;
|
||||||
|
|
||||||
Ok(Arc::new(
|
Ok(Arc::new(Self::_new(gui_handler, validator).with_context(
|
||||||
Self::_new(commands, gui_handler, validator)
|
|| format!("for file {}", path.full_path()),
|
||||||
.with_context(|| format!("for file {}", path.full_path()))?,
|
)?))
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str(
|
pub fn from_str(gui_handler: &mut GuiHandler, s: &str) -> Result<Arc<Self>> {
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
s: &str,
|
|
||||||
) -> Result<Arc<Self>> {
|
|
||||||
let validator = Validator::from_str(
|
let validator = Validator::from_str(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
gui_handler,
|
||||||
s,
|
s,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Arc::new(Self::_new(commands, gui_handler, validator)?))
|
Ok(Arc::new(Self::_new(gui_handler, validator)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge<'a>(
|
pub fn merge<'a>(
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
pathes: impl IntoIterator<Item = &'a AssetPath>,
|
pathes: impl IntoIterator<Item = &'a AssetPath>,
|
||||||
) -> Result<Arc<Self>> {
|
) -> Result<Arc<Self>> {
|
||||||
|
@ -76,7 +66,7 @@ impl GuiBuilder {
|
||||||
path,
|
path,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let builder = Self::_new(commands, gui_handler, validator)
|
let builder = Self::_new(gui_handler, validator)
|
||||||
.with_context(|| format!("for file {}", path.full_path()))?;
|
.with_context(|| format!("for file {}", path.full_path()))?;
|
||||||
|
|
||||||
me.grids.extend(builder.grids);
|
me.grids.extend(builder.grids);
|
||||||
|
@ -96,11 +86,7 @@ impl GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn _new(
|
fn _new(gui_handler: &mut GuiHandler, validator: Validator) -> Result<Self> {
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
validator: Validator,
|
|
||||||
) -> Result<Self> {
|
|
||||||
let root = validator.root();
|
let root = validator.root();
|
||||||
|
|
||||||
let mut ids = HashMap::new();
|
let mut ids = HashMap::new();
|
||||||
|
@ -111,7 +97,6 @@ impl GuiBuilder {
|
||||||
|
|
||||||
for child in &root.children {
|
for child in &root.children {
|
||||||
let tree = Self::create_tree(
|
let tree = Self::create_tree(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
&mut ids,
|
&mut ids,
|
||||||
child,
|
child,
|
||||||
|
@ -194,10 +179,7 @@ impl GuiBuilder {
|
||||||
impl Functionality for GuiBuilder {
|
impl Functionality for GuiBuilder {
|
||||||
fn set_click_callbacks(
|
fn set_click_callbacks(
|
||||||
&self,
|
&self,
|
||||||
functions: Vec<(
|
functions: Vec<(&str, Box<dyn Fn(&mut Commands) -> Result<()> + Send + Sync>)>,
|
||||||
&str,
|
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
|
||||||
)>,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (function_name, callback) in functions {
|
for (function_name, callback) in functions {
|
||||||
let suffix_less_function_name = handle_function_suffix(function_name);
|
let suffix_less_function_name = handle_function_suffix(function_name);
|
||||||
|
@ -213,7 +195,7 @@ impl Functionality for GuiBuilder {
|
||||||
&self,
|
&self,
|
||||||
_functions: Vec<(
|
_functions: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands, &dyn Any) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -223,7 +205,7 @@ impl Functionality for GuiBuilder {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands, bool) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (function_name, callback) in callbacks {
|
for (function_name, callback) in callbacks {
|
||||||
|
@ -240,11 +222,7 @@ impl Functionality for GuiBuilder {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<
|
Box<dyn Fn(&mut Commands, ControllerButton) -> Result<bool> + Send + Sync>,
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (function_name, callback) in callbacks {
|
for (function_name, callback) in callbacks {
|
||||||
|
@ -267,14 +245,9 @@ impl Visibility for GuiBuilder {
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
for grid in &self.grids {
|
for grid in &self.grids {
|
||||||
grid.set_visibility(commands, gui_handler, visibility)?;
|
grid.set_visibility(world, visibility)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -296,7 +269,7 @@ impl GuiElementTraits for GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopGui for GuiBuilder {
|
impl TopGui for GuiBuilder {
|
||||||
fn decline(&self, _commands: &mut Commands, _gui_handler: &mut GuiHandler) -> Result<()> {
|
fn decline(&self, _world: &mut World) -> Result<()> {
|
||||||
if let Some(decline_callback) = self.decline_callback.read().unwrap().as_ref() {
|
if let Some(decline_callback) = self.decline_callback.read().unwrap().as_ref() {
|
||||||
decline_callback()?;
|
decline_callback()?;
|
||||||
}
|
}
|
||||||
|
@ -304,21 +277,11 @@ impl TopGui for GuiBuilder {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_tab(
|
fn next_tab(&self, _world: &mut World, _: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
_gui_handler: &mut GuiHandler,
|
|
||||||
_: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn previous_tab(
|
fn previous_tab(&self, _world: &mut World, _: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
_gui_handler: &mut GuiHandler,
|
|
||||||
_: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,18 +303,18 @@ impl TopLevelGui for GuiBuilder {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn enable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(commands, gui_handler, true)?;
|
self.set_visibility(world, true)?;
|
||||||
|
|
||||||
if let Some(button) = &self.default_select {
|
if let Some(button) = &self.default_select {
|
||||||
button.select(gui_handler)?;
|
button.select(world.resources.get_mut()?)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(commands, gui_handler, false)?;
|
self.set_visibility(world, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -379,7 +342,6 @@ impl_element!(MultiLineTextField);
|
||||||
// private
|
// private
|
||||||
impl GuiBuilder {
|
impl GuiBuilder {
|
||||||
fn create_tree(
|
fn create_tree(
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
ids: &mut HashMap<String, UiElement>,
|
ids: &mut HashMap<String, UiElement>,
|
||||||
root_grid_info: &Arc<GridInfo>,
|
root_grid_info: &Arc<GridInfo>,
|
||||||
|
@ -432,7 +394,6 @@ impl GuiBuilder {
|
||||||
|
|
||||||
for child in root_grid_info.children.read().unwrap().iter() {
|
for child in root_grid_info.children.read().unwrap().iter() {
|
||||||
Self::create_child(
|
Self::create_child(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
child,
|
child,
|
||||||
&root_grid,
|
&root_grid,
|
||||||
|
@ -447,7 +408,6 @@ impl GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_child(
|
fn create_child(
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
child: &UiInfoElement,
|
child: &UiInfoElement,
|
||||||
grid: &Grid,
|
grid: &Grid,
|
||||||
|
@ -463,7 +423,6 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &button_info.id, &button)?;
|
Self::insert_id(ids, &button_info.id, &button)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
button.clone(),
|
button.clone(),
|
||||||
button_info
|
button_info
|
||||||
|
@ -499,7 +458,6 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &label_info.id, &label)?;
|
Self::insert_id(ids, &label_info.id, &label)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
label.clone(),
|
label.clone(),
|
||||||
label_info.x_slot.get().with_context(|| "x_slot of label")?,
|
label_info.x_slot.get().with_context(|| "x_slot of label")?,
|
||||||
|
@ -512,12 +470,11 @@ impl GuiBuilder {
|
||||||
}
|
}
|
||||||
UiInfoElement::MultiLineLabel(multi_line_label_info) => {
|
UiInfoElement::MultiLineLabel(multi_line_label_info) => {
|
||||||
let multi_line_label =
|
let multi_line_label =
|
||||||
MultiLineLabel::try_from(multi_line_label_info, commands, gui_handler)?;
|
MultiLineLabel::try_from(multi_line_label_info, gui_handler)?;
|
||||||
|
|
||||||
GuiBuilder::insert_id(ids, &multi_line_label_info.id, &multi_line_label)?;
|
GuiBuilder::insert_id(ids, &multi_line_label_info.id, &multi_line_label)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
multi_line_label.clone(),
|
multi_line_label.clone(),
|
||||||
multi_line_label_info
|
multi_line_label_info
|
||||||
|
@ -535,16 +492,12 @@ impl GuiBuilder {
|
||||||
multi_line_label.set_layer(layer)?;
|
multi_line_label.set_layer(layer)?;
|
||||||
}
|
}
|
||||||
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
||||||
let multi_line_text_field = MultiLineTextField::try_from(
|
let multi_line_text_field =
|
||||||
multi_line_text_field_info,
|
MultiLineTextField::try_from(multi_line_text_field_info, gui_handler)?;
|
||||||
commands,
|
|
||||||
gui_handler,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
GuiBuilder::insert_id(ids, &multi_line_text_field_info.id, &multi_line_text_field)?;
|
GuiBuilder::insert_id(ids, &multi_line_text_field_info.id, &multi_line_text_field)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
multi_line_text_field.clone(),
|
multi_line_text_field.clone(),
|
||||||
multi_line_text_field_info
|
multi_line_text_field_info
|
||||||
|
@ -567,7 +520,6 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &text_field_info.id, &text_field)?;
|
Self::insert_id(ids, &text_field_info.id, &text_field)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
text_field.clone(),
|
text_field.clone(),
|
||||||
text_field_info
|
text_field_info
|
||||||
|
@ -590,7 +542,6 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &icon_info.id, UiElement::Icon(Arc::downgrade(&icon)))?;
|
Self::insert_id(ids, &icon_info.id, UiElement::Icon(Arc::downgrade(&icon)))?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
icon.clone(),
|
icon.clone(),
|
||||||
icon_info.x_slot.get().with_context(|| "x_slot of icon")?,
|
icon_info.x_slot.get().with_context(|| "x_slot of icon")?,
|
||||||
|
@ -607,7 +558,6 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &progress_bar_info.id, &progress_bar)?;
|
Self::insert_id(ids, &progress_bar_info.id, &progress_bar)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
progress_bar.clone(),
|
progress_bar.clone(),
|
||||||
progress_bar_info
|
progress_bar_info
|
||||||
|
@ -630,7 +580,6 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &grid_info.id, &sub_grid)?;
|
Self::insert_id(ids, &grid_info.id, &sub_grid)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
sub_grid.clone(),
|
sub_grid.clone(),
|
||||||
grid_info.x_slot.get().with_context(|| "x_slot of grid")?,
|
grid_info.x_slot.get().with_context(|| "x_slot of grid")?,
|
||||||
|
@ -644,7 +593,6 @@ impl GuiBuilder {
|
||||||
|
|
||||||
for child in grid_info.children.read().unwrap().iter() {
|
for child in grid_info.children.read().unwrap().iter() {
|
||||||
Self::create_child(
|
Self::create_child(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
child,
|
child,
|
||||||
&sub_grid,
|
&sub_grid,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{any::Any, collections::HashMap, sync::Arc};
|
use std::{any::Any, collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use assetpath::AssetPath;
|
use assetpath::AssetPath;
|
||||||
use ecs::Commands;
|
use ecs::World;
|
||||||
|
|
||||||
use super::validator::{
|
use super::validator::{
|
||||||
buttoninfo::NeighbourInfo,
|
buttoninfo::NeighbourInfo,
|
||||||
|
@ -18,39 +18,27 @@ pub struct GuiSnippet {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiSnippet {
|
impl GuiSnippet {
|
||||||
pub fn new(
|
pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result<Arc<Self>> {
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
path: &AssetPath,
|
|
||||||
) -> Result<Arc<Self>> {
|
|
||||||
let validator = Validator::new(
|
let validator = Validator::new(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
gui_handler,
|
||||||
path,
|
path,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Self::_new(commands, gui_handler, validator)
|
Self::_new(gui_handler, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str(
|
pub fn from_str(gui_handler: &mut GuiHandler, s: &str) -> Result<Arc<Self>> {
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
s: &str,
|
|
||||||
) -> Result<Arc<Self>> {
|
|
||||||
let validator = Validator::from_str(
|
let validator = Validator::from_str(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
gui_handler,
|
||||||
s,
|
s,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Self::_new(commands, gui_handler, validator)
|
Self::_new(gui_handler, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _new(
|
fn _new(gui_handler: &mut GuiHandler, validator: Validator) -> Result<Arc<Self>> {
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
validator: Validator,
|
|
||||||
) -> Result<Arc<Self>> {
|
|
||||||
let root = validator.root();
|
let root = validator.root();
|
||||||
|
|
||||||
let mut ids = HashMap::new();
|
let mut ids = HashMap::new();
|
||||||
|
@ -69,14 +57,7 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(&mut ids, &grid_info.id, &grid)?;
|
GuiBuilder::insert_id(&mut ids, &grid_info.id, &grid)?;
|
||||||
|
|
||||||
for child in grid_info.children.read().unwrap().iter() {
|
for child in grid_info.children.read().unwrap().iter() {
|
||||||
Self::create_child(
|
Self::create_child(gui_handler, child, &grid, &mut ids, &mut custom_neighbours)?;
|
||||||
commands,
|
|
||||||
gui_handler,
|
|
||||||
child,
|
|
||||||
&grid,
|
|
||||||
&mut ids,
|
|
||||||
&mut custom_neighbours,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiBuilder::connect_custom_neighbours(&ids, custom_neighbours)?;
|
GuiBuilder::connect_custom_neighbours(&ids, custom_neighbours)?;
|
||||||
|
@ -113,13 +94,8 @@ impl Visibility for GuiSnippet {
|
||||||
self.grid.visible()
|
self.grid.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
self.grid.set_visibility(world, visibility)
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.grid.set_visibility(commands, gui_handler, visibility)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,10 +148,7 @@ impl Gridable for GuiSnippet {
|
||||||
impl Functionality for GuiSnippet {
|
impl Functionality for GuiSnippet {
|
||||||
fn set_click_callbacks(
|
fn set_click_callbacks(
|
||||||
&self,
|
&self,
|
||||||
functions: Vec<(
|
functions: Vec<(&str, Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>)>,
|
||||||
&str,
|
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
|
||||||
)>,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (function_name, callback) in functions {
|
for (function_name, callback) in functions {
|
||||||
let suffix_less_function_name = handle_function_suffix(function_name);
|
let suffix_less_function_name = handle_function_suffix(function_name);
|
||||||
|
@ -191,7 +164,7 @@ impl Functionality for GuiSnippet {
|
||||||
&self,
|
&self,
|
||||||
_functions: Vec<(
|
_functions: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -201,7 +174,7 @@ impl Functionality for GuiSnippet {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut World, bool) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (function_name, callback) in callbacks {
|
for (function_name, callback) in callbacks {
|
||||||
|
@ -218,11 +191,7 @@ impl Functionality for GuiSnippet {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<
|
Box<dyn Fn(&mut World, ControllerButton) -> Result<bool> + Send + Sync>,
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (function_name, callback) in callbacks {
|
for (function_name, callback) in callbacks {
|
||||||
|
@ -238,7 +207,6 @@ impl Functionality for GuiSnippet {
|
||||||
|
|
||||||
impl GuiSnippet {
|
impl GuiSnippet {
|
||||||
fn create_child(
|
fn create_child(
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
child: &UiInfoElement,
|
child: &UiInfoElement,
|
||||||
grid: &Grid,
|
grid: &Grid,
|
||||||
|
@ -252,7 +220,6 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &button_info.id, &button)?;
|
GuiBuilder::insert_id(ids, &button_info.id, &button)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
button.clone(),
|
button.clone(),
|
||||||
button_info.x_slot.get()?,
|
button_info.x_slot.get()?,
|
||||||
|
@ -269,7 +236,6 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &label_info.id, &label)?;
|
GuiBuilder::insert_id(ids, &label_info.id, &label)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
label,
|
label,
|
||||||
label_info.x_slot.get()?,
|
label_info.x_slot.get()?,
|
||||||
|
@ -280,12 +246,11 @@ impl GuiSnippet {
|
||||||
}
|
}
|
||||||
UiInfoElement::MultiLineLabel(multi_line_label_info) => {
|
UiInfoElement::MultiLineLabel(multi_line_label_info) => {
|
||||||
let multi_line_label =
|
let multi_line_label =
|
||||||
MultiLineLabel::try_from(multi_line_label_info, commands, gui_handler)?;
|
MultiLineLabel::try_from(multi_line_label_info, gui_handler)?;
|
||||||
|
|
||||||
GuiBuilder::insert_id(ids, &multi_line_label_info.id, &multi_line_label)?;
|
GuiBuilder::insert_id(ids, &multi_line_label_info.id, &multi_line_label)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
multi_line_label,
|
multi_line_label,
|
||||||
multi_line_label_info.x_slot.get()?,
|
multi_line_label_info.x_slot.get()?,
|
||||||
|
@ -295,16 +260,12 @@ impl GuiSnippet {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
||||||
let multi_line_text_field = MultiLineTextField::try_from(
|
let multi_line_text_field =
|
||||||
multi_line_text_field_info,
|
MultiLineTextField::try_from(multi_line_text_field_info, gui_handler)?;
|
||||||
commands,
|
|
||||||
gui_handler,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
GuiBuilder::insert_id(ids, &multi_line_text_field_info.id, &multi_line_text_field)?;
|
GuiBuilder::insert_id(ids, &multi_line_text_field_info.id, &multi_line_text_field)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
multi_line_text_field,
|
multi_line_text_field,
|
||||||
multi_line_text_field_info.x_slot.get()?,
|
multi_line_text_field_info.x_slot.get()?,
|
||||||
|
@ -319,7 +280,6 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &text_field_info.id, &text_field)?;
|
GuiBuilder::insert_id(ids, &text_field_info.id, &text_field)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
text_field,
|
text_field,
|
||||||
text_field_info.x_slot.get()?,
|
text_field_info.x_slot.get()?,
|
||||||
|
@ -334,7 +294,6 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &icon_info.id, UiElement::Icon(Arc::downgrade(&icon)))?;
|
GuiBuilder::insert_id(ids, &icon_info.id, UiElement::Icon(Arc::downgrade(&icon)))?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
icon,
|
icon,
|
||||||
icon_info.x_slot.get()?,
|
icon_info.x_slot.get()?,
|
||||||
|
@ -349,7 +308,6 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &progress_bar_info.id, &progress_bar)?;
|
GuiBuilder::insert_id(ids, &progress_bar_info.id, &progress_bar)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
progress_bar,
|
progress_bar,
|
||||||
progress_bar_info.x_slot.get()?,
|
progress_bar_info.x_slot.get()?,
|
||||||
|
@ -364,7 +322,6 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &grid_info.id, &sub_grid)?;
|
GuiBuilder::insert_id(ids, &grid_info.id, &sub_grid)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
commands,
|
|
||||||
gui_handler,
|
gui_handler,
|
||||||
sub_grid.clone(),
|
sub_grid.clone(),
|
||||||
grid_info.x_slot.get()?,
|
grid_info.x_slot.get()?,
|
||||||
|
@ -374,14 +331,7 @@ impl GuiSnippet {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for child in grid_info.children.read().unwrap().iter() {
|
for child in grid_info.children.read().unwrap().iter() {
|
||||||
Self::create_child(
|
Self::create_child(gui_handler, child, &sub_grid, ids, neighbour_infos)?;
|
||||||
commands,
|
|
||||||
gui_handler,
|
|
||||||
child,
|
|
||||||
&sub_grid,
|
|
||||||
ids,
|
|
||||||
neighbour_infos,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,32 +315,23 @@ impl Button {
|
||||||
|
|
||||||
pub fn set_callback<F>(&self, callback: F)
|
pub fn set_callback<F>(&self, callback: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
|
F: Fn(&mut Commands) -> Result<()> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
self.click_executable.set_callback(
|
self.click_executable
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler, _: ()| {
|
.set_callback(move |commands: &mut Commands, _: ()| callback(commands));
|
||||||
callback(commands, gui_handler)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_select_callback<F>(&self, callback: F)
|
pub fn set_select_callback<F>(&self, callback: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync + 'static,
|
F: Fn(&mut Commands, bool) -> Result<()> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
self.on_select_executable.set_callback(
|
self.on_select_executable
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler, select: bool| {
|
.set_callback(move |commands: &mut Commands, select: bool| callback(commands, select));
|
||||||
callback(commands, gui_handler, select)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_custom_callback<F>(&self, callback: F)
|
pub fn set_custom_callback<F>(&self, callback: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
F: Fn(&mut Commands, ControllerButton) -> Result<bool> + Send + Sync + 'static,
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
{
|
{
|
||||||
self.selectable.set_custom_callback(callback);
|
self.selectable.set_custom_callback(callback);
|
||||||
}
|
}
|
||||||
|
@ -457,12 +448,7 @@ impl Visibility for Button {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible.load(SeqCst) {
|
if visibility != self.visible.load(SeqCst) {
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
|
@ -593,18 +579,19 @@ impl Button {
|
||||||
fn create_selected_changed_callback(button: Arc<Button>) {
|
fn create_selected_changed_callback(button: Arc<Button>) {
|
||||||
let button_weak = Arc::downgrade(&button);
|
let button_weak = Arc::downgrade(&button);
|
||||||
|
|
||||||
let selected_changed =
|
let selected_changed = move |commands: &mut Commands, selected: bool| {
|
||||||
move |_commands: &mut Commands, gui_handler: &mut GuiHandler, selected: bool| {
|
if let Some(button) = button_weak.upgrade() {
|
||||||
if let Some(button) = button_weak.upgrade() {
|
let gui_handler = world.resources.get_mut()?;
|
||||||
if selected {
|
|
||||||
button.set_button_state(gui_handler, ButtonState::Selected)?;
|
|
||||||
} else {
|
|
||||||
button.set_button_state(gui_handler, ButtonState::Normal)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
if selected {
|
||||||
};
|
button.set_button_state(gui_handler, ButtonState::Selected)?;
|
||||||
|
} else {
|
||||||
|
button.set_button_state(gui_handler, ButtonState::Normal)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
button.select_executable.set_callback(selected_changed);
|
button.select_executable.set_callback(selected_changed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ecs::Commands;
|
|
||||||
|
|
||||||
use crate::builder::validator::gridinfo::GridInfo;
|
use crate::builder::validator::gridinfo::GridInfo;
|
||||||
|
|
||||||
|
@ -200,7 +199,6 @@ impl Grid {
|
||||||
|
|
||||||
pub fn detach(
|
pub fn detach(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
pos_x: usize,
|
pos_x: usize,
|
||||||
pos_y: usize,
|
pos_y: usize,
|
||||||
|
@ -233,7 +231,7 @@ impl Grid {
|
||||||
Some((child, _x, _y)) => {
|
Some((child, _x, _y)) => {
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
if let Some(child_visibility) = child.visibility() {
|
if let Some(child_visibility) = child.visibility() {
|
||||||
child_visibility.set_visibility(commands, gui_handler, false)?;
|
child_visibility.set_visibility(gui_handler, false)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +244,6 @@ impl Grid {
|
||||||
/// Returns `true` if item got detached
|
/// Returns `true` if item got detached
|
||||||
pub fn detach_item(
|
pub fn detach_item(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
item: Arc<dyn GuiElementTraits>,
|
item: Arc<dyn GuiElementTraits>,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
|
@ -268,7 +265,7 @@ impl Grid {
|
||||||
|
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
if let Some(child_visibility) = child.visibility() {
|
if let Some(child_visibility) = child.visibility() {
|
||||||
child_visibility.set_visibility(commands, gui_handler, false)?;
|
child_visibility.set_visibility(gui_handler, false)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,7 +408,6 @@ impl Grid {
|
||||||
|
|
||||||
pub fn attach(
|
pub fn attach(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
child: Arc<dyn GuiElementTraits>,
|
child: Arc<dyn GuiElementTraits>,
|
||||||
pos_x: usize,
|
pos_x: usize,
|
||||||
|
@ -462,7 +458,7 @@ impl Grid {
|
||||||
ChildState::Some { child, .. } => {
|
ChildState::Some { child, .. } => {
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
if let Some(child_visibility) = child.visibility() {
|
if let Some(child_visibility) = child.visibility() {
|
||||||
child_visibility.set_visibility(commands, gui_handler, false)?;
|
child_visibility.set_visibility(gui_handler, false)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,7 +468,7 @@ impl Grid {
|
||||||
|
|
||||||
if self.visible() {
|
if self.visible() {
|
||||||
if let Some(child_visibility) = child.visibility() {
|
if let Some(child_visibility) = child.visibility() {
|
||||||
child_visibility.set_visibility(commands, gui_handler, true)?;
|
child_visibility.set_visibility(gui_handler, true)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,31 +622,26 @@ impl Grid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable_tree(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable_tree(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||||
self.framable.delete(gui_handler)?;
|
self.framable.delete(gui_handler)?;
|
||||||
|
|
||||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||||
background.disable(gui_handler)?;
|
background.disable(gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_tree_visibility(commands, gui_handler, false)?;
|
self.set_tree_visibility(gui_handler, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tree_visibility(
|
fn set_tree_visibility(&self, gui_handler: &mut GuiHandler, visible: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visible: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
let tree = self.children.read().unwrap();
|
let tree = self.children.read().unwrap();
|
||||||
|
|
||||||
for row in tree.deref() {
|
for row in tree.deref() {
|
||||||
for child_state in row {
|
for child_state in row {
|
||||||
if let Some((child, ..)) = child_state.get_some() {
|
if let Some((child, ..)) = child_state.get_some() {
|
||||||
if let Some(visibility) = child.visibility() {
|
if let Some(visibility) = child.visibility() {
|
||||||
visibility.set_visibility(commands, gui_handler, visible)?;
|
visibility.set_visibility(gui_handler, visible)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -802,12 +793,7 @@ impl Visibility for Grid {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible.load(SeqCst) {
|
if visibility != self.visible.load(SeqCst) {
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
|
@ -818,9 +804,9 @@ impl Visibility for Grid {
|
||||||
background.enable(gui_handler)?;
|
background.enable(gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_tree_visibility(commands, gui_handler, true)?;
|
self.set_tree_visibility(gui_handler, true)?;
|
||||||
} else {
|
} else {
|
||||||
self.disable_tree(commands, gui_handler)?;
|
self.disable_tree(gui_handler)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assetpath::AssetPath;
|
use assetpath::AssetPath;
|
||||||
use ecs::Commands;
|
use ecs::*;
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
use vulkan_rs::prelude::*;
|
use vulkan_rs::prelude::*;
|
||||||
|
|
||||||
|
@ -281,13 +281,10 @@ impl Visibility for Icon {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible.load(SeqCst) {
|
if visibility != self.visible.load(SeqCst) {
|
||||||
|
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use super::{
|
||||||
wrapper::{IconizableWrapper, TextableWrapper},
|
wrapper::{IconizableWrapper, TextableWrapper},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ecs::Commands;
|
use ecs::*;
|
||||||
use vulkan_rs::prelude::*;
|
use vulkan_rs::prelude::*;
|
||||||
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
|
@ -230,13 +230,10 @@ impl Visibility for Label {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use ecs::Commands;
|
use ecs::World;
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
|
|
||||||
pub struct MultiLineLabelBuilder {
|
pub struct MultiLineLabelBuilder {
|
||||||
|
@ -57,11 +57,7 @@ impl MultiLineLabelBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(
|
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineLabel>> {
|
||||||
self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
) -> Result<Arc<MultiLineLabel>> {
|
|
||||||
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
|
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
|
||||||
base_grid.set_margin(0);
|
base_grid.set_margin(0);
|
||||||
base_grid.set_padding(0);
|
base_grid.set_padding(0);
|
||||||
|
@ -77,7 +73,7 @@ impl MultiLineLabelBuilder {
|
||||||
.set_text_alignment(self.text_alignment)
|
.set_text_alignment(self.text_alignment)
|
||||||
.build(gui_handler)?;
|
.build(gui_handler)?;
|
||||||
|
|
||||||
base_grid.attach(commands, gui_handler, label, 0, i as usize, 1, 1)?;
|
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Arc::new(MultiLineLabel {
|
Ok(Arc::new(MultiLineLabel {
|
||||||
|
@ -189,7 +185,6 @@ impl MultiLineLabel {
|
||||||
|
|
||||||
pub fn try_from(
|
pub fn try_from(
|
||||||
multi_line_label_info: &MultiLineLabelInfo,
|
multi_line_label_info: &MultiLineLabelInfo,
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
) -> Result<Arc<Self>> {
|
) -> Result<Arc<Self>> {
|
||||||
let text = multi_line_label_info.text.read().unwrap().clone();
|
let text = multi_line_label_info.text.read().unwrap().clone();
|
||||||
|
@ -218,7 +213,7 @@ impl MultiLineLabel {
|
||||||
multi_line_label_builder = multi_line_label_builder.set_text(text);
|
multi_line_label_builder = multi_line_label_builder.set_text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
multi_line_label_builder.build(commands, gui_handler)
|
multi_line_label_builder.build(gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
||||||
|
@ -256,13 +251,8 @@ impl Visibility for MultiLineLabel {
|
||||||
self.grid.visible()
|
self.grid.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
self.grid.set_visibility(world, visibility)
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.grid.set_visibility(commands, gui_handler, visibility)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,11 +63,7 @@ impl MultiLineTextFieldBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(
|
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineTextField>> {
|
||||||
self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
) -> Result<Arc<MultiLineTextField>> {
|
|
||||||
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
|
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
|
||||||
base_grid.set_margin(0);
|
base_grid.set_margin(0);
|
||||||
base_grid.set_padding(0);
|
base_grid.set_padding(0);
|
||||||
|
@ -83,7 +79,7 @@ impl MultiLineTextFieldBuilder {
|
||||||
.set_text_alignment(self.text_alignment)
|
.set_text_alignment(self.text_alignment)
|
||||||
.build(gui_handler)?;
|
.build(gui_handler)?;
|
||||||
|
|
||||||
base_grid.attach(commands, gui_handler, label, 0, i as usize, 1, 1)?;
|
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = Arc::new(SplittedText::new(self.text));
|
let text = Arc::new(SplittedText::new(self.text));
|
||||||
|
@ -101,9 +97,9 @@ impl MultiLineTextFieldBuilder {
|
||||||
multi_line_text_field.text_changed_exec.set_callback({
|
multi_line_text_field.text_changed_exec.set_callback({
|
||||||
let weak_tf = Arc::downgrade(&multi_line_text_field);
|
let weak_tf = Arc::downgrade(&multi_line_text_field);
|
||||||
|
|
||||||
move |_commands: &mut Commands, gui_handler: &mut GuiHandler, _text| {
|
move |commands: &mut Commands, _text| {
|
||||||
if let Some(tf) = weak_tf.upgrade() {
|
if let Some(tf) = weak_tf.upgrade() {
|
||||||
tf.update_text(gui_handler)?;
|
tf.update_text(world.resources.get_mut()?)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -309,7 +305,6 @@ impl MultiLineTextField {
|
||||||
|
|
||||||
pub fn try_from(
|
pub fn try_from(
|
||||||
multi_line_text_field_info: &MultiLineTextFieldInfo,
|
multi_line_text_field_info: &MultiLineTextFieldInfo,
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
) -> Result<Arc<Self>> {
|
) -> Result<Arc<Self>> {
|
||||||
let text = multi_line_text_field_info.text.read().unwrap().clone();
|
let text = multi_line_text_field_info.text.read().unwrap().clone();
|
||||||
|
@ -338,7 +333,7 @@ impl MultiLineTextField {
|
||||||
multi_line_text_field_builder = multi_line_text_field_builder.set_text(text);
|
multi_line_text_field_builder = multi_line_text_field_builder.set_text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
multi_line_text_field_builder.build(commands, gui_handler)
|
multi_line_text_field_builder.build(gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
||||||
|
@ -376,13 +371,10 @@ impl Visibility for MultiLineTextField {
|
||||||
self.grid.visible()
|
self.grid.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler = world.resources.get_mut()?;
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
self.writeable.add(gui_handler)?;
|
self.writeable.add(gui_handler)?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -390,7 +382,7 @@ impl Visibility for MultiLineTextField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.grid.set_visibility(commands, gui_handler, visibility)
|
self.grid.set_visibility(world, visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{builder::validator::progressbar_info::ProgressBarInfo, prelude::*};
|
use crate::{builder::validator::progressbar_info::ProgressBarInfo, prelude::*};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ecs::Commands;
|
use ecs::*;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
atomic::{AtomicBool, Ordering::SeqCst},
|
atomic::{AtomicBool, Ordering::SeqCst},
|
||||||
|
@ -279,13 +279,10 @@ impl Visibility for ProgressBar {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl TextField {
|
||||||
|
|
||||||
pub fn set_text_changed_callback<F>(&self, f: F)
|
pub fn set_text_changed_callback<F>(&self, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, Option<String>) -> Result<()> + Send + Sync + 'static,
|
F: Fn(&mut Commands, Option<String>) -> Result<()> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
self.text_changed_executable.set_callback(f);
|
self.text_changed_executable.set_callback(f);
|
||||||
}
|
}
|
||||||
|
@ -311,13 +311,10 @@ impl Visibility for TextField {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -10,8 +10,8 @@ pub trait TopLevelGui: Send + Sync {
|
||||||
fn top_gui(&self) -> Option<&dyn TopGui>;
|
fn top_gui(&self) -> Option<&dyn TopGui>;
|
||||||
fn elements(&self) -> Option<&HashMap<String, UiElement>>;
|
fn elements(&self) -> Option<&HashMap<String, UiElement>>;
|
||||||
fn functionality(&self) -> Option<&dyn Functionality>;
|
fn functionality(&self) -> Option<&dyn Functionality>;
|
||||||
fn enable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()>;
|
fn enable(&self, commands: &mut Commands) -> Result<()>;
|
||||||
fn disable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()>;
|
fn disable(&self, commands: &mut Commands) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_to<T>(any: &dyn Any) -> Result<&T>
|
pub fn any_to<T>(any: &dyn Any) -> Result<&T>
|
||||||
|
@ -27,17 +27,14 @@ where
|
||||||
pub trait Functionality {
|
pub trait Functionality {
|
||||||
fn set_click_callbacks(
|
fn set_click_callbacks(
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(&str, Box<dyn Fn(&mut Commands) -> Result<()> + Send + Sync>)>,
|
||||||
&str,
|
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
|
||||||
)>,
|
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
fn set_select_callbacks(
|
fn set_select_callbacks(
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands, bool) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
|
@ -45,11 +42,7 @@ pub trait Functionality {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<
|
Box<dyn Fn(&mut Commands, ControllerButton) -> Result<bool> + Send + Sync>,
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
|
@ -57,7 +50,7 @@ pub trait Functionality {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands, &dyn Any) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
@ -91,12 +84,7 @@ pub trait Gridable {
|
||||||
|
|
||||||
pub trait Visibility {
|
pub trait Visibility {
|
||||||
fn visible(&self) -> bool;
|
fn visible(&self) -> bool;
|
||||||
fn set_visibility(
|
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()>;
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum GuiElement<'a> {
|
pub enum GuiElement<'a> {
|
||||||
|
|
|
@ -9,8 +9,7 @@ use crate::prelude::*;
|
||||||
|
|
||||||
/// `Executable` holds a closure which can be executed
|
/// `Executable` holds a closure which can be executed
|
||||||
pub struct Executable<I: Send + Sync> {
|
pub struct Executable<I: Send + Sync> {
|
||||||
callback:
|
callback: RwLock<Option<Arc<dyn Fn(&mut Commands, I) -> Result<()> + Send + Sync>>>,
|
||||||
RwLock<Option<Arc<dyn Fn(&mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Send + Sync + 'static> Executable<I> {
|
impl<I: Send + Sync + 'static> Executable<I> {
|
||||||
|
@ -28,7 +27,7 @@ impl<I: Send + Sync + 'static> Executable<I> {
|
||||||
/// * `callback` is a `Option<Callback>` closure
|
/// * `callback` is a `Option<Callback>` closure
|
||||||
pub fn set_callback<F>(&self, callback: impl Into<Option<F>>)
|
pub fn set_callback<F>(&self, callback: impl Into<Option<F>>)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync + 'static,
|
F: Fn(&mut Commands, I) -> Result<()> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let mut function = self.callback.write().unwrap();
|
let mut function = self.callback.write().unwrap();
|
||||||
|
|
||||||
|
@ -43,9 +42,7 @@ impl<I: Send + Sync + 'static> Executable<I> {
|
||||||
if let Some(callback) = self.callback.read().unwrap().as_ref() {
|
if let Some(callback) = self.callback.read().unwrap().as_ref() {
|
||||||
let callback = callback.clone();
|
let callback = callback.clone();
|
||||||
|
|
||||||
gui_handler.add_callback(move |commands, gui_handler| {
|
gui_handler.add_callback(move |commands| (callback)(commands, input));
|
||||||
(callback)(commands, gui_handler, input)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -40,15 +40,8 @@ pub struct Selectable {
|
||||||
on_select_executable: Arc<Executable<bool>>,
|
on_select_executable: Arc<Executable<bool>>,
|
||||||
|
|
||||||
// used for custom buttons
|
// used for custom buttons
|
||||||
custom_callback: RwLock<
|
custom_callback:
|
||||||
Option<
|
RwLock<Option<Box<dyn Fn(&mut Commands, ControllerButton) -> Result<bool> + Send + Sync>>>,
|
||||||
Box<
|
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selectable {
|
impl Selectable {
|
||||||
|
@ -124,10 +117,7 @@ impl Selectable {
|
||||||
|
|
||||||
pub fn set_custom_callback<F>(&self, custom_callback: F)
|
pub fn set_custom_callback<F>(&self, custom_callback: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
F: Fn(&mut Commands, ControllerButton) -> Result<bool> + Send + Sync + 'static,
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
{
|
{
|
||||||
*self.custom_callback.write().unwrap() = Some(Box::new(custom_callback));
|
*self.custom_callback.write().unwrap() = Some(Box::new(custom_callback));
|
||||||
}
|
}
|
||||||
|
@ -191,11 +181,10 @@ impl Selectable {
|
||||||
pub(crate) fn custom_click_event(
|
pub(crate) fn custom_click_event(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
button: ControllerButton,
|
button: ControllerButton,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
if let Some(custom_callback) = self.custom_callback.read().unwrap().as_ref() {
|
if let Some(custom_callback) = self.custom_callback.read().unwrap().as_ref() {
|
||||||
if custom_callback(commands, gui_handler, button)? {
|
if custom_callback(commands, button)? {
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
{
|
{
|
||||||
if let Some(audible) = self.click_audible.read().unwrap().as_ref() {
|
if let Some(audible) = self.click_audible.read().unwrap().as_ref() {
|
||||||
|
|
|
@ -2,31 +2,19 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ecs::Commands;
|
use ecs::Commands;
|
||||||
|
|
||||||
use crate::prelude::GuiHandler;
|
|
||||||
|
|
||||||
pub trait TopGui: Send + Sync {
|
pub trait TopGui: Send + Sync {
|
||||||
/// Decline method which is executed on `InputMap::B` press
|
/// Decline method which is executed on `InputMap::B` press
|
||||||
fn decline(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()>;
|
fn decline(&self, commands: &mut Commands) -> Result<()>;
|
||||||
|
|
||||||
/// Method which is executed on `InputMap::RightButton` press
|
/// Method which is executed on `InputMap::RightButton` press
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `second_level` adds support for multiple tab layers, e.g. RB and RT press on controller
|
/// * `second_level` adds support for multiple tab layers, e.g. RB and RT press on controller
|
||||||
fn next_tab(
|
fn next_tab(&self, commands: &mut Commands, second_level: bool) -> Result<()>;
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
second_level: bool,
|
|
||||||
) -> Result<()>;
|
|
||||||
|
|
||||||
/// Method which is executed on `InputMap::LeftButton` press
|
/// Method which is executed on `InputMap::LeftButton` press
|
||||||
/// ///
|
/// ///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `second_level` adds support for multiple tab layers, e.g. RB and RT press on controller
|
/// * `second_level` adds support for multiple tab layers, e.g. RB and RT press on controller
|
||||||
fn previous_tab(
|
fn previous_tab(&self, commands: &mut Commands, second_level: bool) -> Result<()>;
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
second_level: bool,
|
|
||||||
) -> Result<()>;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,7 +245,7 @@ pub struct GuiHandler {
|
||||||
|
|
||||||
text_sample_count: VkSampleCountFlags,
|
text_sample_count: VkSampleCountFlags,
|
||||||
|
|
||||||
callback_list: Vec<Box<dyn FnOnce(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>>,
|
callback_list: Vec<Box<dyn FnOnce(&mut Commands) -> Result<()> + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiHandler {
|
impl GuiHandler {
|
||||||
|
@ -730,12 +730,11 @@ impl GuiHandler {
|
||||||
|
|
||||||
pub fn accept_custom_selection(
|
pub fn accept_custom_selection(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
world: &mut World,
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
button: ControllerButton,
|
button: ControllerButton,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
if let Some(current_selectable) = &self.current_selectable {
|
if let Some(current_selectable) = &self.current_selectable {
|
||||||
if current_selectable.custom_click_event(commands, gui_handler, button)? {
|
if current_selectable.custom_click_event(world, button)? {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -743,15 +742,13 @@ impl GuiHandler {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decline_topgui(&mut self, commands: &mut Commands) -> Result<bool> {
|
pub fn decline_topgui(&mut self, world: &mut World) -> Result<bool> {
|
||||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
|
||||||
|
|
||||||
// workaround for unwanted borrowing behaviour inside decline function
|
// workaround for unwanted borrowing behaviour inside decline function
|
||||||
let opt_top_level_gui = self.top_ui.as_ref().cloned();
|
let opt_top_level_gui = self.top_ui.as_ref().cloned();
|
||||||
|
|
||||||
if let Some(top_level_gui) = opt_top_level_gui {
|
if let Some(top_level_gui) = opt_top_level_gui {
|
||||||
if let Some(top_gui) = top_level_gui.top_gui() {
|
if let Some(top_gui) = top_level_gui.top_gui() {
|
||||||
top_gui.decline(commands, callback_self)?;
|
top_gui.decline(world)?;
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,15 +756,13 @@ impl GuiHandler {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_tab_topgui(&mut self, commands: &mut Commands, second_level: bool) -> Result<bool> {
|
pub fn next_tab_topgui(&mut self, world: &mut World, second_level: bool) -> Result<bool> {
|
||||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
|
||||||
|
|
||||||
// workaround for unwanted borrowing behaviour inside decline function
|
// workaround for unwanted borrowing behaviour inside decline function
|
||||||
let opt_top_level_gui = self.top_ui.as_ref().cloned();
|
let opt_top_level_gui = self.top_ui.as_ref().cloned();
|
||||||
|
|
||||||
if let Some(top_level_gui) = opt_top_level_gui {
|
if let Some(top_level_gui) = opt_top_level_gui {
|
||||||
if let Some(top_gui) = top_level_gui.top_gui() {
|
if let Some(top_gui) = top_level_gui.top_gui() {
|
||||||
top_gui.next_tab(commands, callback_self, second_level)?;
|
top_gui.next_tab(world, second_level)?;
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -775,19 +770,13 @@ impl GuiHandler {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn previous_tab_topgui(
|
pub fn previous_tab_topgui(&mut self, world: &mut World, second_level: bool) -> Result<bool> {
|
||||||
&mut self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
second_level: bool,
|
|
||||||
) -> Result<bool> {
|
|
||||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
|
||||||
|
|
||||||
// workaround for unwanted borrowing behaviour inside decline function
|
// workaround for unwanted borrowing behaviour inside decline function
|
||||||
let opt_top_level_gui = self.top_ui.as_ref().cloned();
|
let opt_top_level_gui = self.top_ui.as_ref().cloned();
|
||||||
|
|
||||||
if let Some(top_level_gui) = opt_top_level_gui {
|
if let Some(top_level_gui) = opt_top_level_gui {
|
||||||
if let Some(top_gui) = top_level_gui.top_gui() {
|
if let Some(top_gui) = top_level_gui.top_gui() {
|
||||||
top_gui.previous_tab(commands, callback_self, second_level)?;
|
top_gui.previous_tab(world, second_level)?;
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -880,16 +869,14 @@ impl GuiHandler {
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
top_gui: Option<Arc<dyn TopLevelGui>>,
|
top_gui: Option<Arc<dyn TopLevelGui>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
|
||||||
|
|
||||||
match (&self.top_ui, &top_gui) {
|
match (&self.top_ui, &top_gui) {
|
||||||
(Some(current), Some(incoming)) => {
|
(Some(current), Some(incoming)) => {
|
||||||
if !Arc::ptr_eq(current, incoming) {
|
if !Arc::ptr_eq(current, incoming) {
|
||||||
current.disable(commands, callback_self)?;
|
current.disable(commands)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(current), None) => {
|
(Some(current), None) => {
|
||||||
current.disable(commands, callback_self)?;
|
current.disable(commands)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -905,16 +892,14 @@ impl GuiHandler {
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
tooltip: Option<Arc<dyn TopLevelGui>>,
|
tooltip: Option<Arc<dyn TopLevelGui>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
|
||||||
|
|
||||||
match (&self.tooltip_ui, &tooltip) {
|
match (&self.tooltip_ui, &tooltip) {
|
||||||
(Some(current), Some(incoming)) => {
|
(Some(current), Some(incoming)) => {
|
||||||
if !Arc::ptr_eq(current, incoming) {
|
if !Arc::ptr_eq(current, incoming) {
|
||||||
current.disable(commands, callback_self)?;
|
current.disable(commands)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(current), None) => {
|
(Some(current), None) => {
|
||||||
current.disable(commands, callback_self)?;
|
current.disable(commands)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -925,25 +910,19 @@ impl GuiHandler {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_callback<
|
pub(crate) fn add_callback<F: FnOnce(&mut Commands) -> Result<()> + Send + Sync + 'static>(
|
||||||
F: FnOnce(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
|
|
||||||
>(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
f: F,
|
f: F,
|
||||||
) {
|
) {
|
||||||
self.callback_list.push(Box::new(f));
|
self.callback_list.push(Box::new(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_callbacks(
|
pub fn process_callbacks(&mut self, commands: &mut Commands) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
) -> Result<()> {
|
|
||||||
let callbacks = mem::take(&mut self.callback_list);
|
let callbacks = mem::take(&mut self.callback_list);
|
||||||
|
|
||||||
callbacks
|
callbacks
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_for_each(|callback| callback(commands, gui_handler))
|
.try_for_each(|callback| callback(commands))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(
|
fn render(
|
||||||
|
|
|
@ -26,48 +26,32 @@ pub struct Keyboard {
|
||||||
|
|
||||||
mode: Arc<RwLock<KeyboardMode>>,
|
mode: Arc<RwLock<KeyboardMode>>,
|
||||||
|
|
||||||
decline_callback: Arc<
|
decline_callback: Arc<RwLock<Option<Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>>>>,
|
||||||
RwLock<Option<Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>>>,
|
accept_callback:
|
||||||
>,
|
Arc<RwLock<Option<Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>>>>,
|
||||||
accept_callback: Arc<
|
|
||||||
RwLock<
|
|
||||||
Option<
|
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
|
|
||||||
elements: HashMap<String, UiElement>,
|
elements: HashMap<String, UiElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keyboard {
|
impl Keyboard {
|
||||||
pub fn new(commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
|
pub fn new(world: &mut World) -> Result<Arc<Self>> {
|
||||||
let text_field_gui: Arc<GuiBuilder> =
|
let text_field_gui: Arc<GuiBuilder> =
|
||||||
GuiBuilder::from_str(commands, gui_handler, include_str!("text_field.xml"))?;
|
GuiBuilder::from_str(world, include_str!("text_field.xml"))?;
|
||||||
|
|
||||||
let text_field: Arc<TextField> = text_field_gui.element("field")?;
|
let text_field: Arc<TextField> = text_field_gui.element("field")?;
|
||||||
|
|
||||||
let decline_callback: Arc<
|
let decline_callback: Arc<
|
||||||
RwLock<Option<Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>>>,
|
RwLock<Option<Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>>>,
|
||||||
> = Arc::new(RwLock::new(None));
|
> = Arc::new(RwLock::new(None));
|
||||||
|
|
||||||
let accept_callback: Arc<
|
let accept_callback: Arc<
|
||||||
RwLock<
|
RwLock<Option<Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>>>,
|
||||||
Option<
|
|
||||||
Box<
|
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
> = Arc::new(RwLock::new(None));
|
> = Arc::new(RwLock::new(None));
|
||||||
|
|
||||||
let mode = Arc::new(RwLock::new(KeyboardMode::UpperCase));
|
let mode = Arc::new(RwLock::new(KeyboardMode::UpperCase));
|
||||||
|
|
||||||
let (lower_case, upper_case, specials) = Self::setup(
|
let (lower_case, upper_case, specials) = Self::setup(
|
||||||
commands,
|
world,
|
||||||
gui_handler,
|
|
||||||
text_field.clone(),
|
text_field.clone(),
|
||||||
&mode,
|
&mode,
|
||||||
decline_callback.clone(),
|
decline_callback.clone(),
|
||||||
|
@ -99,30 +83,17 @@ impl Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
commands: &mut Commands,
|
world: &mut World,
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
textfield: Arc<TextField>,
|
textfield: Arc<TextField>,
|
||||||
mode: &Arc<RwLock<KeyboardMode>>,
|
mode: &Arc<RwLock<KeyboardMode>>,
|
||||||
decline_callback: Arc<
|
decline_callback: Arc<RwLock<Option<Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>>>>,
|
||||||
RwLock<Option<Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>>>,
|
|
||||||
>,
|
|
||||||
accept_callback: Arc<
|
accept_callback: Arc<
|
||||||
RwLock<
|
RwLock<Option<Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>>>,
|
||||||
Option<
|
|
||||||
Box<
|
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
>,
|
||||||
) -> Result<(Arc<GuiBuilder>, Arc<GuiBuilder>, Arc<GuiBuilder>)> {
|
) -> Result<(Arc<GuiBuilder>, Arc<GuiBuilder>, Arc<GuiBuilder>)> {
|
||||||
let lower_case =
|
let lower_case = GuiBuilder::from_str(world, include_str!("lower_case.xml"))?;
|
||||||
GuiBuilder::from_str(commands, gui_handler, include_str!("lower_case.xml"))?;
|
let upper_case = GuiBuilder::from_str(world, include_str!("upper_case.xml"))?;
|
||||||
let upper_case =
|
let specials = GuiBuilder::from_str(world, include_str!("specials.xml"))?;
|
||||||
GuiBuilder::from_str(commands, gui_handler, include_str!("upper_case.xml"))?;
|
|
||||||
let specials = GuiBuilder::from_str(commands, gui_handler, include_str!("specials.xml"))?;
|
|
||||||
|
|
||||||
// first row
|
// first row
|
||||||
Self::set_text_callback(&lower_case, "q", textfield.clone())?;
|
Self::set_text_callback(&lower_case, "q", textfield.clone())?;
|
||||||
|
@ -224,35 +195,31 @@ impl Keyboard {
|
||||||
Self::set_text_callback(&specials, ".", textfield.clone())?;
|
Self::set_text_callback(&specials, ".", textfield.clone())?;
|
||||||
Self::set_text_callback(&specials, "_", textfield.clone())?;
|
Self::set_text_callback(&specials, "_", textfield.clone())?;
|
||||||
|
|
||||||
let back = Box::new(
|
let back = Box::new(move |world: &mut World| {
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(callback) = decline_callback.read().unwrap().as_ref() {
|
||||||
if let Some(callback) = decline_callback.read().unwrap().as_ref() {
|
(callback)(world)?;
|
||||||
(callback)(commands, gui_handler)?;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let accept = {
|
let accept = {
|
||||||
let weak_textfield = Arc::downgrade(&textfield);
|
let weak_textfield = Arc::downgrade(&textfield);
|
||||||
let weak_accept = Arc::downgrade(&accept_callback);
|
let weak_accept = Arc::downgrade(&accept_callback);
|
||||||
|
|
||||||
Box::new(
|
Box::new(move |world: &mut World| {
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(textfield) = weak_textfield.upgrade() {
|
||||||
if let Some(textfield) = weak_textfield.upgrade() {
|
if let Some(accept_callback) = weak_accept.upgrade() {
|
||||||
if let Some(accept_callback) = weak_accept.upgrade() {
|
if let Some(text) = textfield.text() {
|
||||||
if let Some(text) = textfield.text() {
|
if let Some(callback) = accept_callback.read().unwrap().as_ref() {
|
||||||
if let Some(callback) = accept_callback.read().unwrap().as_ref() {
|
(callback)(world, &text)?;
|
||||||
(callback)(commands, gui_handler, &text)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
})
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let switch_to_upper = {
|
let switch_to_upper = {
|
||||||
|
@ -260,24 +227,22 @@ impl Keyboard {
|
||||||
let weak_lower = Arc::downgrade(&lower_case);
|
let weak_lower = Arc::downgrade(&lower_case);
|
||||||
let weak_upper = Arc::downgrade(&upper_case);
|
let weak_upper = Arc::downgrade(&upper_case);
|
||||||
|
|
||||||
Box::new(
|
Box::new(move |world: &mut World| {
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(lower) = weak_lower.upgrade() {
|
||||||
if let Some(lower) = weak_lower.upgrade() {
|
if let Some(upper) = weak_upper.upgrade() {
|
||||||
if let Some(upper) = weak_upper.upgrade() {
|
let mut mode = mode.write().unwrap();
|
||||||
let mut mode = mode.write().unwrap();
|
|
||||||
|
|
||||||
if let KeyboardMode::LowerCase = mode.deref() {
|
if let KeyboardMode::LowerCase = mode.deref() {
|
||||||
*mode = KeyboardMode::UpperCase;
|
*mode = KeyboardMode::UpperCase;
|
||||||
|
|
||||||
lower.disable(commands, gui_handler)?;
|
lower.disable(world)?;
|
||||||
upper.enable(commands, gui_handler)?;
|
upper.enable(world)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
})
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let switch_to_special = {
|
let switch_to_special = {
|
||||||
|
@ -285,24 +250,22 @@ impl Keyboard {
|
||||||
let weak_upper = Arc::downgrade(&upper_case);
|
let weak_upper = Arc::downgrade(&upper_case);
|
||||||
let weak_specials = Arc::downgrade(&specials);
|
let weak_specials = Arc::downgrade(&specials);
|
||||||
|
|
||||||
Box::new(
|
Box::new(move |world: &mut World| {
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(specials) = weak_specials.upgrade() {
|
||||||
if let Some(specials) = weak_specials.upgrade() {
|
if let Some(upper) = weak_upper.upgrade() {
|
||||||
if let Some(upper) = weak_upper.upgrade() {
|
let mut mode = mode.write().unwrap();
|
||||||
let mut mode = mode.write().unwrap();
|
|
||||||
|
|
||||||
if let KeyboardMode::UpperCase = mode.deref() {
|
if let KeyboardMode::UpperCase = mode.deref() {
|
||||||
*mode = KeyboardMode::Specials;
|
*mode = KeyboardMode::Specials;
|
||||||
|
|
||||||
upper.disable(commands, gui_handler)?;
|
upper.disable(world)?;
|
||||||
specials.enable(commands, gui_handler)?;
|
specials.enable(world)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
})
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let switch_to_lower = {
|
let switch_to_lower = {
|
||||||
|
@ -310,38 +273,34 @@ impl Keyboard {
|
||||||
let weak_lower = Arc::downgrade(&lower_case);
|
let weak_lower = Arc::downgrade(&lower_case);
|
||||||
let weak_specials = Arc::downgrade(&specials);
|
let weak_specials = Arc::downgrade(&specials);
|
||||||
|
|
||||||
Box::new(
|
Box::new(move |world: &mut World| {
|
||||||
move |commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(lower) = weak_lower.upgrade() {
|
||||||
if let Some(lower) = weak_lower.upgrade() {
|
if let Some(specials) = weak_specials.upgrade() {
|
||||||
if let Some(specials) = weak_specials.upgrade() {
|
let mut mode = mode.write().unwrap();
|
||||||
let mut mode = mode.write().unwrap();
|
|
||||||
|
|
||||||
if let KeyboardMode::Specials = mode.deref() {
|
if let KeyboardMode::Specials = mode.deref() {
|
||||||
*mode = KeyboardMode::LowerCase;
|
*mode = KeyboardMode::LowerCase;
|
||||||
|
|
||||||
specials.disable(commands, gui_handler)?;
|
specials.disable(world)?;
|
||||||
lower.enable(commands, gui_handler)?;
|
lower.enable(world)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
})
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let space_bar = {
|
let space_bar = {
|
||||||
let weak_textfield = Arc::downgrade(&textfield);
|
let weak_textfield = Arc::downgrade(&textfield);
|
||||||
|
|
||||||
Box::new(
|
Box::new(move |world: &mut World| {
|
||||||
move |_commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(text_field) = weak_textfield.upgrade() {
|
||||||
if let Some(text_field) = weak_textfield.upgrade() {
|
text_field.add_letter(world.resources.get_mut()?, ' ')?;
|
||||||
text_field.add_letter(gui_handler, ' ')?;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
})
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
lower_case.set_click_callbacks(vec![
|
lower_case.set_click_callbacks(vec![
|
||||||
|
@ -376,51 +335,40 @@ impl Keyboard {
|
||||||
let weak_textfield = Arc::downgrade(&textfield);
|
let weak_textfield = Arc::downgrade(&textfield);
|
||||||
let weak_button = Arc::downgrade(&button_ref);
|
let weak_button = Arc::downgrade(&button_ref);
|
||||||
|
|
||||||
button_ref.set_callback(Box::new(
|
button_ref.set_callback(Box::new(move |world: &mut World| {
|
||||||
move |_commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(textfield) = weak_textfield.upgrade() {
|
||||||
if let Some(textfield) = weak_textfield.upgrade() {
|
if let Some(button) = weak_button.upgrade() {
|
||||||
if let Some(button) = weak_button.upgrade() {
|
if let Some(text) = button.text()? {
|
||||||
if let Some(text) = button.text()? {
|
textfield
|
||||||
textfield.add_letter(gui_handler, text.as_bytes()[0] as char)?;
|
.add_letter(world.resources.get_mut()?, text.as_bytes()[0] as char)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopGui for Keyboard {
|
impl TopGui for Keyboard {
|
||||||
fn decline(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn decline(&self, world: &mut World) -> Result<()> {
|
||||||
if let Some(callback) = self.decline_callback.read().unwrap().as_ref() {
|
if let Some(callback) = self.decline_callback.read().unwrap().as_ref() {
|
||||||
(callback)(commands, gui_handler)?;
|
(callback)(world)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_tab(
|
fn next_tab(&self, _world: &mut World, _: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
_gui_handler: &mut GuiHandler,
|
|
||||||
_: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn previous_tab(
|
fn previous_tab(&self, world: &mut World, second_level: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
second_level: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
// abuse event
|
// abuse event
|
||||||
if !second_level {
|
if !second_level {
|
||||||
self.text_field.remove_last(gui_handler)?;
|
self.text_field.remove_last(world.resources.get_mut()?)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -438,12 +386,7 @@ impl Visibility for Keyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
visibility: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
let mode = self.mode.read().unwrap();
|
let mode = self.mode.read().unwrap();
|
||||||
|
|
||||||
let gui = match mode.deref() {
|
let gui = match mode.deref() {
|
||||||
|
@ -453,11 +396,11 @@ impl Visibility for Keyboard {
|
||||||
};
|
};
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
gui.enable(commands, gui_handler)?;
|
gui.enable(world)?;
|
||||||
self.text_field_gui.enable(commands, gui_handler)?;
|
self.text_field_gui.enable(world)?;
|
||||||
} else {
|
} else {
|
||||||
gui.disable(commands, gui_handler)?;
|
gui.disable(world)?;
|
||||||
self.text_field_gui.disable(commands, gui_handler)?;
|
self.text_field_gui.disable(world)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -495,15 +438,15 @@ impl TopLevelGui for Keyboard {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn enable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(commands, gui_handler, true)?;
|
self.set_visibility(world, true)?;
|
||||||
self.text_field.focus_input(gui_handler)?;
|
self.text_field.focus_input(world.resources.get_mut()?)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(commands, gui_handler, false)?;
|
self.set_visibility(world, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -512,10 +455,7 @@ impl TopLevelGui for Keyboard {
|
||||||
impl Functionality for Keyboard {
|
impl Functionality for Keyboard {
|
||||||
fn set_click_callbacks(
|
fn set_click_callbacks(
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(&str, Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>)>,
|
||||||
&str,
|
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
|
||||||
)>,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Some((_, callback)) = callbacks.into_iter().find(|(name, _)| *name == "decline") {
|
if let Some((_, callback)) = callbacks.into_iter().find(|(name, _)| *name == "decline") {
|
||||||
*self.decline_callback.write().unwrap() = Some(callback);
|
*self.decline_callback.write().unwrap() = Some(callback);
|
||||||
|
@ -528,7 +468,7 @@ impl Functionality for Keyboard {
|
||||||
&self,
|
&self,
|
||||||
_: Vec<(
|
_: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut World, bool) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -538,11 +478,7 @@ impl Functionality for Keyboard {
|
||||||
&self,
|
&self,
|
||||||
_: Vec<(
|
_: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<
|
Box<dyn Fn(&mut World, ControllerButton) -> Result<bool> + Send + Sync>,
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -552,7 +488,7 @@ impl Functionality for Keyboard {
|
||||||
&self,
|
&self,
|
||||||
callbacks: Vec<(
|
callbacks: Vec<(
|
||||||
&str,
|
&str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (name, callback) in callbacks {
|
for (name, callback) in callbacks {
|
||||||
|
|
33
src/state.rs
33
src/state.rs
|
@ -111,13 +111,12 @@ pub(crate) struct State {
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub(crate) fn new<'a>(
|
pub(crate) fn new<'a>(
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
name: &str,
|
name: &str,
|
||||||
creation_type: CreationType<'a>,
|
creation_type: CreationType<'a>,
|
||||||
) -> Result<Arc<Self>> {
|
) -> Result<Arc<Self>> {
|
||||||
let gui = match creation_type {
|
let gui = match creation_type {
|
||||||
CreationType::File(path) => GuiBuilder::new(commands, gui_handler, path)?,
|
CreationType::File(path) => GuiBuilder::new(gui_handler, path)?,
|
||||||
CreationType::TopGui(top_gui) => top_gui,
|
CreationType::TopGui(top_gui) => top_gui,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,14 +215,14 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopGui for State {
|
impl TopGui for State {
|
||||||
fn decline(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn decline(&self, commands: &mut Commands) -> Result<()> {
|
||||||
match self.decline.read().unwrap().as_ref() {
|
match self.decline.read().unwrap().as_ref() {
|
||||||
Some(decline) => {
|
Some(decline) => {
|
||||||
(decline)(commands)?;
|
(decline)(commands)?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if let Some(top_gui) = self.top_level_gui.top_gui() {
|
if let Some(top_gui) = self.top_level_gui.top_gui() {
|
||||||
top_gui.decline(commands, gui_handler)?;
|
top_gui.decline(commands)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,19 +230,14 @@ impl TopGui for State {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_tab(
|
fn next_tab(&self, commands: &mut Commands, second_level: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
second_level: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
match self.next_tab.read().unwrap().as_ref() {
|
match self.next_tab.read().unwrap().as_ref() {
|
||||||
Some(next_tab) => {
|
Some(next_tab) => {
|
||||||
(next_tab)(commands)?;
|
(next_tab)(commands)?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if let Some(top_gui) = self.top_level_gui.top_gui() {
|
if let Some(top_gui) = self.top_level_gui.top_gui() {
|
||||||
top_gui.next_tab(commands, gui_handler, second_level)?;
|
top_gui.next_tab(commands, second_level)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,19 +245,14 @@ impl TopGui for State {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn previous_tab(
|
fn previous_tab(&self, commands: &mut Commands, second_level: bool) -> Result<()> {
|
||||||
&self,
|
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
second_level: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
match self.previous_tab.read().unwrap().as_ref() {
|
match self.previous_tab.read().unwrap().as_ref() {
|
||||||
Some(previous_tab) => {
|
Some(previous_tab) => {
|
||||||
(previous_tab)(commands)?;
|
(previous_tab)(commands)?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if let Some(top_gui) = self.top_level_gui.top_gui() {
|
if let Some(top_gui) = self.top_level_gui.top_gui() {
|
||||||
top_gui.previous_tab(commands, gui_handler, second_level)?;
|
top_gui.previous_tab(commands, second_level)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,8 +278,8 @@ impl TopLevelGui for State {
|
||||||
self.top_level_gui.functionality()
|
self.top_level_gui.functionality()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn enable(&self, commands: &mut Commands) -> Result<()> {
|
||||||
self.top_level_gui.enable(commands, gui_handler)?;
|
self.top_level_gui.enable(commands)?;
|
||||||
|
|
||||||
if let Some(activate) = self.on_activate.read().unwrap().as_ref() {
|
if let Some(activate) = self.on_activate.read().unwrap().as_ref() {
|
||||||
(activate)(commands)?;
|
(activate)(commands)?;
|
||||||
|
@ -299,8 +288,8 @@ impl TopLevelGui for State {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, commands: &mut Commands, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable(&self, commands: &mut Commands) -> Result<()> {
|
||||||
self.top_level_gui.disable(commands, gui_handler)?;
|
self.top_level_gui.disable(commands)?;
|
||||||
|
|
||||||
if let Some(deactivate) = self.on_deactivate.read().unwrap().as_ref() {
|
if let Some(deactivate) = self.on_deactivate.read().unwrap().as_ref() {
|
||||||
(deactivate)(commands)?;
|
(deactivate)(commands)?;
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub enum StateUpdateType<'a> {
|
||||||
ClickCallbacks(
|
ClickCallbacks(
|
||||||
Vec<(
|
Vec<(
|
||||||
&'a str,
|
&'a str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ pub enum StateUpdateType<'a> {
|
||||||
SelectCallbacks(
|
SelectCallbacks(
|
||||||
Vec<(
|
Vec<(
|
||||||
&'a str,
|
&'a str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands, bool) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -79,11 +79,7 @@ pub enum StateUpdateType<'a> {
|
||||||
CustomClickCallbacks(
|
CustomClickCallbacks(
|
||||||
Vec<(
|
Vec<(
|
||||||
&'a str,
|
&'a str,
|
||||||
Box<
|
Box<dyn Fn(&mut Commands, ControllerButton) -> Result<bool> + Send + Sync>,
|
||||||
dyn Fn(&mut Commands, &mut GuiHandler, ControllerButton) -> Result<bool>
|
|
||||||
+ Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
)>,
|
)>,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -91,7 +87,7 @@ pub enum StateUpdateType<'a> {
|
||||||
VecCallbacks(
|
VecCallbacks(
|
||||||
Vec<(
|
Vec<(
|
||||||
&'a str,
|
&'a str,
|
||||||
Box<dyn Fn(&mut Commands, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync>,
|
Box<dyn Fn(&mut Commands, &dyn Any) -> Result<()> + Send + Sync>,
|
||||||
)>,
|
)>,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -170,14 +166,13 @@ impl States {
|
||||||
/// Adds a single state
|
/// Adds a single state
|
||||||
pub fn add_state<'a>(
|
pub fn add_state<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
id: &str,
|
id: &str,
|
||||||
creation_type: impl Into<CreationType<'a>>,
|
creation_type: impl Into<CreationType<'a>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.states.insert(
|
self.states.insert(
|
||||||
id.to_string(),
|
id.to_string(),
|
||||||
State::new(commands, gui_handler, id, creation_type.into())?,
|
State::new(gui_handler, id, creation_type.into())?,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -227,13 +222,13 @@ impl States {
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute deactivate on old state
|
// execute deactivate on old state
|
||||||
old_state.disable(commands, gui_handler)?;
|
old_state.disable(commands)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set new state, either no state or requested state
|
// set new state, either no state or requested state
|
||||||
match state {
|
match state {
|
||||||
Some(state) => {
|
Some(state) => {
|
||||||
state.enable(commands, gui_handler)?;
|
state.enable(commands)?;
|
||||||
gui_handler.set_top_gui(commands, Some(state.clone()))?;
|
gui_handler.set_top_gui(commands, Some(state.clone()))?;
|
||||||
|
|
||||||
if logging {
|
if logging {
|
||||||
|
|
Loading…
Reference in a new issue