Compare commits
4 commits
bfd891e688
...
2f1b4688af
Author | SHA1 | Date | |
---|---|---|---|
2f1b4688af | |||
|
6828597672 | ||
|
d5fee4d486 | ||
|
10cb0a997f |
15 changed files with 177 additions and 138 deletions
|
@ -20,3 +20,4 @@ ecs = { git = "https://gavania.de/hodasemi/ecs.git" }
|
||||||
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["audio"]
|
||||||
|
|
|
@ -23,31 +23,31 @@ pub struct GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiBuilder {
|
impl GuiBuilder {
|
||||||
pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result<Arc<Self>> {
|
pub fn new(world: &mut World, path: &AssetPath) -> Result<Arc<Self>> {
|
||||||
let validator = Validator::new(
|
let validator = Validator::new(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
world.resources.get::<GuiHandler>(),
|
||||||
path,
|
path,
|
||||||
)
|
)
|
||||||
.with_context(|| format!("validator for {}", path.full_path()))?;
|
.with_context(|| format!("validator for {}", path.full_path()))?;
|
||||||
|
|
||||||
Ok(Arc::new(Self::_new(gui_handler, validator).with_context(
|
Ok(Arc::new(Self::_new(world, validator).with_context(
|
||||||
|| format!("for file {}", path.full_path()),
|
|| format!("for file {}", path.full_path()),
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str(gui_handler: &mut GuiHandler, s: &str) -> Result<Arc<Self>> {
|
pub fn from_str(world: &mut World, s: &str) -> Result<Arc<Self>> {
|
||||||
let validator = Validator::from_str(
|
let validator = Validator::from_str(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
world.resources.get::<GuiHandler>(),
|
||||||
s,
|
s,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Arc::new(Self::_new(gui_handler, validator)?))
|
Ok(Arc::new(Self::_new(world, validator)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge<'a>(
|
pub fn merge<'a>(
|
||||||
gui_handler: &mut GuiHandler,
|
world: &mut World,
|
||||||
pathes: impl IntoIterator<Item = &'a AssetPath>,
|
pathes: impl IntoIterator<Item = &'a AssetPath>,
|
||||||
) -> Result<Arc<Self>> {
|
) -> Result<Arc<Self>> {
|
||||||
let mut me = Self {
|
let mut me = Self {
|
||||||
|
@ -62,11 +62,11 @@ impl GuiBuilder {
|
||||||
for path in pathes.into_iter() {
|
for path in pathes.into_iter() {
|
||||||
let validator = Validator::new(
|
let validator = Validator::new(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
world.resources.get::<GuiHandler>(),
|
||||||
path,
|
path,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let builder = Self::_new(gui_handler, validator)
|
let builder = Self::_new(world, 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);
|
||||||
|
@ -86,7 +86,7 @@ impl GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn _new(gui_handler: &mut GuiHandler, validator: Validator) -> Result<Self> {
|
fn _new(world: &mut World, validator: Validator) -> Result<Self> {
|
||||||
let root = validator.root();
|
let root = validator.root();
|
||||||
|
|
||||||
let mut ids = HashMap::new();
|
let mut ids = HashMap::new();
|
||||||
|
@ -95,8 +95,11 @@ impl GuiBuilder {
|
||||||
|
|
||||||
let mut grids = Vec::new();
|
let mut grids = Vec::new();
|
||||||
|
|
||||||
|
let gui_handler = world.resources.get_mut_unchecked::<GuiHandler>();
|
||||||
|
|
||||||
for child in &root.children {
|
for child in &root.children {
|
||||||
let tree = Self::create_tree(
|
let tree = Self::create_tree(
|
||||||
|
world,
|
||||||
gui_handler,
|
gui_handler,
|
||||||
&mut ids,
|
&mut ids,
|
||||||
child,
|
child,
|
||||||
|
@ -245,9 +248,9 @@ impl Visibility for GuiBuilder {
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
for grid in &self.grids {
|
for grid in &self.grids {
|
||||||
grid.set_visibility(gui_handler, visibility)?;
|
grid.set_visibility(world, visibility)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -303,18 +306,18 @@ impl TopLevelGui for GuiBuilder {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn enable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(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::<GuiHandler>())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(gui_handler, false)?;
|
self.set_visibility(world, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -342,6 +345,7 @@ impl_element!(MultiLineTextField);
|
||||||
// private
|
// private
|
||||||
impl GuiBuilder {
|
impl GuiBuilder {
|
||||||
fn create_tree(
|
fn create_tree(
|
||||||
|
world: &mut World,
|
||||||
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>,
|
||||||
|
@ -394,6 +398,7 @@ 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(
|
||||||
|
world,
|
||||||
gui_handler,
|
gui_handler,
|
||||||
child,
|
child,
|
||||||
&root_grid,
|
&root_grid,
|
||||||
|
@ -408,6 +413,7 @@ impl GuiBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_child(
|
fn create_child(
|
||||||
|
world: &mut World,
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
child: &UiInfoElement,
|
child: &UiInfoElement,
|
||||||
grid: &Grid,
|
grid: &Grid,
|
||||||
|
@ -423,7 +429,7 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &button_info.id, &button)?;
|
Self::insert_id(ids, &button_info.id, &button)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
gui_handler,
|
world,
|
||||||
button.clone(),
|
button.clone(),
|
||||||
button_info
|
button_info
|
||||||
.x_slot
|
.x_slot
|
||||||
|
@ -458,7 +464,7 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &label_info.id, &label)?;
|
Self::insert_id(ids, &label_info.id, &label)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
gui_handler,
|
world,
|
||||||
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")?,
|
||||||
label_info.y_slot.get().with_context(|| "y_slot of label")?,
|
label_info.y_slot.get().with_context(|| "y_slot of label")?,
|
||||||
|
@ -470,12 +476,12 @@ 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, gui_handler)?;
|
MultiLineLabel::try_from(multi_line_label_info, world, 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(
|
||||||
gui_handler,
|
world,
|
||||||
multi_line_label.clone(),
|
multi_line_label.clone(),
|
||||||
multi_line_label_info
|
multi_line_label_info
|
||||||
.x_slot
|
.x_slot
|
||||||
|
@ -493,12 +499,12 @@ impl GuiBuilder {
|
||||||
}
|
}
|
||||||
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
||||||
let multi_line_text_field =
|
let multi_line_text_field =
|
||||||
MultiLineTextField::try_from(multi_line_text_field_info, gui_handler)?;
|
MultiLineTextField::try_from(multi_line_text_field_info, world, 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(
|
||||||
gui_handler,
|
world,
|
||||||
multi_line_text_field.clone(),
|
multi_line_text_field.clone(),
|
||||||
multi_line_text_field_info
|
multi_line_text_field_info
|
||||||
.x_slot
|
.x_slot
|
||||||
|
@ -520,7 +526,7 @@ 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(
|
||||||
gui_handler,
|
world,
|
||||||
text_field.clone(),
|
text_field.clone(),
|
||||||
text_field_info
|
text_field_info
|
||||||
.x_slot
|
.x_slot
|
||||||
|
@ -542,7 +548,7 @@ 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(
|
||||||
gui_handler,
|
world,
|
||||||
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")?,
|
||||||
icon_info.y_slot.get().with_context(|| "y_slot of icon")?,
|
icon_info.y_slot.get().with_context(|| "y_slot of icon")?,
|
||||||
|
@ -558,7 +564,7 @@ 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(
|
||||||
gui_handler,
|
world,
|
||||||
progress_bar.clone(),
|
progress_bar.clone(),
|
||||||
progress_bar_info
|
progress_bar_info
|
||||||
.x_slot
|
.x_slot
|
||||||
|
@ -580,7 +586,7 @@ impl GuiBuilder {
|
||||||
Self::insert_id(ids, &grid_info.id, &sub_grid)?;
|
Self::insert_id(ids, &grid_info.id, &sub_grid)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
gui_handler,
|
world,
|
||||||
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")?,
|
||||||
grid_info.y_slot.get().with_context(|| "y_slot of grid")?,
|
grid_info.y_slot.get().with_context(|| "y_slot of grid")?,
|
||||||
|
@ -593,6 +599,7 @@ 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(
|
||||||
|
world,
|
||||||
gui_handler,
|
gui_handler,
|
||||||
child,
|
child,
|
||||||
&sub_grid,
|
&sub_grid,
|
||||||
|
|
|
@ -18,27 +18,27 @@ pub struct GuiSnippet {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiSnippet {
|
impl GuiSnippet {
|
||||||
pub fn new(gui_handler: &mut GuiHandler, path: &AssetPath) -> Result<Arc<Self>> {
|
pub fn new(world: &mut World, path: &AssetPath) -> Result<Arc<Self>> {
|
||||||
let validator = Validator::new(
|
let validator = Validator::new(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
world.resources.get::<GuiHandler>(),
|
||||||
path,
|
path,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Self::_new(gui_handler, validator)
|
Self::_new(world, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_str(gui_handler: &mut GuiHandler, s: &str) -> Result<Arc<Self>> {
|
pub fn from_str(world: &mut World, s: &str) -> Result<Arc<Self>> {
|
||||||
let validator = Validator::from_str(
|
let validator = Validator::from_str(
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
gui_handler,
|
world.resources.get::<GuiHandler>(),
|
||||||
s,
|
s,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Self::_new(gui_handler, validator)
|
Self::_new(world, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _new(gui_handler: &mut GuiHandler, validator: Validator) -> Result<Arc<Self>> {
|
fn _new(world: &mut World, validator: Validator) -> Result<Arc<Self>> {
|
||||||
let root = validator.root();
|
let root = validator.root();
|
||||||
|
|
||||||
let mut ids = HashMap::new();
|
let mut ids = HashMap::new();
|
||||||
|
@ -51,13 +51,22 @@ impl GuiSnippet {
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let gui_handler = world.resources.get_mut_unchecked::<GuiHandler>();
|
||||||
|
|
||||||
let grid_info = &root.children[0];
|
let grid_info = &root.children[0];
|
||||||
let grid = Grid::try_from(gui_handler, grid_info, false)?;
|
let grid = Grid::try_from(gui_handler, grid_info, false)?;
|
||||||
|
|
||||||
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(gui_handler, child, &grid, &mut ids, &mut custom_neighbours)?;
|
Self::create_child(
|
||||||
|
world,
|
||||||
|
gui_handler,
|
||||||
|
child,
|
||||||
|
&grid,
|
||||||
|
&mut ids,
|
||||||
|
&mut custom_neighbours,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiBuilder::connect_custom_neighbours(&ids, custom_neighbours)?;
|
GuiBuilder::connect_custom_neighbours(&ids, custom_neighbours)?;
|
||||||
|
@ -94,8 +103,8 @@ impl Visibility for GuiSnippet {
|
||||||
self.grid.visible()
|
self.grid.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
self.grid.set_visibility(gui_handler, visibility)
|
self.grid.set_visibility(world, visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +216,7 @@ impl Functionality for GuiSnippet {
|
||||||
|
|
||||||
impl GuiSnippet {
|
impl GuiSnippet {
|
||||||
fn create_child(
|
fn create_child(
|
||||||
|
world: &mut World,
|
||||||
gui_handler: &mut GuiHandler,
|
gui_handler: &mut GuiHandler,
|
||||||
child: &UiInfoElement,
|
child: &UiInfoElement,
|
||||||
grid: &Grid,
|
grid: &Grid,
|
||||||
|
@ -220,7 +230,7 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &button_info.id, &button)?;
|
GuiBuilder::insert_id(ids, &button_info.id, &button)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
gui_handler,
|
world,
|
||||||
button.clone(),
|
button.clone(),
|
||||||
button_info.x_slot.get()?,
|
button_info.x_slot.get()?,
|
||||||
button_info.y_slot.get()?,
|
button_info.y_slot.get()?,
|
||||||
|
@ -236,7 +246,7 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &label_info.id, &label)?;
|
GuiBuilder::insert_id(ids, &label_info.id, &label)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
gui_handler,
|
world,
|
||||||
label,
|
label,
|
||||||
label_info.x_slot.get()?,
|
label_info.x_slot.get()?,
|
||||||
label_info.y_slot.get()?,
|
label_info.y_slot.get()?,
|
||||||
|
@ -246,12 +256,12 @@ 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, gui_handler)?;
|
MultiLineLabel::try_from(multi_line_label_info, world, 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(
|
||||||
gui_handler,
|
world,
|
||||||
multi_line_label,
|
multi_line_label,
|
||||||
multi_line_label_info.x_slot.get()?,
|
multi_line_label_info.x_slot.get()?,
|
||||||
multi_line_label_info.y_slot.get()?,
|
multi_line_label_info.y_slot.get()?,
|
||||||
|
@ -261,12 +271,12 @@ impl GuiSnippet {
|
||||||
}
|
}
|
||||||
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
UiInfoElement::MultiLineTextField(multi_line_text_field_info) => {
|
||||||
let multi_line_text_field =
|
let multi_line_text_field =
|
||||||
MultiLineTextField::try_from(multi_line_text_field_info, gui_handler)?;
|
MultiLineTextField::try_from(multi_line_text_field_info, world, 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(
|
||||||
gui_handler,
|
world,
|
||||||
multi_line_text_field,
|
multi_line_text_field,
|
||||||
multi_line_text_field_info.x_slot.get()?,
|
multi_line_text_field_info.x_slot.get()?,
|
||||||
multi_line_text_field_info.y_slot.get()?,
|
multi_line_text_field_info.y_slot.get()?,
|
||||||
|
@ -280,7 +290,7 @@ 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(
|
||||||
gui_handler,
|
world,
|
||||||
text_field,
|
text_field,
|
||||||
text_field_info.x_slot.get()?,
|
text_field_info.x_slot.get()?,
|
||||||
text_field_info.y_slot.get()?,
|
text_field_info.y_slot.get()?,
|
||||||
|
@ -294,7 +304,7 @@ 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(
|
||||||
gui_handler,
|
world,
|
||||||
icon,
|
icon,
|
||||||
icon_info.x_slot.get()?,
|
icon_info.x_slot.get()?,
|
||||||
icon_info.y_slot.get()?,
|
icon_info.y_slot.get()?,
|
||||||
|
@ -308,7 +318,7 @@ 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(
|
||||||
gui_handler,
|
world,
|
||||||
progress_bar,
|
progress_bar,
|
||||||
progress_bar_info.x_slot.get()?,
|
progress_bar_info.x_slot.get()?,
|
||||||
progress_bar_info.y_slot.get()?,
|
progress_bar_info.y_slot.get()?,
|
||||||
|
@ -322,7 +332,7 @@ impl GuiSnippet {
|
||||||
GuiBuilder::insert_id(ids, &grid_info.id, &sub_grid)?;
|
GuiBuilder::insert_id(ids, &grid_info.id, &sub_grid)?;
|
||||||
|
|
||||||
grid.attach(
|
grid.attach(
|
||||||
gui_handler,
|
world,
|
||||||
sub_grid.clone(),
|
sub_grid.clone(),
|
||||||
grid_info.x_slot.get()?,
|
grid_info.x_slot.get()?,
|
||||||
grid_info.y_slot.get()?,
|
grid_info.y_slot.get()?,
|
||||||
|
@ -331,7 +341,7 @@ impl GuiSnippet {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for child in grid_info.children.read().unwrap().iter() {
|
for child in grid_info.children.read().unwrap().iter() {
|
||||||
Self::create_child(gui_handler, child, &sub_grid, ids, neighbour_infos)?;
|
Self::create_child(world, gui_handler, child, &sub_grid, ids, neighbour_infos)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,8 +448,10 @@ impl Visibility for Button {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible.load(SeqCst) {
|
if visibility != self.visible.load(SeqCst) {
|
||||||
|
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -4,7 +4,6 @@ use anyhow::Result;
|
||||||
use ecs::World;
|
use ecs::World;
|
||||||
|
|
||||||
use super::ControllerButton;
|
use super::ControllerButton;
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
macro_rules! callbacks {
|
macro_rules! callbacks {
|
||||||
($name:ident, $($cb:tt)*) => {
|
($name:ident, $($cb:tt)*) => {
|
||||||
|
@ -28,12 +27,12 @@ macro_rules! callbacks {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks!(ClickCallbacks, Fn(&mut World, &mut GuiHandler) -> Result<()> + Send + Sync);
|
callbacks!(ClickCallbacks, Fn(&mut World) -> Result<()> + Send + Sync);
|
||||||
callbacks!(SelectCallbacks, Fn(&mut World, &mut GuiHandler, bool) -> anyhow::Result<()> + Send + Sync);
|
callbacks!(SelectCallbacks, Fn(&mut World, bool) -> anyhow::Result<()> + Send + Sync);
|
||||||
callbacks!(CustomCallbacks, Fn(&mut World, &mut GuiHandler, ControllerButton) -> anyhow::Result<bool> + Send + Sync);
|
callbacks!(CustomCallbacks, Fn(&mut World, ControllerButton) -> anyhow::Result<bool> + Send + Sync);
|
||||||
callbacks!(
|
callbacks!(
|
||||||
VecCallbacks,
|
VecCallbacks,
|
||||||
Fn(&mut World, &mut GuiHandler, &dyn Any) -> Result<()> + Send + Sync
|
Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -41,8 +40,8 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
fn normal_fn() -> impl Fn(&mut World, &mut GuiHandler) -> Result<()> + Send + Sync {
|
fn normal_fn() -> impl Fn(&mut World) -> Result<()> + Send + Sync {
|
||||||
|_, _| Ok(())
|
|_| Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -52,10 +51,7 @@ mod test {
|
||||||
impl Test {
|
impl Test {
|
||||||
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 World, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
|
||||||
)>,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use ecs::World;
|
||||||
|
|
||||||
use crate::builder::validator::gridinfo::GridInfo;
|
use crate::builder::validator::gridinfo::GridInfo;
|
||||||
|
|
||||||
|
@ -199,7 +200,7 @@ impl Grid {
|
||||||
|
|
||||||
pub fn detach(
|
pub fn detach(
|
||||||
&self,
|
&self,
|
||||||
gui_handler: &mut GuiHandler,
|
world: &mut World,
|
||||||
pos_x: usize,
|
pos_x: usize,
|
||||||
pos_y: usize,
|
pos_y: usize,
|
||||||
) -> Result<Option<Arc<dyn GuiElementTraits>>> {
|
) -> Result<Option<Arc<dyn GuiElementTraits>>> {
|
||||||
|
@ -231,7 +232,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(gui_handler, false)?;
|
child_visibility.set_visibility(world, false)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,11 +243,7 @@ impl Grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if item got detached
|
/// Returns `true` if item got detached
|
||||||
pub fn detach_item(
|
pub fn detach_item(&self, world: &mut World, item: Arc<dyn GuiElementTraits>) -> Result<bool> {
|
||||||
&self,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
item: Arc<dyn GuiElementTraits>,
|
|
||||||
) -> Result<bool> {
|
|
||||||
let mut grid = self.children.write().unwrap();
|
let mut grid = self.children.write().unwrap();
|
||||||
let mut removed = false;
|
let mut removed = false;
|
||||||
|
|
||||||
|
@ -265,7 +262,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(gui_handler, false)?;
|
child_visibility.set_visibility(world, false)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,7 +405,7 @@ impl Grid {
|
||||||
|
|
||||||
pub fn attach(
|
pub fn attach(
|
||||||
&self,
|
&self,
|
||||||
gui_handler: &mut GuiHandler,
|
world: &mut World,
|
||||||
child: Arc<dyn GuiElementTraits>,
|
child: Arc<dyn GuiElementTraits>,
|
||||||
pos_x: usize,
|
pos_x: usize,
|
||||||
pos_y: usize,
|
pos_y: usize,
|
||||||
|
@ -447,7 +444,14 @@ impl Grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.framable.is_framed() {
|
if self.framable.is_framed() {
|
||||||
self.child_position(gui_handler, child_gridable, pos_x, pos_y, dim_x, dim_y)?;
|
self.child_position(
|
||||||
|
world.resources.get_mut::<GuiHandler>(),
|
||||||
|
child_gridable,
|
||||||
|
pos_x,
|
||||||
|
pos_y,
|
||||||
|
dim_x,
|
||||||
|
dim_y,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
child_gridable.set_layer(self.framable.ui_layer())?;
|
child_gridable.set_layer(self.framable.ui_layer())?;
|
||||||
|
@ -458,7 +462,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(gui_handler, false)?;
|
child_visibility.set_visibility(world, false)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,7 +472,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(gui_handler, true)?;
|
child_visibility.set_visibility(world, true)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,26 +626,26 @@ impl Grid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable_tree(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable_tree(&self, world: &mut World, 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(gui_handler, false)?;
|
self.set_tree_visibility(world, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tree_visibility(&self, gui_handler: &mut GuiHandler, visible: bool) -> Result<()> {
|
fn set_tree_visibility(&self, world: &mut World, 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(gui_handler, visible)?;
|
visibility.set_visibility(world, visible)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -793,8 +797,10 @@ impl Visibility for Grid {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible.load(SeqCst) {
|
if visibility != self.visible.load(SeqCst) {
|
||||||
|
let gui_handler = world.resources.get_mut_unchecked::<GuiHandler>();
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
@ -804,9 +810,9 @@ impl Visibility for Grid {
|
||||||
background.enable(gui_handler)?;
|
background.enable(gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_tree_visibility(gui_handler, true)?;
|
self.set_tree_visibility(world, true)?;
|
||||||
} else {
|
} else {
|
||||||
self.disable_tree(gui_handler)?;
|
self.disable_tree(world, gui_handler)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assetpath::AssetPath;
|
use assetpath::AssetPath;
|
||||||
|
use ecs::World;
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
use vulkan_rs::prelude::*;
|
use vulkan_rs::prelude::*;
|
||||||
|
|
||||||
|
@ -280,8 +281,10 @@ impl Visibility for Icon {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible.load(SeqCst) {
|
if visibility != self.visible.load(SeqCst) {
|
||||||
|
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -8,6 +8,7 @@ use super::{
|
||||||
wrapper::{IconizableWrapper, TextableWrapper},
|
wrapper::{IconizableWrapper, TextableWrapper},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use ecs::World;
|
||||||
use vulkan_rs::prelude::*;
|
use vulkan_rs::prelude::*;
|
||||||
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
|
@ -229,8 +230,10 @@ impl Visibility for Label {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::sync::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use ecs::World;
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
|
|
||||||
pub struct MultiLineLabelBuilder {
|
pub struct MultiLineLabelBuilder {
|
||||||
|
@ -56,7 +57,11 @@ impl MultiLineLabelBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineLabel>> {
|
pub fn build(
|
||||||
|
self,
|
||||||
|
world: &mut World,
|
||||||
|
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);
|
||||||
|
@ -72,7 +77,7 @@ impl MultiLineLabelBuilder {
|
||||||
.set_text_alignment(self.text_alignment)
|
.set_text_alignment(self.text_alignment)
|
||||||
.build(gui_handler)?;
|
.build(gui_handler)?;
|
||||||
|
|
||||||
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
|
base_grid.attach(world, label, 0, i as usize, 1, 1)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Arc::new(MultiLineLabel {
|
Ok(Arc::new(MultiLineLabel {
|
||||||
|
@ -184,6 +189,7 @@ impl MultiLineLabel {
|
||||||
|
|
||||||
pub fn try_from(
|
pub fn try_from(
|
||||||
multi_line_label_info: &MultiLineLabelInfo,
|
multi_line_label_info: &MultiLineLabelInfo,
|
||||||
|
world: &mut World,
|
||||||
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();
|
||||||
|
@ -212,7 +218,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(gui_handler)
|
multi_line_label_builder.build(world, gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
||||||
|
@ -250,8 +256,8 @@ impl Visibility for MultiLineLabel {
|
||||||
self.grid.visible()
|
self.grid.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
self.grid.set_visibility(gui_handler, visibility)
|
self.grid.set_visibility(world, visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,11 @@ impl MultiLineTextFieldBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineTextField>> {
|
pub fn build(
|
||||||
|
self,
|
||||||
|
world: &mut World,
|
||||||
|
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);
|
||||||
|
@ -79,7 +83,7 @@ impl MultiLineTextFieldBuilder {
|
||||||
.set_text_alignment(self.text_alignment)
|
.set_text_alignment(self.text_alignment)
|
||||||
.build(gui_handler)?;
|
.build(gui_handler)?;
|
||||||
|
|
||||||
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
|
base_grid.attach(world, label, 0, i as usize, 1, 1)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = Arc::new(SplittedText::new(self.text));
|
let text = Arc::new(SplittedText::new(self.text));
|
||||||
|
@ -305,6 +309,7 @@ impl MultiLineTextField {
|
||||||
|
|
||||||
pub fn try_from(
|
pub fn try_from(
|
||||||
multi_line_text_field_info: &MultiLineTextFieldInfo,
|
multi_line_text_field_info: &MultiLineTextFieldInfo,
|
||||||
|
world: &mut World,
|
||||||
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();
|
||||||
|
@ -333,7 +338,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(gui_handler)
|
multi_line_text_field_builder.build(world, gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
||||||
|
@ -371,8 +376,10 @@ impl Visibility for MultiLineTextField {
|
||||||
self.grid.visible()
|
self.grid.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
self.writeable.add(gui_handler)?;
|
self.writeable.add(gui_handler)?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -380,7 +387,7 @@ impl Visibility for MultiLineTextField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.grid.set_visibility(gui_handler, visibility)
|
self.grid.set_visibility(world, visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +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::World;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
atomic::{AtomicBool, Ordering::SeqCst},
|
atomic::{AtomicBool, Ordering::SeqCst},
|
||||||
|
@ -278,8 +279,10 @@ impl Visibility for ProgressBar {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||||
|
|
||||||
self.visible.store(visibility, SeqCst);
|
self.visible.store(visibility, SeqCst);
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
|
|
|
@ -311,8 +311,10 @@ impl Visibility for TextField {
|
||||||
self.visible.load(SeqCst)
|
self.visible.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()> {
|
||||||
if visibility != self.visible() {
|
if visibility != self.visible() {
|
||||||
|
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||||
|
|
||||||
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, gui_handler: &mut GuiHandler) -> Result<()>;
|
fn enable(&self, world: &mut World) -> Result<()>;
|
||||||
fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()>;
|
fn disable(&self, world: &mut World) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_to<T>(any: &dyn Any) -> Result<&T>
|
pub fn any_to<T>(any: &dyn Any) -> Result<&T>
|
||||||
|
@ -84,7 +84,7 @@ pub trait Gridable {
|
||||||
|
|
||||||
pub trait Visibility {
|
pub trait Visibility {
|
||||||
fn visible(&self) -> bool;
|
fn visible(&self) -> bool;
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()>;
|
fn set_visibility(&self, world: &mut World, visibility: bool) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum GuiElement<'a> {
|
pub enum GuiElement<'a> {
|
||||||
|
|
|
@ -34,9 +34,9 @@ pub struct Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keyboard {
|
impl Keyboard {
|
||||||
pub fn new(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(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")?;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ impl Keyboard {
|
||||||
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(
|
||||||
gui_handler,
|
world,
|
||||||
text_field.clone(),
|
text_field.clone(),
|
||||||
&mode,
|
&mode,
|
||||||
decline_callback.clone(),
|
decline_callback.clone(),
|
||||||
|
@ -83,7 +83,7 @@ impl Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
gui_handler: &mut GuiHandler,
|
world: &mut World,
|
||||||
textfield: Arc<TextField>,
|
textfield: Arc<TextField>,
|
||||||
mode: &Arc<RwLock<KeyboardMode>>,
|
mode: &Arc<RwLock<KeyboardMode>>,
|
||||||
decline_callback: Arc<RwLock<Option<Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>>>>,
|
decline_callback: Arc<RwLock<Option<Box<dyn Fn(&mut World) -> Result<()> + Send + Sync>>>>,
|
||||||
|
@ -91,9 +91,9 @@ impl Keyboard {
|
||||||
RwLock<Option<Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>>>,
|
RwLock<Option<Box<dyn Fn(&mut World, &dyn Any) -> Result<()> + Send + Sync>>>,
|
||||||
>,
|
>,
|
||||||
) -> Result<(Arc<GuiBuilder>, Arc<GuiBuilder>, Arc<GuiBuilder>)> {
|
) -> Result<(Arc<GuiBuilder>, Arc<GuiBuilder>, Arc<GuiBuilder>)> {
|
||||||
let lower_case = GuiBuilder::from_str(gui_handler, include_str!("lower_case.xml"))?;
|
let lower_case = GuiBuilder::from_str(world, include_str!("lower_case.xml"))?;
|
||||||
let upper_case = GuiBuilder::from_str(gui_handler, include_str!("upper_case.xml"))?;
|
let upper_case = GuiBuilder::from_str(world, include_str!("upper_case.xml"))?;
|
||||||
let specials = GuiBuilder::from_str(gui_handler, include_str!("specials.xml"))?;
|
let specials = GuiBuilder::from_str(world, 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())?;
|
||||||
|
@ -235,10 +235,8 @@ impl Keyboard {
|
||||||
if let KeyboardMode::LowerCase = mode.deref() {
|
if let KeyboardMode::LowerCase = mode.deref() {
|
||||||
*mode = KeyboardMode::UpperCase;
|
*mode = KeyboardMode::UpperCase;
|
||||||
|
|
||||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
lower.disable(world)?;
|
||||||
|
upper.enable(world)?;
|
||||||
lower.disable(gui_handler)?;
|
|
||||||
upper.enable(gui_handler)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,10 +258,8 @@ impl Keyboard {
|
||||||
if let KeyboardMode::UpperCase = mode.deref() {
|
if let KeyboardMode::UpperCase = mode.deref() {
|
||||||
*mode = KeyboardMode::Specials;
|
*mode = KeyboardMode::Specials;
|
||||||
|
|
||||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
upper.disable(world)?;
|
||||||
|
specials.enable(world)?;
|
||||||
upper.disable(gui_handler)?;
|
|
||||||
specials.enable(gui_handler)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,10 +281,8 @@ impl Keyboard {
|
||||||
if let KeyboardMode::Specials = mode.deref() {
|
if let KeyboardMode::Specials = mode.deref() {
|
||||||
*mode = KeyboardMode::LowerCase;
|
*mode = KeyboardMode::LowerCase;
|
||||||
|
|
||||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
specials.disable(world)?;
|
||||||
|
lower.enable(world)?;
|
||||||
specials.disable(gui_handler)?;
|
|
||||||
lower.enable(gui_handler)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,7 +388,7 @@ impl Visibility for Keyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
fn set_visibility(&self, world: &mut World, 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() {
|
||||||
|
@ -404,11 +398,11 @@ impl Visibility for Keyboard {
|
||||||
};
|
};
|
||||||
|
|
||||||
if visibility {
|
if visibility {
|
||||||
gui.enable(gui_handler)?;
|
gui.enable(world)?;
|
||||||
self.text_field_gui.enable(gui_handler)?;
|
self.text_field_gui.enable(world)?;
|
||||||
} else {
|
} else {
|
||||||
gui.disable(gui_handler)?;
|
gui.disable(world)?;
|
||||||
self.text_field_gui.disable(gui_handler)?;
|
self.text_field_gui.disable(world)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -446,15 +440,16 @@ impl TopLevelGui for Keyboard {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn enable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(gui_handler, true)?;
|
self.set_visibility(world, true)?;
|
||||||
self.text_field.focus_input(gui_handler)?;
|
self.text_field
|
||||||
|
.focus_input(world.resources.get_mut::<GuiHandler>())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn disable(&self, world: &mut World) -> Result<()> {
|
||||||
self.set_visibility(gui_handler, false)?;
|
self.set_visibility(world, false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,14 +261,12 @@ impl States {
|
||||||
/// Adds a single state
|
/// Adds a single state
|
||||||
pub fn add_state<'a>(
|
pub fn add_state<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
gui_handler: &mut GuiHandler,
|
world: &mut World,
|
||||||
id: &str,
|
id: &str,
|
||||||
creation_type: impl Into<CreationType<'a>>,
|
creation_type: impl Into<CreationType<'a>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.states.insert(
|
self.states
|
||||||
id.to_string(),
|
.insert(id.to_string(), State::new(world, id, creation_type.into())?);
|
||||||
State::new(gui_handler, id, creation_type.into())?,
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -314,13 +312,13 @@ impl States {
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute deactivate on old state
|
// execute deactivate on old state
|
||||||
old_state.deactivate(world, gui_handler)?;
|
old_state.deactivate(world)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.activate(world, gui_handler)?;
|
state.activate(world)?;
|
||||||
gui_handler.set_top_gui(Some(state.clone()));
|
gui_handler.set_top_gui(Some(state.clone()));
|
||||||
|
|
||||||
if logging {
|
if logging {
|
||||||
|
@ -387,12 +385,12 @@ impl States {
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
fn new<'a>(
|
fn new<'a>(
|
||||||
gui_handler: &mut GuiHandler,
|
world: &mut World,
|
||||||
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(gui_handler, path)?,
|
CreationType::File(path) => GuiBuilder::new(world, path)?,
|
||||||
CreationType::TopGui(top_gui) => top_gui,
|
CreationType::TopGui(top_gui) => top_gui,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -445,8 +443,8 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(&self, world: &mut World, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn activate(&self, world: &mut World) -> Result<()> {
|
||||||
self.top_level_gui.enable(gui_handler)?;
|
self.top_level_gui.enable(world)?;
|
||||||
|
|
||||||
if let Some(activate) = self.on_activate.read().unwrap().as_ref() {
|
if let Some(activate) = self.on_activate.read().unwrap().as_ref() {
|
||||||
(activate)(world)?;
|
(activate)(world)?;
|
||||||
|
@ -455,8 +453,8 @@ impl State {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deactivate(&self, world: &mut World, gui_handler: &mut GuiHandler) -> Result<()> {
|
fn deactivate(&self, world: &mut World) -> Result<()> {
|
||||||
self.top_level_gui.disable(gui_handler)?;
|
self.top_level_gui.disable(world)?;
|
||||||
|
|
||||||
if let Some(deactivate) = self.on_deactivate.read().unwrap().as_ref() {
|
if let Some(deactivate) = self.on_deactivate.read().unwrap().as_ref() {
|
||||||
(deactivate)(world)?;
|
(deactivate)(world)?;
|
||||||
|
|
Loading…
Reference in a new issue