Compare commits

..

1 commit

Author SHA1 Message Date
c5286a3340 Update Rust crate quick-xml to 0.37.0
Some checks failed
Gavania Merge Build / build (pull_request) Failing after 2m21s
2025-03-04 09:05:37 +00:00
25 changed files with 661 additions and 752 deletions

View file

@ -116,26 +116,24 @@ impl ButtonBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<Button>> {
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
pub fn build(self, gui_handler: Arc<GuiHandler<'_>>) -> Result<Arc<Button<'_>>> {
let framable = Framable::new(gui_handler.clone(), false)?;
let normal = FillType::new(
gui_handler,
framable.clone(),
self.normal
.ok_or(anyhow!("normal button layout not set!"))?,
)?;
let selected = FillType::new(
gui_handler,
framable.clone(),
self.selected
.ok_or(anyhow!("selected button layout not set!"))?,
)?;
let click_executable = Executable::new();
let select_executable = Executable::new();
let on_select_executable = Executable::new();
let click_executable = Executable::new(&gui_handler);
let select_executable = Executable::new(&gui_handler);
let on_select_executable = Executable::new(&gui_handler);
#[cfg(feature = "audio")]
let click_sound = self
@ -152,6 +150,7 @@ impl ButtonBuilder {
let clickable = Clickable::new(framable.clone(), click_executable.clone());
let selectable = Selectable::new(
&gui_handler,
click_executable.clone(),
select_executable.clone(),
on_select_executable.clone(),
@ -184,11 +183,10 @@ impl ButtonBuilder {
);
if !self.text.is_empty() {
textable.set_text(gui_handler, &self.text, false)?;
textable.set_text(&self.text, false)?;
}
let iconizable = IconizableWrapper::new(
gui_handler,
framable.clone(),
self.icon.map(IconBuilderType::Image),
None,
@ -196,7 +194,6 @@ impl ButtonBuilder {
)?;
let info_icon = IconizableWrapper::new(
gui_handler,
framable.clone(),
None,
Some(IconizablePositioning {
@ -256,10 +253,10 @@ pub enum ButtonSelectMode {
Bigger,
}
pub struct Button {
pub struct Button<'a> {
clickable: Arc<Clickable>,
hoverable: Arc<Hoverable>,
selectable: Arc<Selectable>,
selectable: Arc<Selectable<'a>>,
framable: Arc<Framable>,
iconizable: IconizableWrapper,
textable: TextableWrapper,
@ -283,7 +280,7 @@ pub struct Button {
visible: AtomicBool,
}
impl Button {
impl<'a> Button<'a> {
pub fn builder() -> ButtonBuilder {
ButtonBuilder {
icon: None,
@ -308,23 +305,22 @@ impl Button {
}
}
pub fn select(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.selectable.select(gui_handler)
pub fn select(&self) -> Result<()> {
self.selectable.select()
}
pub fn set_callback<F>(&self, callback: F)
where
F: Fn() -> Result<()> + Send + Sync + 'static,
{
self.click_executable.set_callback(move |_, _| callback());
self.click_executable.set_callback(move |_| callback());
}
pub fn set_select_callback<F>(&self, callback: F)
where
F: Fn(bool) -> Result<()> + Send + Sync + 'static,
{
self.on_select_executable
.set_callback(|_m, select| callback(select));
self.on_select_executable.set_callback(callback);
}
pub fn set_custom_callback<F>(&self, callback: F)
@ -334,43 +330,46 @@ impl Button {
self.selectable.set_custom_callback(callback);
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
self.textable.set_text(gui_handler, text, self.visible())
pub fn set_text(&self, text: impl ToString) -> Result<()> {
self.textable.set_text(text, self.visible())
}
pub fn set_icon(&self, gui_handler: &mut GuiHandler, icon: &Arc<Image>) -> Result<()> {
self.iconizable.set_icon(gui_handler, icon, self.visible())
pub fn set_icon(&self, icon: &Arc<Image>) -> Result<()> {
self.iconizable.set_icon(icon, self.visible())
}
pub fn set_icon_margon(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> {
self.iconizable.set_margin(gui_handler, margin)
pub fn set_icon_margon(&self, margin: u32) -> Result<()> {
self.iconizable.set_margin(margin)
}
pub fn clear_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.iconizable.clear_icon(gui_handler, self.visible())
pub fn clear_icon(&self) -> Result<()> {
self.iconizable.clear_icon(self.visible())
}
pub fn icon(&self) -> Result<Option<Arc<Image>>> {
self.iconizable.icon()
}
pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(gui_handler, button, self.visible())
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(button, self.visible())
}
pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.info_icon.clear_icon(gui_handler, self.visible())
pub fn clear_info_icon(&self) -> Result<()> {
self.info_icon.clear_icon(self.visible())
}
pub fn text(&self) -> Result<Option<String>> {
self.textable.text()
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
self.textable.set_text_color(gui_handler, text_color)
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
self.textable.set_text_color(text_color)
}
pub fn try_from(gui_handler: &mut GuiHandler, button_info: &ButtonInfo) -> Result<Arc<Self>> {
pub fn try_from(
button_info: &ButtonInfo,
gui_handler: &Arc<GuiHandler<'a>>,
) -> Result<Arc<Self>> {
let mut button_builder = Button::builder()
.set_select_mode(button_info.select_mode)
.set_isolate(button_info.isolate);
@ -421,13 +420,13 @@ impl Button {
button_info.margin,
);
let button = button_builder.build(gui_handler)?;
let button = button_builder.build(gui_handler.clone())?;
Ok(button)
}
}
impl GuiElementTraits for Button {
impl<'a> GuiElementTraits for Button<'a> {
fn gridable(&self) -> Option<&dyn Gridable> {
Some(self)
}
@ -436,36 +435,36 @@ impl GuiElementTraits for Button {
Some(self)
}
fn downcast<'a>(&'a self) -> Option<GuiElement<'a>> {
fn downcast<'b>(&'b self) -> Option<GuiElement<'b>> {
Some(GuiElement::Button(self))
}
}
impl Visibility for Button {
impl<'a> Visibility for Button<'a> {
fn visible(&self) -> bool {
self.visible.load(SeqCst)
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible.load(SeqCst) {
self.visible.store(visibility, SeqCst);
if visibility {
self.framable.add(gui_handler)?;
self.selectable.add(gui_handler)?;
self.hoverable.add(gui_handler)?;
self.clickable.add(gui_handler)?;
self.framable.add()?;
self.selectable.add()?;
self.hoverable.add()?;
self.clickable.add()?;
self.textable.enable(gui_handler)?;
self.iconizable.enable(gui_handler)?;
self.info_icon.enable(gui_handler)?;
self.textable.enable()?;
self.iconizable.enable()?;
self.info_icon.enable()?;
match *self.button_state.lock().unwrap() {
ButtonState::Normal => self.normal.enable(gui_handler)?,
ButtonState::Selected => self.selected.enable(gui_handler)?,
ButtonState::Normal => self.normal.enable()?,
ButtonState::Selected => self.selected.enable()?,
}
} else {
self.disable_base(gui_handler)?;
self.disable_base()?;
}
}
@ -473,10 +472,9 @@ impl Visibility for Button {
}
}
impl Gridable for Button {
impl<'a> Gridable for Button<'a> {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -484,23 +482,22 @@ impl Gridable for Button {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.framable
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
self.normal.update_frame(gui_handler)?;
self.selected.update_frame(gui_handler)?;
self.textable.update(gui_handler)?;
self.iconizable.update_frame(gui_handler)?;
self.info_icon.update_frame(gui_handler)?;
self.normal.update_frame()?;
self.selected.update_frame()?;
self.textable.update()?;
self.iconizable.update_frame()?;
self.info_icon.update_frame()?;
if self.select_mode == ButtonSelectMode::Bigger {
self.modify_hovered_vbo(gui_handler)?;
self.modify_hovered_vbo()?;
}
Ok(())
}
fn selectable(&self) -> Option<&Arc<Selectable>> {
fn selectable(&self) -> Option<&Arc<Selectable<'_>>> {
Some(&self.selectable)
}
@ -528,8 +525,16 @@ impl Gridable for Button {
}
}
impl<'a> Drop for Button<'a> {
fn drop(&mut self) {
if self.visible.load(SeqCst) {
self.disable_base().unwrap();
}
}
}
// private
impl Button {
impl<'a> Button<'a> {
// fn create_hovered_changed_callback(button: Arc<Button>) -> Result<()> {
// let button_weak = Arc::downgrade(&button);
@ -552,13 +557,13 @@ impl Button {
// .set_hovered_changed_callback(Some(hovered_changed))
// }
fn create_clicked_changed_callback(button: Arc<Button>) {
fn create_clicked_changed_callback(button: Arc<Button<'a>>) {
let button_weak = Arc::downgrade(&button);
let clicked_changed = Box::new(move |gui_handler| {
let clicked_changed = Box::new(move || {
if let Some(button) = button_weak.upgrade() {
if button.clickable.clicked() {
button.hoverable.set_hovered(gui_handler, false)?;
button.hoverable.set_hovered(false)?;
} else {
// if let Some(displayable) = displayable_weak.upgrade() {
// displayable.update_frame()?;
@ -574,15 +579,15 @@ impl Button {
.set_clicked_changed_callback(Some(clicked_changed));
}
fn create_selected_changed_callback(button: Arc<Button>) {
fn create_selected_changed_callback(button: Arc<Button<'a>>) {
let button_weak = Arc::downgrade(&button);
let selected_changed = move |(gui_handler, selected)| {
let selected_changed = move |selected| {
if let Some(button) = button_weak.upgrade() {
if selected {
button.set_button_state(gui_handler, ButtonState::Selected)?;
button.set_button_state(ButtonState::Selected)?;
} else {
button.set_button_state(gui_handler, ButtonState::Normal)?;
button.set_button_state(ButtonState::Normal)?;
}
}
@ -592,7 +597,7 @@ impl Button {
button.select_executable.set_callback(selected_changed);
}
fn modify_hovered_vbo(&self, gui_handler: &GuiHandler) -> Result<()> {
fn modify_hovered_vbo(&self) -> Result<()> {
assert!(
self.framable.is_framed(),
"button frame needs to be defined before hovering can be calculated"
@ -605,7 +610,7 @@ impl Button {
let buffer = displayable.buffer();
let mut frame = buffer.map_complete()?;
let ortho = gui_handler.ortho();
let ortho = self.framable.ortho();
let left = self.framable.left() as f32;
let right = self.framable.right() as f32;
let top = self.framable.top() as f32;
@ -629,7 +634,7 @@ impl Button {
let buffer = colorable.buffer();
let mut frame = buffer.map_complete()?;
let ortho = gui_handler.ortho();
let ortho = self.framable.ortho();
let left = self.framable.left() as f32;
let right = self.framable.right() as f32;
let top = self.framable.top() as f32;
@ -647,29 +652,25 @@ impl Button {
Ok(())
}
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.delete(gui_handler)?;
fn disable_base(&self) -> Result<()> {
self.framable.delete()?;
self.selectable.delete(gui_handler)?;
self.hoverable.delete(gui_handler)?;
self.clickable.delete(gui_handler)?;
self.selectable.delete()?;
self.hoverable.delete()?;
self.clickable.delete()?;
self.textable.disable(gui_handler)?;
self.iconizable.disable(gui_handler)?;
self.info_icon.disable(gui_handler)?;
self.textable.disable()?;
self.iconizable.disable()?;
self.info_icon.disable()?;
self.normal.disable(gui_handler)?;
self.selected.disable(gui_handler)?;
self.normal.disable()?;
self.selected.disable()?;
Ok(())
}
#[inline]
fn set_button_state(
&self,
gui_handler: &mut GuiHandler,
button_state: ButtonState,
) -> Result<()> {
fn set_button_state(&self, button_state: ButtonState) -> Result<()> {
let mut current_button_state = self.button_state.lock().unwrap();
if button_state == *current_button_state {
@ -681,16 +682,16 @@ impl Button {
match button_state {
ButtonState::Normal => {
if self.visible() {
self.normal.enable(gui_handler)?;
self.normal.enable()?;
}
self.selected.disable(gui_handler)?;
self.selected.disable()?;
}
ButtonState::Selected => {
self.normal.disable(gui_handler)?;
self.normal.disable()?;
if self.visible() {
self.selected.enable(gui_handler)?;
self.selected.enable()?;
}
}
}
@ -699,8 +700,8 @@ impl Button {
}
}
impl Deref for Button {
type Target = Arc<Selectable>;
impl<'a> Deref for Button<'a> {
type Target = Arc<Selectable<'a>>;
fn deref(&self) -> &Self::Target {
&self.selectable

View file

@ -7,8 +7,8 @@ use assetpath::AssetPath;
use utilities::prelude::*;
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering::SeqCst},
Arc,
};
#[derive(Debug, Clone)]
@ -60,52 +60,44 @@ pub(crate) enum InnerFillType {
}
impl InnerFillType {
pub(crate) fn new(
gui_handler: &mut GuiHandler,
framable: Arc<Framable>,
fill_type_info: FillTypeInfo,
) -> Result<Self> {
pub(crate) fn new(framable: Arc<Framable>, fill_type_info: FillTypeInfo) -> Result<Self> {
match fill_type_info {
FillTypeInfo::Element(descriptor, fill_type) => Ok(InnerFillType::Image(
Displayable::new(gui_handler, framable, descriptor, fill_type)?,
Displayable::new(framable, descriptor, fill_type)?,
)),
FillTypeInfo::Image(path) => Ok(InnerFillType::Image(Displayable::new(
gui_handler,
framable,
path,
DisplayableFillType::Expand,
)?)),
FillTypeInfo::Color(color, fill_type) => Ok(InnerFillType::Color(Colorable::new(
gui_handler,
framable,
color,
fill_type,
framable, color, fill_type,
)?)),
}
}
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn enable(&self) -> Result<()> {
match self {
Self::Image(displayable) => displayable.add(gui_handler)?,
Self::Color(colorable) => colorable.add(gui_handler)?,
Self::Image(displayable) => displayable.add()?,
Self::Color(colorable) => colorable.add()?,
}
Ok(())
}
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn disable(&self) -> Result<()> {
match self {
Self::Image(displayable) => displayable.delete(gui_handler)?,
Self::Color(colorable) => colorable.delete(gui_handler)?,
Self::Image(displayable) => displayable.delete()?,
Self::Color(colorable) => colorable.delete()?,
}
Ok(())
}
pub(crate) fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn update_frame(&self) -> Result<()> {
match self {
Self::Image(displayable) => displayable.update_frame(gui_handler)?,
Self::Color(colorable) => colorable.update_frame(gui_handler)?,
Self::Image(displayable) => displayable.update_frame()?,
Self::Color(colorable) => colorable.update_frame()?,
}
Ok(())
@ -127,13 +119,9 @@ pub(crate) struct FillType {
}
impl FillType {
pub(crate) fn new(
gui_handler: &mut GuiHandler,
framable: Arc<Framable>,
fill_type_info: FillTypeInfo,
) -> Result<Self> {
pub(crate) fn new(framable: Arc<Framable>, fill_type_info: FillTypeInfo) -> Result<Self> {
let me = Self {
inner: InnerFillType::new(gui_handler, framable.clone(), fill_type_info)?,
inner: InnerFillType::new(framable.clone(), fill_type_info)?,
visible: AtomicBool::new(false),
};
@ -142,26 +130,26 @@ impl FillType {
Ok(me)
}
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn enable(&self) -> Result<()> {
if !self.visible.load(SeqCst) {
self.visible.store(true, SeqCst);
self.inner.enable(gui_handler)?;
self.inner.enable()?;
}
Ok(())
}
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn disable(&self) -> Result<()> {
if self.visible.load(SeqCst) {
self.visible.store(false, SeqCst);
self.inner.disable(gui_handler)?;
self.inner.disable()?;
}
Ok(())
}
pub(crate) fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.inner.update_frame(gui_handler)
pub(crate) fn update_frame(&self) -> Result<()> {
self.inner.update_frame()
}
pub(crate) fn set_ui_layer(&self, layer: i32) {
@ -195,3 +183,14 @@ impl PartialEq<FillTypeInfo> for FillType {
}
}
}
impl Drop for FillType {
fn drop(&mut self) {
if self.visible.load(SeqCst) {
match &self.inner {
InnerFillType::Image(displayable) => displayable.delete().unwrap(),
InnerFillType::Color(colorable) => colorable.delete().unwrap(),
}
}
}
}

View file

@ -4,8 +4,8 @@ use anyhow::Result;
use crate::builder::validator::gridinfo::GridInfo;
use std::sync::{
Arc, RwLock, RwLockReadGuard,
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
Arc, RwLock, RwLockReadGuard,
};
use std::{ops::Deref, sync::Weak};
@ -93,6 +93,8 @@ impl ChildState {
}
pub struct Grid {
gui_handler: Arc<GuiHandler>,
pub(crate) framable: Arc<Framable>,
background: RwLock<Option<FillType>>,
@ -109,13 +111,15 @@ pub struct Grid {
impl Grid {
pub fn new(
gui_handler: &GuiHandler,
gui_handler: Arc<GuiHandler>,
dim_x: usize,
dim_y: usize,
top_level: bool,
) -> Result<Arc<Self>> {
let grid = Arc::new(Grid {
framable: Framable::new(gui_handler.width(), gui_handler.height(), top_level)?,
gui_handler: gui_handler.clone(),
framable: Framable::new(gui_handler, top_level)?,
background: RwLock::new(None),
children: RwLock::new(vec![vec![ChildState::None; dim_y]; dim_x]),
@ -129,20 +133,20 @@ impl Grid {
visible: AtomicBool::new(false),
});
// if top_level {
// let weak_grid = Arc::downgrade(&grid);
if top_level {
let weak_grid = Arc::downgrade(&grid);
// grid.framable.add_callback(
// weak_grid.clone(),
// Box::new(move |gui_handler| {
// if let Some(grid) = weak_grid.upgrade() {
// grid.calculate_child_positions(gui_handler)?;
// }
grid.framable.add_callback(
weak_grid.clone(),
Box::new(move || {
if let Some(grid) = weak_grid.upgrade() {
grid.calculate_child_positions()?;
}
// Ok(())
// }),
// );
// }
Ok(())
}),
);
}
Ok(grid)
}
@ -151,18 +155,8 @@ impl Grid {
(self.dim_x, self.dim_y)
}
pub fn set_background(
&self,
gui_handler: &mut GuiHandler,
background: impl Into<FillTypeInfo>,
) -> Result<()> {
super::set_background(
gui_handler,
self.visible(),
&self.framable,
&self.background,
background,
)
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
super::set_background(self.visible(), &self.framable, &self.background, background)
}
pub(crate) fn background(&self) -> RwLockReadGuard<'_, Option<FillType>> {
@ -197,12 +191,7 @@ impl Grid {
Ok(self.children.read().unwrap()[x][y].map(|c| c.clone()))
}
pub fn detach(
&self,
gui_handler: &mut GuiHandler,
pos_x: usize,
pos_y: usize,
) -> Result<Option<Arc<dyn GuiElementTraits>>> {
pub fn detach(&self, pos_x: usize, pos_y: usize) -> Result<Option<Arc<dyn GuiElementTraits>>> {
if cfg!(debug_assertions) {
if pos_x >= self.dim_x as usize {
panic!(
@ -231,7 +220,7 @@ impl Grid {
Some((child, _x, _y)) => {
if self.visible() {
if let Some(child_visibility) = child.visibility() {
child_visibility.set_visibility(gui_handler, false)?;
child_visibility.set_visibility(false)?;
}
}
@ -242,11 +231,7 @@ impl Grid {
}
/// Returns `true` if item got detached
pub fn detach_item(
&self,
gui_handler: &mut GuiHandler,
item: Arc<dyn GuiElementTraits>,
) -> Result<bool> {
pub fn detach_item(&self, item: Arc<dyn GuiElementTraits>) -> Result<bool> {
let mut grid = self.children.write().unwrap();
let mut removed = false;
@ -265,7 +250,7 @@ impl Grid {
if self.visible() {
if let Some(child_visibility) = child.visibility() {
child_visibility.set_visibility(gui_handler, false)?;
child_visibility.set_visibility(false)?;
}
}
}
@ -288,20 +273,20 @@ impl Grid {
Ok(removed)
}
pub fn set_position(&self, gui_handler: &mut GuiHandler, x: i32, y: i32) -> Result<()> {
pub fn set_position(&self, x: i32, y: i32) -> Result<()> {
// update own position
self.framable.change_position(gui_handler, x, y)?;
self.framable.change_position(x, y)?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
self.calculate_child_positions(gui_handler)?;
self.calculate_child_positions()?;
Ok(())
}
fn calculate_child_positions(&self, gui_handler: &mut GuiHandler) -> Result<()> {
fn calculate_child_positions(&self) -> Result<()> {
// recalculate positions of the children
let children = self.children.read().unwrap();
@ -309,7 +294,7 @@ impl Grid {
for (y, child_opt) in row.iter().enumerate() {
if let Some((child, dim_x, dim_y)) = child_opt.get_some() {
if let Some(child_gridable) = child.gridable() {
self.child_position(gui_handler, child_gridable, x, y, dim_x, dim_y)?;
self.child_position(child_gridable, x, y, dim_x, dim_y)?;
}
}
}
@ -329,18 +314,18 @@ impl Grid {
(width, height)
}
pub fn disallow_position_scale(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.allow_position_scale(gui_handler, false)
pub fn disallow_position_scale(&self) -> Result<()> {
self.framable.allow_position_scale(false)
}
pub fn disallow_size_scale(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.allow_size_scale(gui_handler, false)
pub fn disallow_size_scale(&self) -> Result<()> {
self.framable.allow_size_scale(false)
}
pub fn connect(
pub fn connect<'a>(
&self,
direction: ConnectDirection,
elements: impl IntoIterator<Item = (usize, &Arc<Selectable>)>,
elements: impl IntoIterator<Item = (usize, &'a Arc<Selectable>)>,
) -> Result<()> {
for (index, selectable) in elements {
match direction {
@ -408,7 +393,6 @@ impl Grid {
pub fn attach(
&self,
gui_handler: &mut GuiHandler,
child: Arc<dyn GuiElementTraits>,
pos_x: usize,
pos_y: usize,
@ -447,7 +431,7 @@ impl Grid {
}
if self.framable.is_framed() {
self.child_position(gui_handler, child_gridable, pos_x, pos_y, dim_x, dim_y)?;
self.child_position(child_gridable, pos_x, pos_y, dim_x, dim_y)?;
}
child_gridable.set_layer(self.framable.ui_layer())?;
@ -458,7 +442,7 @@ impl Grid {
ChildState::Some { child, .. } => {
if self.visible() {
if let Some(child_visibility) = child.visibility() {
child_visibility.set_visibility(gui_handler, false)?;
child_visibility.set_visibility(false)?;
}
}
}
@ -468,7 +452,7 @@ impl Grid {
if self.visible() {
if let Some(child_visibility) = child.visibility() {
child_visibility.set_visibility(gui_handler, true)?;
child_visibility.set_visibility(true)?;
}
}
@ -500,11 +484,11 @@ impl Grid {
pub fn try_from(
grid_info: &GridInfo,
gui_handler: &mut GuiHandler,
gui_handler: &Arc<GuiHandler>,
top_level: bool,
) -> Result<Arc<Self>> {
let grid = Grid::new(
gui_handler,
gui_handler.clone(),
grid_info.x_dimension.get()?,
grid_info.y_dimension.get()?,
top_level,
@ -514,32 +498,26 @@ impl Grid {
grid.set_padding(grid_info.padding);
if let Some(background) = &grid_info.background_type {
grid.set_background(gui_handler, background.clone())?;
grid.set_background(background.clone())?;
}
Ok(grid)
}
pub fn change_position_unscaled(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
) -> Result<()> {
self.framable.change_position_unscaled(gui_handler, x, y)?;
pub fn change_position_unscaled(&self, x: i32, y: i32) -> Result<()> {
self.framable.change_position_unscaled(x, y)?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
self.calculate_child_positions(gui_handler)?;
self.calculate_child_positions()?;
Ok(())
}
fn child_position(
&self,
gui_handler: &mut GuiHandler,
child: &dyn Gridable,
pos_x: usize,
pos_y: usize,
@ -568,8 +546,8 @@ impl Grid {
single_height + (dim_y - 1) as i32 * (single_height + self.margin.load(SeqCst) as i32)
};
let win_width = gui_handler.width();
let win_height = gui_handler.height();
let win_width = self.gui_handler.width();
let win_height = self.gui_handler.height();
let y_align = match self.framable.vertical_alignment() {
VerticalAlign::Top => 0,
@ -593,7 +571,6 @@ impl Grid {
+ pos_y as i32 * (single_height + self.margin.load(SeqCst) as i32);
child.set_frame(
gui_handler,
child_x - x_align as i32,
child_y - y_align as i32,
child_width as u32,
@ -605,12 +582,12 @@ impl Grid {
Ok(())
}
pub fn select(&self, gui_handler: &mut GuiHandler, x: u32, y: u32) -> Result<()> {
pub fn select(&self, x: u32, y: u32) -> Result<()> {
match self.children.read().unwrap()[x as usize][y as usize].get_some() {
Some((child, ..)) => match child.gridable() {
Some(gridable) => match gridable.selectable() {
Some(selectable) => {
selectable.select(gui_handler)?;
selectable.select()?;
Ok(())
}
None => panic!("gridable at position ({}, {}), is not selectable", x, y),
@ -622,26 +599,26 @@ impl Grid {
}
}
fn disable_tree(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.delete(gui_handler)?;
fn disable_tree(&self) -> Result<()> {
self.framable.delete()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.disable(gui_handler)?;
background.disable()?;
}
self.set_tree_visibility(gui_handler, false)?;
self.set_tree_visibility(false)?;
Ok(())
}
fn set_tree_visibility(&self, gui_handler: &mut GuiHandler, visible: bool) -> Result<()> {
fn set_tree_visibility(&self, visible: bool) -> Result<()> {
let tree = self.children.read().unwrap();
for row in tree.deref() {
for child_state in row {
if let Some((child, ..)) = child_state.get_some() {
if let Some(visibility) = child.visibility() {
visibility.set_visibility(gui_handler, visible)?;
visibility.set_visibility(visible)?;
}
}
}
@ -793,20 +770,20 @@ impl Visibility for Grid {
self.visible.load(SeqCst)
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible.load(SeqCst) {
self.visible.store(visibility, SeqCst);
if visibility {
self.framable.add(gui_handler)?;
Framable::add(&self.framable)?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.enable(gui_handler)?;
background.enable()?;
}
self.set_tree_visibility(gui_handler, true)?;
self.set_tree_visibility(true)?;
} else {
self.disable_tree(gui_handler)?;
self.disable_tree()?;
}
}
@ -817,7 +794,6 @@ impl Visibility for Grid {
impl Gridable for Grid {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -825,14 +801,13 @@ impl Gridable for Grid {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.framable
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
self.calculate_child_positions(gui_handler)?;
self.calculate_child_positions()?;
Ok(())
}
@ -869,3 +844,11 @@ impl Gridable for Grid {
self.framable.position()
}
}
impl Drop for Grid {
fn drop(&mut self) {
if self.visible.load(SeqCst) {
self.disable_tree().unwrap();
}
}
}

View file

@ -8,14 +8,14 @@ use utilities::prelude::*;
use vulkan_rs::prelude::*;
use std::sync::{
Arc, RwLock,
atomic::{AtomicBool, Ordering::SeqCst},
Arc, RwLock,
};
use super::{
IconBuilderType,
fill_type::FillType,
wrapper::{IconizableWrapper, TextableWrapper},
IconBuilderType,
};
pub struct IconBuilder {
@ -65,20 +65,15 @@ impl IconBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<Icon>> {
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<Icon>> {
let framable = Framable::new(gui_handler, false)?;
let iconizable_wrapper = IconizableWrapper::new(
gui_handler,
framable.clone(),
self.content,
None,
self.margin,
)?;
let iconizable_wrapper =
IconizableWrapper::new(framable.clone(), self.content, None, self.margin)?;
let background = RwLock::new(
self.background
.map(|info| FillType::new(gui_handler, framable.clone(), info))
.map(|info| FillType::new(framable.clone(), info))
.transpose()?,
);
@ -90,11 +85,10 @@ impl IconBuilder {
);
if let Some(text) = self.text {
textable_wrapper.set_text(gui_handler, &text, false)?;
textable_wrapper.set_text(&text, false)?;
}
let info_icon = IconizableWrapper::new(
gui_handler,
framable.clone(),
None,
Some(IconizablePositioning {
@ -141,70 +135,51 @@ impl Icon {
}
}
pub fn clear_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.iconizable_wrapper
.clear_icon(gui_handler, self.visible())
pub fn clear_icon(&self) -> Result<()> {
self.iconizable_wrapper.clear_icon(self.visible())
}
pub fn set_icon(&self, gui_handler: &mut GuiHandler, icon: &Arc<Image>) -> Result<()> {
self.iconizable_wrapper
.set_icon(gui_handler, icon, self.visible())
pub fn set_icon(&self, icon: &Arc<Image>) -> Result<()> {
self.iconizable_wrapper.set_icon(icon, self.visible())
}
pub fn set_icon_from_path(
&self,
gui_handler: &mut GuiHandler,
asset_path: AssetPath,
) -> Result<()> {
self.iconizable_wrapper
.set_icon(gui_handler, asset_path, self.visible())
pub fn set_icon_from_path(&self, asset_path: AssetPath) -> Result<()> {
self.iconizable_wrapper.set_icon(asset_path, self.visible())
}
pub fn set_margin(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> {
self.iconizable_wrapper.set_margin(gui_handler, margin)
pub fn set_margin(&self, margin: u32) -> Result<()> {
self.iconizable_wrapper.set_margin(margin)
}
pub fn set_background(
&self,
gui_handler: &mut GuiHandler,
background: impl Into<FillTypeInfo>,
) -> Result<()> {
super::set_background(
gui_handler,
self.visible(),
&self.framable,
&self.background,
background,
)
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
super::set_background(self.visible(), &self.framable, &self.background, background)
}
pub fn clear_background(&self) {
*self.background.write().unwrap() = None;
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
self.textable_wrapper
.set_text(gui_handler, text, self.visible())
pub fn set_text(&self, text: impl ToString) -> Result<()> {
self.textable_wrapper.set_text(text, self.visible())
}
pub fn clear_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.textable_wrapper
.set_text(gui_handler, "", self.visible())
pub fn clear_text(&self) -> Result<()> {
self.textable_wrapper.set_text("", self.visible())
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, color: Color) -> Result<()> {
self.textable_wrapper.set_text_color(gui_handler, color)
pub fn set_text_color(&self, color: Color) -> Result<()> {
self.textable_wrapper.set_text_color(color)
}
pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(gui_handler, button, self.visible())
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(button, self.visible())
}
pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.info_icon.clear_icon(gui_handler, self.visible())
pub fn clear_info_icon(&self) -> Result<()> {
self.info_icon.clear_icon(self.visible())
}
pub fn try_from(icon_info: &IconInfo, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
pub fn try_from(icon_info: &IconInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
let mut icon_builder = Icon::builder().set_text_color(icon_info.text_color);
if let Some(text_ratio) = icon_info.text_ratio {
@ -232,7 +207,7 @@ impl Icon {
}
}
icon_builder.build(gui_handler)
icon_builder.build(gui_handler.clone())
}
pub fn icon(&self) -> Result<Option<Arc<Image>>> {
@ -246,15 +221,15 @@ impl Icon {
)
}
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.delete(gui_handler)?;
fn disable_base(&self) -> Result<()> {
self.framable.delete()?;
self.iconizable_wrapper.disable(gui_handler)?;
self.textable_wrapper.disable(gui_handler)?;
self.info_icon.disable(gui_handler)?;
self.iconizable_wrapper.disable()?;
self.textable_wrapper.disable()?;
self.info_icon.disable()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.disable(gui_handler)?;
background.disable()?;
}
Ok(())
@ -280,22 +255,22 @@ impl Visibility for Icon {
self.visible.load(SeqCst)
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible.load(SeqCst) {
self.visible.store(visibility, SeqCst);
if visibility {
self.framable.add(gui_handler)?;
self.framable.add()?;
self.info_icon.enable(gui_handler)?;
self.iconizable_wrapper.enable(gui_handler)?;
self.textable_wrapper.enable(gui_handler)?;
self.info_icon.enable()?;
self.iconizable_wrapper.enable()?;
self.textable_wrapper.enable()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.enable(gui_handler)?;
background.enable()?;
}
} else {
self.disable_base(gui_handler)?;
self.disable_base()?;
}
}
@ -306,7 +281,6 @@ impl Visibility for Icon {
impl Gridable for Icon {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -314,15 +288,14 @@ impl Gridable for Icon {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.framable
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
self.iconizable_wrapper.update_frame(gui_handler)?;
self.textable_wrapper.update(gui_handler)?;
self.info_icon.update_frame(gui_handler)?;
self.iconizable_wrapper.update_frame()?;
self.textable_wrapper.update()?;
self.info_icon.update_frame()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
Ok(())
@ -353,3 +326,11 @@ impl Gridable for Icon {
self.framable.position()
}
}
impl Drop for Icon {
fn drop(&mut self) {
if self.visible.load(SeqCst) {
self.disable_base().unwrap();
}
}
}

View file

@ -11,8 +11,8 @@ use super::{
use vulkan_rs::prelude::*;
use std::sync::{
Arc, RwLock,
atomic::{AtomicBool, Ordering::SeqCst},
Arc, RwLock,
};
use anyhow::Result;
@ -57,8 +57,8 @@ impl LabelBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<Label>> {
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<Label>> {
let framable = Framable::new(gui_handler, false)?;
let textable_wrapper = TextableWrapper::new(
framable.clone(),
@ -68,16 +68,15 @@ impl LabelBuilder {
);
if let Some(text) = &self.text {
textable_wrapper.set_text(gui_handler, text, false)?;
textable_wrapper.set_text(text, false)?;
}
let background = self
.background
.map(|info| FillType::new(gui_handler, framable.clone(), info))
.map(|info| FillType::new(framable.clone(), info))
.transpose()?;
let info_icon = IconizableWrapper::new(
gui_handler,
framable.clone(),
None,
Some(IconizablePositioning {
@ -121,59 +120,43 @@ impl Label {
}
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
self.textable_wrapper
.set_text(gui_handler, text, self.visible())
pub fn set_text(&self, text: impl ToString) -> Result<()> {
self.textable_wrapper.set_text(text, self.visible())
}
pub fn text(&self) -> Result<Option<String>> {
self.textable_wrapper.text()
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
self.textable_wrapper
.set_text_color(gui_handler, text_color)
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
self.textable_wrapper.set_text_color(text_color)
}
pub fn set_alignment(
&self,
gui_handler: &mut GuiHandler,
alignment: TextAlignment,
) -> Result<()> {
self.textable_wrapper.set_alignment(gui_handler, alignment)
pub fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
self.textable_wrapper.set_alignment(alignment)
}
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
self.textable_wrapper.set_height_ratio(gui_handler, ratio)
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
self.textable_wrapper.set_height_ratio(ratio)
}
pub fn text_ratio(&self) -> f32 {
self.textable_wrapper.height_ratio()
}
pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(gui_handler, button, self.visible())
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
self.info_icon.set_icon(button, self.visible())
}
pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.info_icon.clear_icon(gui_handler, self.visible())
pub fn clear_info_icon(&self) -> Result<()> {
self.info_icon.clear_icon(self.visible())
}
pub fn set_background(
&self,
gui_handler: &mut GuiHandler,
background: impl Into<FillTypeInfo>,
) -> Result<()> {
super::set_background(
gui_handler,
self.visible(),
&self.framable,
&self.background,
background,
)
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
super::set_background(self.visible(), &self.framable, &self.background, background)
}
pub fn try_from(label_info: &LabelInfo, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
pub fn try_from(label_info: &LabelInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
let text = label_info.text.read().unwrap().clone();
let color = label_info.text_color;
@ -193,17 +176,17 @@ impl Label {
label_builder = label_builder.set_text(text);
}
label_builder.build(gui_handler)
label_builder.build(gui_handler.clone())
}
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.delete(gui_handler)?;
fn disable_base(&self) -> Result<()> {
self.framable.delete()?;
self.textable_wrapper.disable(gui_handler)?;
self.info_icon.disable(gui_handler)?;
self.textable_wrapper.disable()?;
self.info_icon.disable()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.disable(gui_handler)?;
background.disable()?;
}
Ok(())
@ -229,21 +212,21 @@ impl Visibility for Label {
self.visible.load(SeqCst)
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible() {
self.visible.store(visibility, SeqCst);
if visibility {
self.framable.add(gui_handler)?;
self.framable.add()?;
self.textable_wrapper.enable(gui_handler)?;
self.info_icon.enable(gui_handler)?;
self.textable_wrapper.enable()?;
self.info_icon.enable()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.enable(gui_handler)?;
background.enable()?;
}
} else {
self.disable_base(gui_handler)?;
self.disable_base()?;
}
}
@ -254,7 +237,6 @@ impl Visibility for Label {
impl Gridable for Label {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -262,14 +244,13 @@ impl Gridable for Label {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.framable
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
self.textable_wrapper.update(gui_handler)?;
self.info_icon.update_frame(gui_handler)?;
self.textable_wrapper.update()?;
self.info_icon.update_frame()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
Ok(())
@ -299,3 +280,11 @@ impl Gridable for Label {
self.framable.position()
}
}
impl Drop for Label {
fn drop(&mut self) {
if self.visible.load(SeqCst) {
self.disable_base().unwrap();
}
}
}

View file

@ -22,7 +22,6 @@ pub mod prelude;
mod wrapper;
pub(crate) fn set_background(
gui_handler: &mut GuiHandler,
visible: bool,
framable: &Arc<Framable>,
current: &RwLock<Option<FillType>>,
@ -38,14 +37,14 @@ pub(crate) fn set_background(
};
if update {
let fill_type = FillType::new(gui_handler, framable.clone(), fill_info)?;
let fill_type = FillType::new(framable.clone(), fill_info)?;
if framable.is_framed() {
fill_type.update_frame(gui_handler)?;
fill_type.update_frame()?;
}
if visible {
fill_type.enable(gui_handler)?;
fill_type.enable()?;
}
*current_background = Some(fill_type);

View file

@ -1,8 +1,8 @@
use crate::{builder::validator::multi_line_labelinfo::MultiLineLabelInfo, prelude::*};
use std::sync::{
Arc, Mutex,
atomic::{AtomicU32, Ordering::SeqCst},
Arc, Mutex,
};
use anyhow::{Context, Result};
@ -56,13 +56,13 @@ impl MultiLineLabelBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineLabel>> {
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<MultiLineLabel>> {
let base_grid = Grid::new(gui_handler.clone(), 1, self.line_count as usize, false)?;
base_grid.set_margin(0);
base_grid.set_padding(0);
if let Some(background) = self.background {
base_grid.set_background(gui_handler, background)?;
base_grid.set_background(background)?;
}
for i in 0..self.line_count {
@ -70,9 +70,9 @@ impl MultiLineLabelBuilder {
.set_ratio(self.text_ratio)
.set_text_color(self.text_color)
.set_text_alignment(self.text_alignment)
.build(gui_handler)?;
.build(gui_handler.clone())?;
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
base_grid.attach(label, 0, i as usize, 1, 1)?;
}
Ok(Arc::new(MultiLineLabel {
@ -107,13 +107,13 @@ impl MultiLineLabel {
}
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
pub fn set_text(&self, text: impl ToString) -> Result<()> {
*self.text.lock().unwrap() = text.to_string();
self.update_text(gui_handler)
self.update_text()
}
fn update_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
fn update_text(&self) -> Result<()> {
let text = self.text.lock().unwrap();
let splits = text.split(' ');
let character_count = self.characters_per_line.load(SeqCst) as usize;
@ -145,9 +145,9 @@ impl MultiLineLabel {
self.iter_label(|label, y| {
if y < lines.len() {
label.set_text(gui_handler, &lines[y])?;
label.set_text(&lines[y])?;
} else {
label.set_text(gui_handler, "")?;
label.set_text("")?;
}
Ok(())
@ -158,33 +158,25 @@ impl MultiLineLabel {
self.text.lock().unwrap().clone()
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
self.iter_label(|label, _| label.set_text_color(gui_handler, text_color))
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
self.iter_label(|label, _| label.set_text_color(text_color))
}
pub fn set_alignment(
&self,
gui_handler: &mut GuiHandler,
alignment: TextAlignment,
) -> Result<()> {
self.iter_label(|label, _| label.set_alignment(gui_handler, alignment))
pub fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
self.iter_label(|label, _| label.set_alignment(alignment))
}
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
self.iter_label(|label, _| label.set_text_ratio(gui_handler, ratio))
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
self.iter_label(|label, _| label.set_text_ratio(ratio))
}
pub fn set_background(
&self,
gui_handler: &mut GuiHandler,
background: impl Into<FillTypeInfo>,
) -> Result<()> {
self.grid.set_background(gui_handler, background)
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
self.grid.set_background(background)
}
pub fn try_from(
multi_line_label_info: &MultiLineLabelInfo,
gui_handler: &mut GuiHandler,
gui_handler: &Arc<GuiHandler>,
) -> Result<Arc<Self>> {
let text = multi_line_label_info.text.read().unwrap().clone();
let color = multi_line_label_info.text_color;
@ -212,12 +204,12 @@ impl MultiLineLabel {
multi_line_label_builder = multi_line_label_builder.set_text(text);
}
multi_line_label_builder.build(gui_handler)
multi_line_label_builder.build(gui_handler.clone())
}
fn iter_label<F>(&self, mut f: F) -> Result<()>
fn iter_label<F>(&self, f: F) -> Result<()>
where
F: FnMut(&Label, usize) -> Result<()>,
F: Fn(&Label, usize) -> Result<()>,
{
for y in 0..self.grid.dimensions().1 {
let child = self.grid.child_at(0, y)?.unwrap();
@ -250,15 +242,14 @@ impl Visibility for MultiLineLabel {
self.grid.visible()
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
self.grid.set_visibility(gui_handler, visibility)
fn set_visibility(&self, visibility: bool) -> Result<()> {
self.grid.set_visibility(visibility)
}
}
impl Gridable for MultiLineLabel {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -266,8 +257,7 @@ impl Gridable for MultiLineLabel {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.grid
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align)?;
self.grid.set_frame(x, y, w, h, vert_align, hori_align)?;
if let Some(child) = self.grid.child_at(0, 0)? {
let gui_element = child.downcast().unwrap();
@ -289,7 +279,7 @@ impl Gridable for MultiLineLabel {
self.characters_per_line
.store(max_letter_count as u32, SeqCst);
self.update_text(gui_handler)?;
self.update_text()?;
}
Ok(())

View file

@ -5,8 +5,8 @@ use crate::{
};
use std::sync::{
Arc, Mutex,
atomic::{AtomicU32, Ordering::SeqCst},
Arc, Mutex,
};
use anyhow::{Context, Result};
@ -62,13 +62,13 @@ impl MultiLineTextFieldBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineTextField>> {
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<MultiLineTextField>> {
let base_grid = Grid::new(gui_handler.clone(), 1, self.line_count as usize, false)?;
base_grid.set_margin(0);
base_grid.set_padding(0);
if let Some(background) = self.background {
base_grid.set_background(gui_handler, background)?;
base_grid.set_background(background)?;
}
for i in 0..self.line_count {
@ -76,14 +76,14 @@ impl MultiLineTextFieldBuilder {
.set_ratio(self.text_ratio)
.set_text_color(self.text_color)
.set_text_alignment(self.text_alignment)
.build(gui_handler)?;
.build(gui_handler.clone())?;
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
base_grid.attach(label, 0, i as usize, 1, 1)?;
}
let text = Arc::new(SplittedText::new(self.text));
let text_changed_exec = Executable::new();
let writeable = Writeable::new(text.clone(), text_changed_exec.clone())?;
let text_changed_exec = Executable::new(&gui_handler);
let writeable = Writeable::new(gui_handler, text.clone(), text_changed_exec.clone())?;
let multi_line_text_field = Arc::new(MultiLineTextField {
grid: base_grid,
@ -96,9 +96,9 @@ impl MultiLineTextFieldBuilder {
multi_line_text_field.text_changed_exec.set_callback({
let weak_tf = Arc::downgrade(&multi_line_text_field);
move |gui_handler: &mut GuiHandler, _text| {
move |_text| {
if let Some(tf) = weak_tf.upgrade() {
tf.update_text(gui_handler)?;
tf.update_text()?;
}
Ok(())
@ -173,13 +173,13 @@ impl SplittedText {
}
impl ModifyText for SplittedText {
fn set_text(&self, _gui_handler: &mut GuiHandler, text: String) -> Result<()> {
fn set_text(&self, text: String) -> Result<()> {
*self.text.lock().unwrap() = text;
self.update_text()
}
fn add_letter(&self, _gui_handler: &mut GuiHandler, letter: char) -> Result<String> {
fn add_letter(&self, letter: char) -> Result<String> {
*self.text.lock().unwrap() += &format!("{}", letter);
self.update_text()?;
@ -187,7 +187,7 @@ impl ModifyText for SplittedText {
Ok(self.text.lock().unwrap().clone())
}
fn remove_last(&self, _gui_handler: &mut GuiHandler) -> Result<Option<String>> {
fn remove_last(&self) -> Result<Option<String>> {
self.text.lock().unwrap().pop();
self.update_text()?;
@ -219,25 +219,25 @@ impl MultiLineTextField {
}
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
self.text.set_text(gui_handler, text.to_string())
pub fn set_text(&self, text: impl ToString) -> Result<()> {
self.text.set_text(text.to_string())
}
fn update_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
fn update_text(&self) -> Result<()> {
let lines = self.text.lines();
self.iter_label(|label, y| {
if y < lines.len() {
label.set_text(gui_handler, &lines[y])?;
label.set_text(&lines[y])?;
} else {
label.set_text(gui_handler, "")?;
label.set_text("")?;
}
Ok(())
})
}
fn update_color_change(self: &Arc<MultiLineTextField>) {
fn update_color_change(self: &Arc<Self>) {
if let Some(background) = &*self.grid.background() {
if let InnerFillType::Color(colorable) = &background.inner {
let normal_color = colorable.color();
@ -245,19 +245,14 @@ impl MultiLineTextField {
let weak_self = Arc::downgrade(self);
self.writeable
.set_activation_changed(move |gui_handler, active| {
self.writeable.set_activation_changed(move |active| {
if let Some(me) = weak_self.upgrade() {
if active {
me.grid.set_background(
gui_handler,
(focus_color, DisplayableFillType::Expand),
)?;
me.grid
.set_background((focus_color, DisplayableFillType::Expand))?;
} else {
me.grid.set_background(
gui_handler,
(normal_color, DisplayableFillType::Expand),
)?;
me.grid
.set_background((normal_color, DisplayableFillType::Expand))?;
}
}
@ -271,40 +266,32 @@ impl MultiLineTextField {
self.text.text()
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
self.iter_label(|label, _| label.set_text_color(gui_handler, text_color))
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
self.iter_label(|label, _| label.set_text_color(text_color))
}
pub fn set_alignment(
&self,
gui_handler: &mut GuiHandler,
alignment: TextAlignment,
) -> Result<()> {
self.iter_label(|label, _| label.set_alignment(gui_handler, alignment))
pub fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
self.iter_label(|label, _| label.set_alignment(alignment))
}
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
self.iter_label(|label, _| label.set_text_ratio(gui_handler, ratio))
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
self.iter_label(|label, _| label.set_text_ratio(ratio))
}
pub fn set_background(
self: &Arc<Self>,
gui_handler: &mut GuiHandler,
background: impl Into<FillTypeInfo>,
) -> Result<()> {
self.grid.set_background(gui_handler, background)?;
pub fn set_background(self: &Arc<Self>, background: impl Into<FillTypeInfo>) -> Result<()> {
self.grid.set_background(background)?;
self.update_color_change();
Ok(())
}
pub fn focus_input(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.writeable.set_active(gui_handler)
pub fn focus_input(&self) -> Result<()> {
self.writeable.set_active()
}
pub fn try_from(
multi_line_text_field_info: &MultiLineTextFieldInfo,
gui_handler: &mut GuiHandler,
gui_handler: &Arc<GuiHandler>,
) -> Result<Arc<Self>> {
let text = multi_line_text_field_info.text.read().unwrap().clone();
let color = multi_line_text_field_info.text_color;
@ -332,12 +319,12 @@ impl MultiLineTextField {
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(gui_handler.clone())
}
fn iter_label<F>(&self, mut f: F) -> Result<()>
fn iter_label<F>(&self, f: F) -> Result<()>
where
F: FnMut(&Label, usize) -> Result<()>,
F: Fn(&Label, usize) -> Result<()>,
{
for y in 0..self.grid.dimensions().1 {
let child = self.grid.child_at(0, y)?.unwrap();
@ -370,23 +357,22 @@ impl Visibility for MultiLineTextField {
self.grid.visible()
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible() {
if visibility {
self.writeable.add(gui_handler)?;
self.writeable.add()?;
} else {
self.writeable.delete(gui_handler)?;
self.writeable.delete()?;
}
}
self.grid.set_visibility(gui_handler, visibility)
self.grid.set_visibility(visibility)
}
}
impl Gridable for MultiLineTextField {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -394,8 +380,7 @@ impl Gridable for MultiLineTextField {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.grid
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align)?;
self.grid.set_frame(x, y, w, h, vert_align, hori_align)?;
if let Some(child) = self.grid.child_at(0, 0)? {
let gui_element = child.downcast().unwrap();
@ -416,7 +401,7 @@ impl Gridable for MultiLineTextField {
self.text.set_characters_per_line(max_letter_count as u32);
self.update_text(gui_handler)?;
self.update_text()?;
}
Ok(())
@ -439,3 +424,11 @@ impl Gridable for MultiLineTextField {
self.grid.position_extent()
}
}
impl Drop for MultiLineTextField {
fn drop(&mut self) {
if self.visible() {
self.writeable.delete().unwrap();
}
}
}

View file

@ -2,8 +2,8 @@ use crate::{builder::validator::progressbar_info::ProgressBarInfo, prelude::*};
use anyhow::Result;
use std::sync::{
Arc, Mutex,
atomic::{AtomicBool, Ordering::SeqCst},
Arc, Mutex,
};
use utilities::prelude::*;
@ -74,17 +74,17 @@ impl ProgressBarBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<ProgressBar>> {
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<ProgressBar>> {
let framable = Framable::new(gui_handler, false)?;
let background = self
.background
.map(|r#type| FillType::new(gui_handler, framable.clone(), r#type))
.map(|r#type| FillType::new(framable.clone(), r#type))
.transpose()?;
let foreground = self
.foreground
.map(|r#type| FillType::new(gui_handler, framable.clone(), r#type))
.map(|r#type| FillType::new(framable.clone(), r#type))
.transpose()?;
let textable_wrapper = TextableWrapper::new(
@ -95,7 +95,7 @@ impl ProgressBarBuilder {
);
if let Some(text) = self.text {
textable_wrapper.set_text(gui_handler, &text, false)?;
textable_wrapper.set_text(&text, false)?;
}
Ok(Arc::new(ProgressBar {
@ -140,7 +140,7 @@ impl ProgressBar {
}
}
pub fn set_progress(&self, gui_handler: &mut GuiHandler, mut progress: f32) -> Result<()> {
pub fn set_progress(&self, mut progress: f32) -> Result<()> {
if progress < 0.0 {
progress = 0.0;
} else if progress > 1.0 {
@ -156,22 +156,22 @@ impl ProgressBar {
InnerFillType::Image(displayable) => {
displayable.set_right_factor(progress);
displayable.set_right_uv_factor(progress);
displayable.update_frame(gui_handler)?;
displayable.update_frame()?;
}
InnerFillType::Color(colorable) => {
colorable.set_right_factor(progress);
colorable.update_frame(gui_handler)?;
colorable.update_frame()?;
}
},
GrowDirection::BottomToTop => match &foreground.inner {
InnerFillType::Image(displayable) => {
displayable.set_top_factor(progress);
displayable.set_top_uv_factor(progress);
displayable.update_frame(gui_handler)?;
displayable.update_frame()?;
}
InnerFillType::Color(colorable) => {
colorable.set_top_factor(progress);
colorable.update_frame(gui_handler)?;
colorable.update_frame()?;
}
},
}
@ -181,32 +181,25 @@ impl ProgressBar {
Ok(())
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
self.textable_wrapper
.set_text(gui_handler, text, self.visible())
pub fn set_text(&self, text: impl ToString) -> Result<()> {
self.textable_wrapper.set_text(text, self.visible())
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
self.textable_wrapper
.set_text_color(gui_handler, text_color)
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
self.textable_wrapper.set_text_color(text_color)
}
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
self.textable_wrapper.set_height_ratio(gui_handler, ratio)
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
self.textable_wrapper.set_height_ratio(ratio)
}
pub fn set_text_alignment(
&self,
gui_handler: &mut GuiHandler,
text_alignment: TextAlignment,
) -> Result<()> {
self.textable_wrapper
.set_alignment(gui_handler, text_alignment)
pub fn set_text_alignment(&self, text_alignment: TextAlignment) -> Result<()> {
self.textable_wrapper.set_alignment(text_alignment)
}
pub fn try_from(
progress_bar_info: &ProgressBarInfo,
gui_handler: &mut GuiHandler,
gui_handler: &Arc<GuiHandler>,
) -> Result<Arc<Self>> {
let mut progress_bar_builder = ProgressBar::builder()
.set_text_alignment(progress_bar_info.text_alignment)
@ -234,7 +227,7 @@ impl ProgressBar {
progress_bar_builder = progress_bar_builder.set_grow_direction(dir);
}
progress_bar_builder.build(gui_handler)
progress_bar_builder.build(gui_handler.clone())
}
#[inline]
@ -242,18 +235,18 @@ impl ProgressBar {
*self.progress.lock().unwrap()
}
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.delete(gui_handler)?;
fn disable_base(&self) -> Result<()> {
Framable::delete(&self.framable)?;
if let Some(background) = &self.background {
background.disable(gui_handler)?;
background.disable()?;
}
if let Some(foreground) = &self.foreground {
foreground.disable(gui_handler)?;
foreground.disable()?;
}
self.textable_wrapper.disable(gui_handler)?;
self.textable_wrapper.disable()?;
Ok(())
}
@ -278,24 +271,24 @@ impl Visibility for ProgressBar {
self.visible.load(SeqCst)
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible() {
self.visible.store(visibility, SeqCst);
if visibility {
self.framable.add(gui_handler)?;
Framable::add(&self.framable)?;
if let Some(background) = &self.background {
background.enable(gui_handler)?;
background.enable()?;
}
if let Some(foreground) = &self.foreground {
foreground.enable(gui_handler)?;
foreground.enable()?;
}
self.textable_wrapper.enable(gui_handler)?;
self.textable_wrapper.enable()?;
} else {
self.disable_base(gui_handler)?;
self.disable_base()?;
}
}
@ -306,7 +299,6 @@ impl Visibility for ProgressBar {
impl Gridable for ProgressBar {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -314,18 +306,17 @@ impl Gridable for ProgressBar {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.framable
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
if let Some(background) = &self.background {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
if let Some(foreground) = &self.foreground {
foreground.update_frame(gui_handler)?;
foreground.update_frame()?;
}
self.textable_wrapper.update(gui_handler)?;
self.textable_wrapper.update()?;
Ok(())
}
@ -357,3 +348,11 @@ impl Gridable for ProgressBar {
self.framable.position()
}
}
impl Drop for ProgressBar {
fn drop(&mut self) {
if self.visible.load(SeqCst) {
self.disable_base().unwrap();
}
}
}

View file

@ -3,8 +3,8 @@ use anyhow::Result;
use utilities::prelude::*;
use std::sync::{
Arc, RwLock,
atomic::{AtomicBool, Ordering::SeqCst},
Arc, RwLock,
};
use super::fill_type::{FillType, InnerFillType};
@ -48,18 +48,17 @@ impl TextFieldBuilder {
self
}
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<TextField>> {
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<TextField>> {
let framable = Framable::new(gui_handler.clone(), false)?;
let background = RwLock::new(
self.background
.clone()
.map(|info| FillType::new(gui_handler, framable.clone(), info))
.map(|info| FillType::new(framable.clone(), info))
.transpose()?,
);
let textable = Textable::new(
gui_handler,
framable.clone(),
match self.text {
Some(text) => text,
@ -70,9 +69,13 @@ impl TextFieldBuilder {
self.text_color,
)?;
let text_changed_executable = Executable::new();
let text_changed_executable = Executable::new(&gui_handler);
let writeable = Writeable::new(textable.clone(), text_changed_executable.clone())?;
let writeable = Writeable::new(
gui_handler,
textable.clone(),
text_changed_executable.clone(),
)?;
let text_field = Arc::new(TextField {
framable,
@ -114,7 +117,7 @@ impl TextField {
}
}
pub fn try_from(info: &TextFieldInfo, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
pub fn try_from(info: &TextFieldInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
let text = info.text.read().unwrap().clone();
let color = info.text_color;
@ -134,7 +137,7 @@ impl TextField {
text_field_builder = text_field_builder.set_text(text);
}
text_field_builder.build(gui_handler)
text_field_builder.build(gui_handler.clone())
}
fn update_color_change(self: &Arc<Self>) {
@ -145,18 +148,17 @@ impl TextField {
let weak_self = Arc::downgrade(self);
self.writeable
.set_activation_changed(move |gui_handler, active| {
self.writeable.set_activation_changed(move |active| {
if let Some(me) = weak_self.upgrade() {
if active {
if let Some(background) = &*me.background.read().unwrap() {
if let InnerFillType::Color(colorable) = &background.inner {
colorable.set_color(gui_handler, focus_color)?;
colorable.set_color(focus_color)?;
}
}
} else if let Some(background) = &*me.background.read().unwrap() {
if let InnerFillType::Color(colorable) = &background.inner {
colorable.set_color(gui_handler, normal_color)?;
colorable.set_color(normal_color)?;
}
}
}
@ -169,37 +171,31 @@ impl TextField {
pub fn set_text_changed_callback<F>(&self, f: F)
where
F: Fn(&mut GuiHandler, Option<String>) -> Result<()> + Send + Sync + 'static,
F: Fn(Option<String>) -> Result<()> + Send + Sync + 'static,
{
self.text_changed_executable.set_callback(f);
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
self.textable.set_text_color(gui_handler, text_color)
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
self.textable.set_text_color(text_color)
}
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
self.textable.set_text(gui_handler, text)
pub fn set_text(&self, text: impl ToString) -> Result<()> {
self.textable.set_text(text)
}
pub fn text(&self) -> Option<String> {
let t = self.textable.text();
if t.is_empty() { None } else { Some(t) }
if t.is_empty() {
None
} else {
Some(t)
}
}
pub fn set_background(
self: &Arc<Self>,
gui_handler: &mut GuiHandler,
background: impl Into<FillTypeInfo>,
) -> Result<()> {
super::set_background(
gui_handler,
self.visible(),
&self.framable,
&self.background,
background,
)?;
pub fn set_background(self: &Arc<Self>, background: impl Into<FillTypeInfo>) -> Result<()> {
super::set_background(self.visible(), &self.framable, &self.background, background)?;
self.update_color_change();
@ -216,25 +212,25 @@ impl TextField {
None
}
pub fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<()> {
self.writeable.add_letter(gui_handler, letter)
pub fn add_letter(&self, letter: char) -> Result<()> {
self.writeable.add_letter(letter)
}
pub fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.writeable.remove_last(gui_handler)
pub fn remove_last(&self) -> Result<()> {
self.writeable.remove_last()
}
pub fn focus_input(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.writeable.set_active(gui_handler)
pub fn focus_input(&self) -> Result<()> {
self.writeable.set_active()
}
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
self.framable.delete(gui_handler)?;
self.textable.delete(gui_handler)?;
self.writeable.delete(gui_handler)?;
fn disable_base(&self) -> Result<()> {
self.framable.delete()?;
self.textable.delete()?;
self.writeable.delete()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.disable(gui_handler)?;
background.disable()?;
}
Ok(())
@ -258,7 +254,6 @@ impl GuiElementTraits for TextField {
impl Gridable for TextField {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -266,13 +261,12 @@ impl Gridable for TextField {
vert_align: VerticalAlign,
hori_align: HorizontalAlign,
) -> Result<()> {
self.framable
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
self.textable.update_text(gui_handler)?;
self.textable.update_text()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.update_frame(gui_handler)?;
background.update_frame()?;
}
Ok(())
@ -310,23 +304,33 @@ impl Visibility for TextField {
self.visible.load(SeqCst)
}
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
fn set_visibility(&self, visibility: bool) -> Result<()> {
if visibility != self.visible() {
self.visible.store(visibility, SeqCst);
if visibility {
self.framable.add(gui_handler)?;
self.textable.add(gui_handler)?;
self.writeable.add(gui_handler)?;
self.framable.add()?;
self.textable.add()?;
self.writeable.add()?;
if let Some(background) = self.background.read().unwrap().as_ref() {
background.enable(gui_handler)?;
background.enable()?;
}
} else {
self.disable_base(gui_handler)?;
self.disable_base()?;
}
}
Ok(())
}
}
impl Drop for TextField {
fn drop(&mut self) {
if self.visible() {
self.disable_base().unwrap();
}
self.textable.clear_callback();
}
}

View file

@ -54,7 +54,6 @@ pub trait GuiElementTraits: Send + Sync {
pub trait Gridable {
fn set_frame(
&self,
gui_handler: &mut GuiHandler,
x: i32,
y: i32,
w: u32,
@ -74,7 +73,7 @@ pub trait Gridable {
pub trait Visibility {
fn visible(&self) -> bool;
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()>;
fn set_visibility(&self, visibility: bool) -> Result<()>;
}
pub enum GuiElement<'a> {

View file

@ -35,7 +35,7 @@ impl Debug for UiElement {
macro_rules! impl_from {
($data_type:ident $(< $($lt:lifetime),+ >)? ) => {
impl<'a> From<&Arc<$data_type$(<$($lt,)+>)?>> for UiElement {
impl From<&Arc<$data_type$(<$($lt,)+>)?>> for UiElement {
fn from(v: &Arc<$data_type$(<$($lt,)+>)?>) -> Self {
UiElement::$data_type(Arc::downgrade(v))
}
@ -59,7 +59,7 @@ pub trait GetElement<T> {
macro_rules! impl_element {
($data_type:ident $(< $($lt:lifetime),+ >)? ) => {
impl<'a> GetElement<$data_type$(<$($lt,)+>)?> for HashMap<String, UiElement> {
impl GetElement<$data_type$(<$($lt,)+>)?> for HashMap<String, UiElement> {
fn element(&self, id: &str) -> Result<Arc<$data_type$(<$($lt,)+>)?>> {
match self.get(id) {
Some(element) => match element {

View file

@ -4,8 +4,8 @@ use crate::{
};
use anyhow::Result;
use std::sync::{
Arc, Mutex,
atomic::{AtomicU32, Ordering::SeqCst},
Arc, Mutex,
};
use utilities::prelude::*;
use vulkan_rs::prelude::*;
@ -48,26 +48,17 @@ impl TextableWrapper {
Ok(())
}
pub(crate) fn set_text_color(
&self,
gui_handler: &mut GuiHandler,
text_color: Color,
) -> Result<()> {
pub(crate) fn set_text_color(&self, text_color: Color) -> Result<()> {
*self.color.lock().unwrap() = text_color;
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
textable.set_text_color(gui_handler, text_color)?;
textable.set_text_color(text_color)?;
}
Ok(())
}
pub(crate) fn set_text(
&self,
gui_handler: &mut GuiHandler,
text: impl ToString,
is_visible: bool,
) -> Result<()> {
pub(crate) fn set_text(&self, text: impl ToString, is_visible: bool) -> Result<()> {
let text = text.to_string();
let mut textable = self.textable.lock().unwrap();
@ -77,18 +68,17 @@ impl TextableWrapper {
current_textable.clear_callback();
if is_visible {
current_textable.delete(gui_handler)?;
current_textable.delete()?;
}
*textable = None;
} else {
current_textable.set_text(gui_handler, text)?;
current_textable.set_text(text)?;
}
}
None => {
if !text.is_empty() {
let new_textable = Textable::new(
gui_handler,
self.framable.clone(),
text,
*self.ratio.lock().unwrap(),
@ -97,13 +87,13 @@ impl TextableWrapper {
)?;
if self.framable.is_framed() {
new_textable.update_text(gui_handler)?;
new_textable.update_text()?;
}
new_textable.set_ui_layer(self.framable.ui_layer());
if is_visible {
new_textable.add(gui_handler)?;
new_textable.add()?;
}
*textable = Some(new_textable);
@ -123,15 +113,11 @@ impl TextableWrapper {
.map(|textable| textable.text()))
}
pub(crate) fn set_height_ratio(
&self,
gui_handler: &mut GuiHandler,
height_ratio: f32,
) -> Result<()> {
pub(crate) fn set_height_ratio(&self, height_ratio: f32) -> Result<()> {
*self.ratio.lock().unwrap() = height_ratio;
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
textable.set_size(gui_handler, height_ratio)?;
textable.set_size(height_ratio)?;
}
Ok(())
@ -141,39 +127,35 @@ impl TextableWrapper {
*self.ratio.lock().unwrap()
}
pub(crate) fn set_alignment(
&self,
gui_handler: &mut GuiHandler,
alignment: TextAlignment,
) -> Result<()> {
pub(crate) fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
*self.alignment.lock().unwrap() = alignment;
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
textable.set_text_alignment(gui_handler, alignment)?;
textable.set_text_alignment(alignment)?;
}
Ok(())
}
pub(crate) fn update(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn update(&self) -> Result<()> {
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
textable.update_text(gui_handler)?;
textable.update_text()?;
}
Ok(())
}
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn enable(&self) -> Result<()> {
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
textable.add(gui_handler)?;
textable.add()?;
}
Ok(())
}
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn disable(&self) -> Result<()> {
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
textable.delete(gui_handler)?;
textable.delete()?;
}
Ok(())
@ -198,15 +180,13 @@ pub(crate) struct IconizableWrapper {
impl IconizableWrapper {
pub(crate) fn new(
gui_handler: &mut GuiHandler,
framable: Arc<Framable>,
builder: Option<IconBuilderType>,
positioning: Option<IconizablePositioning>,
margin: u32,
) -> Result<Self> {
let iconizable: Option<Result<Arc<Iconizable>>> = builder.map(|content| {
let iconizable =
Iconizable::new(gui_handler, framable.clone(), content, positioning.clone())?;
let iconizable = Iconizable::new(framable.clone(), content, positioning.clone())?;
iconizable.set_margin(margin)?;
@ -234,16 +214,12 @@ impl IconizableWrapper {
Ok(())
}
pub(crate) fn clear_icon(
&self,
gui_handler: &mut GuiHandler,
is_visible: bool,
) -> Result<()> {
pub(crate) fn clear_icon(&self, is_visible: bool) -> Result<()> {
let mut iconizable = self.iconizable.lock().unwrap();
if let Some(iconizable) = iconizable.as_ref() {
if is_visible {
iconizable.delete(gui_handler)?;
iconizable.delete()?;
}
iconizable.clear_callback();
@ -256,17 +232,15 @@ impl IconizableWrapper {
pub(crate) fn set_icon(
&self,
gui_handler: &mut GuiHandler,
icon_builder: impl Into<IconBuilderType>,
is_visible: bool,
) -> Result<()> {
let mut iconizable = self.iconizable.lock().unwrap();
match iconizable.as_ref() {
Some(iconizable) => iconizable.set_icon(gui_handler, icon_builder)?,
Some(iconizable) => iconizable.set_icon(icon_builder)?,
None => {
let new_iconizable = Iconizable::new(
gui_handler,
self.framable.clone(),
icon_builder,
self.positioning.clone(),
@ -275,13 +249,13 @@ impl IconizableWrapper {
new_iconizable.set_margin(self.margin.load(SeqCst))?;
if self.framable.is_framed() {
new_iconizable.update_frame(gui_handler)?;
new_iconizable.update_frame()?;
}
new_iconizable.set_ui_layer(self.framable.ui_layer());
if is_visible {
new_iconizable.add(gui_handler)?;
new_iconizable.add()?;
}
*iconizable = Some(new_iconizable);
@ -291,11 +265,11 @@ impl IconizableWrapper {
Ok(())
}
pub(crate) fn set_margin(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> {
pub(crate) fn set_margin(&self, margin: u32) -> Result<()> {
if self.framable.is_framed() {
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
iconizable.set_margin(margin)?;
iconizable.update_frame(gui_handler)?;
iconizable.update_frame()?;
}
}
@ -311,25 +285,25 @@ impl IconizableWrapper {
}
}
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn enable(&self) -> Result<()> {
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
iconizable.add(gui_handler)?;
iconizable.add()?;
}
Ok(())
}
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn disable(&self) -> Result<()> {
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
iconizable.delete(gui_handler)?;
iconizable.delete()?;
}
Ok(())
}
pub(crate) fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn update_frame(&self) -> Result<()> {
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
iconizable.update_frame(gui_handler)?;
iconizable.update_frame()?;
}
Ok(())

View file

@ -25,8 +25,7 @@ pub struct Clickable {
ui_layer: AtomicI32,
executable: Arc<Executable<()>>,
clicked_changed_callback:
RwLock<Option<Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>>>,
clicked_changed_callback: RwLock<Option<Box<dyn Fn() -> Result<()> + Send + Sync>>>,
}
impl Clickable {
@ -56,7 +55,7 @@ impl Clickable {
/// # Arguments
///
/// * `clickable` is a `&Arc<Clickable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_clickable(self.ui_layer.load(SeqCst), self.clone())
}
@ -65,7 +64,7 @@ impl Clickable {
/// # Arguments
///
/// * `clickable` is a `&Arc<Clickable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_clickable(self.ui_layer.load(SeqCst), self)?;
self.set_clicked(gui_handler, false)?;
@ -90,7 +89,7 @@ impl Clickable {
/// * `clicked_changed_callback` is a `Option<Box<Callback>>`
pub fn set_clicked_changed_callback(
&self,
clicked_changed_callback: Option<Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>>,
clicked_changed_callback: Option<Box<dyn Fn() -> Result<()> + Send + Sync>>,
) {
*self.clicked_changed_callback.write().unwrap() = clicked_changed_callback;
}
@ -100,14 +99,14 @@ impl Clickable {
*self.audible.write().unwrap() = audible;
}
pub fn set_clicked(&self, gui_handler: &mut GuiHandler, clicked: bool) -> Result<bool> {
pub fn set_clicked(&self, gui_handler: &mut GuiHandler<'_>, clicked: bool) -> Result<bool> {
if self.clicked() != clicked {
self.clicked.store(clicked, SeqCst);
if let Some(clicked_changed_callback) =
self.clicked_changed_callback.read().unwrap().as_ref()
{
clicked_changed_callback(gui_handler)?;
clicked_changed_callback()?;
}
if self.clicked() {

View file

@ -34,7 +34,7 @@ pub struct Colorable {
impl Colorable {
/// Factory method for `Colorable`, returns `Arc<Colorable>`.
pub fn new(
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
framable: Arc<Framable>,
color: Color,
fill_type: DisplayableFillType,
@ -80,7 +80,7 @@ impl Colorable {
/// # Arguments
///
/// * `colorable` is a `&Arc<Colorable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_colorable(self.ui_layer.load(SeqCst), self.clone())
}
@ -89,7 +89,7 @@ impl Colorable {
/// # Arguments
///
/// * `colorable` is a `&Arc<Colorable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_colorable(self.ui_layer.load(SeqCst), self)
}
@ -107,7 +107,7 @@ impl Colorable {
/// # Arguments
///
/// * `color` defines the color
pub fn set_color(&self, gui_handler: &mut GuiHandler, color: Color) -> Result<()> {
pub fn set_color(&self, color: Color, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
let set = gui_handler.color_descriptor(color)?;
*self.color.write().unwrap() = color;
@ -147,7 +147,7 @@ impl Colorable {
}
/// Update frame method if the original frame is invalidated
pub fn update_frame(&self, gui_handler: &GuiHandler) -> Result<()> {
pub fn update_frame(&self, gui_handler: &GuiHandler<'_>) -> Result<()> {
let mut frame = self.buffer.map_complete()?;
let mut x_start = self.framable.left() as f32;

View file

@ -71,7 +71,7 @@ impl Displayable {
/// * `framable` is a `Arc<Framable>` instance
/// * `name` is the name for a png
pub fn new(
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
framable: Arc<Framable>,
displayable_type: impl Into<DisplayableType>,
fill_type: DisplayableFillType,
@ -128,7 +128,7 @@ impl Displayable {
/// # Arguments
///
/// * `displayable` is a `&Arc<Displayable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_displayable(self.ui_layer.load(SeqCst), self.clone())
}
@ -137,7 +137,7 @@ impl Displayable {
/// # Arguments
///
/// * `displayable` is a `&Arc<Displayable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_displayable(self.ui_layer.load(SeqCst), self)
}
@ -161,7 +161,7 @@ impl Displayable {
/// * `name` is the name of the texture in `gui/` without `.png` suffix
pub fn set_image(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
displayable_type: impl Into<DisplayableType>,
) -> Result<()> {
let displayable_type = displayable_type.into();
@ -233,7 +233,7 @@ impl Displayable {
}
/// Update frame method if the original frame is invalidated
pub fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn update_frame(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
let mut frame = self.buffer.map_complete()?;
let mut x_start = self.framable.left() as f32;

View file

@ -7,8 +7,8 @@ use std::sync::{Arc, RwLock};
use crate::prelude::*;
/// `Executable` holds a closure which can be executed
pub struct Executable<I: Send + Sync> {
callback: RwLock<Option<Arc<dyn Fn(&mut GuiHandler, I) -> Result<()> + Send + Sync>>>,
pub struct Executable<I: Send + Sync + 'static> {
callback: RwLock<Option<Arc<dyn Fn(I) -> Result<()> + Send + Sync>>>,
}
impl<I: Send + Sync + 'static> Executable<I> {
@ -26,7 +26,7 @@ impl<I: Send + Sync + 'static> Executable<I> {
/// * `callback` is a `Option<Callback>` closure
pub fn set_callback<F>(&self, callback: impl Into<Option<F>>)
where
F: Fn(&mut GuiHandler, I) -> Result<()> + Send + Sync + 'static,
F: Fn(I) -> Result<()> + Send + Sync + 'static,
{
let mut function = self.callback.write().unwrap();
@ -37,11 +37,11 @@ impl<I: Send + Sync + 'static> Executable<I> {
}
/// Execute the callback closure if possible
pub fn execute(&self, gui_handler: &mut GuiHandler, input: I) -> Result<()> {
pub fn execute(&self, gui_handler: &mut GuiHandler<'_>, input: I) -> Result<()> {
if let Some(callback) = self.callback.read().unwrap().as_ref() {
let callback = callback.clone();
gui_handler.add_callback(move |gui_handler| (callback)(gui_handler, input));
gui_handler.add_callback(move || (callback)(input));
}
Ok(())

View file

@ -86,7 +86,7 @@ pub struct Framable {
resize_callbacks: RwLock<
Vec<(
Handle,
Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>,
Box<dyn Fn(&mut GuiHandler<'_>) -> Result<()> + Send + Sync>,
)>,
>,
@ -149,7 +149,7 @@ impl Framable {
/// # Arguments
///
/// * `framable` - is a `&Arc<Framable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
// check if window size is the same as last time
if gui_handler.width() != self.window_width.load(SeqCst)
|| gui_handler.height() != self.window_height.load(SeqCst)
@ -174,7 +174,7 @@ impl Framable {
/// # Arguments
///
/// * `framable` - is a `&Arc<Framable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
if self.resize_allowed() {
gui_handler.delete_framable(self.ui_layer.load(SeqCst), self)?;
}
@ -192,7 +192,7 @@ impl Framable {
pub(crate) fn set_reference_size(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
width: u32,
height: u32,
) -> Result<()> {
@ -209,7 +209,7 @@ impl Framable {
pub(crate) fn allow_position_scale(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
allowed: bool,
) -> Result<()> {
if allowed != self.reference_scale_position.load(SeqCst) {
@ -225,7 +225,7 @@ impl Framable {
pub(crate) fn allow_size_scale(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
allowed: bool,
) -> Result<()> {
if allowed != self.reference_scale_size.load(SeqCst) {
@ -247,7 +247,7 @@ impl Framable {
/// width and a certain alignment
pub fn set_frame(
&self,
gui_handler: &GuiHandler,
gui_handler: &GuiHandler<'_>,
x_off: i32,
y_off: i32,
w: u32,
@ -311,7 +311,7 @@ impl Framable {
pub fn add_callback(
&self,
handle: impl Into<Handle>,
callback: Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>,
callback: Box<dyn Fn(&mut GuiHandler<'_>) -> Result<()> + Send + Sync>,
) {
let handle = handle.into();
@ -354,7 +354,7 @@ impl Framable {
*self.horizontal_alignment.read().unwrap()
}
fn calculate_frame(&self, gui_handler: &GuiHandler) {
fn calculate_frame(&self, gui_handler: &GuiHandler<'_>) {
let width = gui_handler.width();
let height = gui_handler.height();
@ -428,7 +428,7 @@ impl Framable {
pub fn change_position(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
x_offset: i32,
y_offset: i32,
) -> Result<()> {
@ -443,7 +443,7 @@ impl Framable {
}
pub fn change_position_unscaled(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
x: i32,
y: i32,
) -> Result<()> {
@ -469,7 +469,7 @@ impl Framable {
Ok(())
}
pub fn resize(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn resize(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
self.calculate_frame(gui_handler);
for (_, callback) in self.resize_callbacks.read().unwrap().iter() {

View file

@ -56,7 +56,7 @@ impl Hoverable {
/// # Arguments
///
/// * `hoverable` is a `&Arc<Hoverable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_hoverable(self.ui_layer.load(SeqCst), self.clone())?;
Ok(())
@ -67,7 +67,7 @@ impl Hoverable {
/// # Arguments
///
/// * `hoverable` is a `&Arc<Hoverable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_hoverable(self.ui_layer.load(SeqCst), self)?;
self.set_hovered(gui_handler, false)?;
@ -103,7 +103,7 @@ impl Hoverable {
/// # Arguments
///
/// * `hovered` is the new hovered state
pub fn set_hovered(&self, gui_handler: &mut GuiHandler, hovered: bool) -> Result<()> {
pub fn set_hovered(&self, gui_handler: &mut GuiHandler<'_>, hovered: bool) -> Result<()> {
if self.hovered() != hovered {
self.hovered.store(hovered, SeqCst);

View file

@ -85,7 +85,7 @@ impl Iconizable {
/// * `framable` is a `Arc<Framable>` instance
/// * `icon` is a reference to an `Arc<Image>`
pub fn new(
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
framable: Arc<Framable>,
icon_builder: impl Into<IconBuilderType>,
positioning: impl Into<Option<IconizablePositioning>>,
@ -137,7 +137,7 @@ impl Iconizable {
/// # Arguments
///
/// * `iconizable` is a `&Arc<Iconizable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_iconizable(self.ui_layer.load(SeqCst), self.clone())
}
@ -146,7 +146,7 @@ impl Iconizable {
/// # Arguments
///
/// * `iconizable` is a `&Arc<Iconizable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_iconizable(self.ui_layer.load(SeqCst), self)
}
@ -172,7 +172,7 @@ impl Iconizable {
}
/// Updates the frame
pub fn update_frame(&self, gui_handler: &GuiHandler) -> Result<()> {
pub fn update_frame(&self, gui_handler: &GuiHandler<'_>) -> Result<()> {
assert!(self.framable.is_framed(), "framable is not framed yet");
// frame parameter
@ -269,7 +269,7 @@ impl Iconizable {
/// * `icon` the new icon
pub fn set_icon(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
icon_builder: impl Into<IconBuilderType>,
) -> Result<()> {
let icon = gui_handler.request_icon(icon_builder)?;

View file

@ -12,13 +12,13 @@ use std::sync::{
/// `Selectable` gives the ability to navigate per button or controller to
/// optionally adjacent neighbour Selectables and to execute a closure
/// when the current Selectable is pressed
pub struct Selectable {
pub struct Selectable<'a> {
selected: AtomicBool,
east_neighbour: RwLock<Option<Weak<Selectable>>>,
west_neighbour: RwLock<Option<Weak<Selectable>>>,
north_neighbour: RwLock<Option<Weak<Selectable>>>,
south_neighbour: RwLock<Option<Weak<Selectable>>>,
east_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
west_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
north_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
south_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
#[cfg(feature = "audio")]
select_audible: RwLock<Option<Arc<Audible>>>,
@ -30,28 +30,29 @@ pub struct Selectable {
isolate: bool,
// used when clicked
executable: Arc<Executable<()>>,
executable: Arc<Executable<&'a mut World>>,
// used internally by button
selected_changed_executable: Arc<Executable<bool>>,
selected_changed_executable: Arc<Executable<(&'a mut World, bool)>>,
// exposed externally for event
on_select_executable: Arc<Executable<bool>>,
on_select_executable: Arc<Executable<(&'a mut World, bool)>>,
// used for custom buttons
custom_callback: RwLock<Option<Box<dyn Fn(ControllerButton) -> Result<bool> + Send + Sync>>>,
custom_callback:
RwLock<Option<Box<dyn Fn(&mut World, ControllerButton) -> Result<bool> + Send + Sync>>>,
}
impl Selectable {
impl<'a> Selectable<'a> {
/// Factory method for `Selectable`, returns `Arc<Selectable>`.
///
/// # Arguments
///
/// * `executable` is a `Arc<Executable>` instance
pub fn new(
executable: Arc<Executable<()>>,
selected_changed_executable: Arc<Executable<bool>>,
on_select_executable: Arc<Executable<bool>>,
executable: Arc<Executable<&'a mut World>>,
selected_changed_executable: Arc<Executable<(&'a mut World, bool)>>,
on_select_executable: Arc<Executable<(&'a mut World, bool)>>,
isolate: bool,
) -> Arc<Self> {
Arc::new(Selectable {
@ -84,7 +85,7 @@ impl Selectable {
/// # Arguments
///
/// * `selectable` is a `&Arc<Selectable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_selectable(self.ui_layer.load(SeqCst), self.clone())
}
@ -93,7 +94,7 @@ impl Selectable {
/// # Arguments
///
/// * `selectable` is a `&Arc<Selectable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_selectable(self.ui_layer.load(SeqCst), self)?;
self.set_selected(gui_handler, false)?;
@ -109,7 +110,7 @@ impl Selectable {
/// # Argument
///
/// * `selectable` is a `Arc<Selectable>` instance
pub fn select(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn select(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.set_selectable(Some(self.clone()))
}
@ -136,7 +137,7 @@ impl Selectable {
/// # Arguments
///
/// * `selected` is the new selected state
pub fn set_selected(&self, gui_handler: &mut GuiHandler, selected: bool) -> Result<()> {
pub fn set_selected(&self, gui_handler: &mut GuiHandler<'_>, selected: bool) -> Result<()> {
if self.selected() != selected {
self.selected.store(selected, SeqCst);
@ -163,7 +164,7 @@ impl Selectable {
}
/// Executes the `Executable`'s callback
pub(crate) fn click_event(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn click_event(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
#[cfg(feature = "audio")]
{
if let Some(audible) = self.click_audible.read().unwrap().as_ref() {
@ -194,7 +195,7 @@ impl Selectable {
}
/// Returns the current east neighbour, if possible
pub fn east_neighbour(&self) -> Option<Arc<Selectable>> {
pub fn east_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
if let Some(weak_neighbour) = self.east_neighbour.read().unwrap().as_ref() {
if let Some(neighbour) = weak_neighbour.upgrade() {
return Some(neighbour);
@ -209,7 +210,7 @@ impl Selectable {
/// # Arguments
///
/// * `selectable` the new east neighbour
pub fn set_east_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
pub fn set_east_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
if self.isolate {
return;
}
@ -223,7 +224,7 @@ impl Selectable {
}
/// Returns the current west neighbour, if possible
pub fn west_neighbour(&self) -> Option<Arc<Selectable>> {
pub fn west_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
if let Some(weak_neighbour) = self.west_neighbour.read().unwrap().as_ref() {
if let Some(neighbour) = weak_neighbour.upgrade() {
return Some(neighbour);
@ -238,7 +239,7 @@ impl Selectable {
/// # Arguments
///
/// * `selectable` the new west neighbour
pub fn set_west_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
pub fn set_west_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
if self.isolate {
return;
}
@ -252,7 +253,7 @@ impl Selectable {
}
/// Returns the current north neighbour, if possible
pub fn north_neighbour(&self) -> Option<Arc<Selectable>> {
pub fn north_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
if let Some(weak_neighbour) = self.north_neighbour.read().unwrap().as_ref() {
if let Some(neighbour) = weak_neighbour.upgrade() {
return Some(neighbour);
@ -267,7 +268,7 @@ impl Selectable {
/// # Argumnents
///
/// * `selectable` the new north neighbour
pub fn set_north_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
pub fn set_north_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
if self.isolate {
return;
}
@ -281,7 +282,7 @@ impl Selectable {
}
/// Returns the current south neighbour, if possible
pub fn south_neighbour(&self) -> Option<Arc<Selectable>> {
pub fn south_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
if let Some(weak_neighbour) = self.south_neighbour.read().unwrap().as_ref() {
if let Some(neighbour) = weak_neighbour.upgrade() {
return Some(neighbour);
@ -296,7 +297,7 @@ impl Selectable {
/// # Arguments
///
/// * `selectable` the new south neighbour
pub fn set_south_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
pub fn set_south_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
if self.isolate {
return;
}
@ -309,7 +310,7 @@ impl Selectable {
}
}
pub fn connect_vertically<'c>(upper: &Arc<Selectable>, lower: &Arc<Selectable>) {
pub fn connect_vertically<'c>(upper: &Arc<Selectable<'c>>, lower: &Arc<Selectable<'c>>) {
if upper.isolate || lower.isolate {
return;
}
@ -318,7 +319,7 @@ impl Selectable {
*lower.north_neighbour.write().unwrap() = Some(Arc::downgrade(upper));
}
pub fn connect_horizontally<'c>(left: &Arc<Selectable>, right: &Arc<Selectable>) {
pub fn connect_horizontally<'c>(left: &Arc<Selectable<'c>>, right: &Arc<Selectable<'c>>) {
if left.isolate || right.isolate {
return;
}

View file

@ -80,7 +80,7 @@ impl Textable {
/// * `height_ratio` the ratio of the height in respect to the framable height
/// * `text_alignment` where the text is aligned to
pub fn new(
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
framable: Arc<Framable>,
text: String,
height_ratio: f32,
@ -143,7 +143,7 @@ impl Textable {
/// # Arguments
///
/// * `textable` is a `&Arc<Textable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_textable(self.ui_layer.load(SeqCst), self.clone())
}
@ -152,7 +152,7 @@ impl Textable {
/// # Arguments
///
/// * `textable` is a `&Arc<Textable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_textable(self.ui_layer.load(SeqCst), self)
}
@ -172,7 +172,7 @@ impl Textable {
/// * `text_color` defines the color of the text
pub fn set_text_color(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
text_color: Color,
) -> Result<()> {
let set = gui_handler.color_descriptor(text_color)?;
@ -189,7 +189,7 @@ impl Textable {
/// * `text_alignment` where the text is aligned to
pub fn set_text_alignment(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
text_alignment: TextAlignment,
) -> Result<()> {
*self.text_alignment.write().unwrap() = text_alignment;
@ -219,7 +219,7 @@ impl Textable {
///
/// * `text` the text to be displayed
/// * `height_ratio` the ratio of the height in respect to the framable height
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
pub fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: impl ToString) -> Result<()> {
let text = text.to_string();
if text.is_empty() {
@ -250,7 +250,7 @@ impl Textable {
/// # Arguments
///
/// * `height_ratio` the ratio of the height in respect to the framable height
pub fn set_size(&self, gui_handler: &mut GuiHandler, height_ratio: f32) -> Result<()> {
pub fn set_size(&self, gui_handler: &mut GuiHandler<'_>, height_ratio: f32) -> Result<()> {
*self.height_ratio.write().unwrap() = height_ratio;
self.update_text(gui_handler)?;
@ -284,7 +284,7 @@ impl Textable {
}
/// Updates the texts buffer
pub fn update_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn update_text(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
self.calculate_text_size();
let (x, y) = self.calc_pos_from_alignment();
@ -327,7 +327,7 @@ impl Textable {
fn create_buffer(
&self,
gui_handler: &mut GuiHandler,
gui_handler: &mut GuiHandler<'_>,
win_x: f32,
win_y: f32,
) -> Result<()> {
@ -499,7 +499,7 @@ impl Textable {
Ok(())
}
fn text_changed_through_write(&self, gui_handler: &mut GuiHandler) -> Result<()> {
fn text_changed_through_write(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
self.vertex_count
.store(self.text.read().unwrap().len() as u32 * 6, SeqCst);
self.character_size.store(
@ -515,19 +515,19 @@ impl Textable {
}
impl ModifyText for Textable {
fn set_text(&self, gui_handler: &mut GuiHandler, text: String) -> Result<()> {
fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: String) -> Result<()> {
*self.text.write().unwrap() = text;
self.text_changed_through_write(gui_handler)
}
fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<String> {
fn add_letter(&self, gui_handler: &mut GuiHandler<'_>, letter: char) -> Result<String> {
self.text.write().unwrap().push(letter);
self.text_changed_through_write(gui_handler)?;
Ok(self.text.read().unwrap().clone())
}
fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<Option<String>> {
fn remove_last(&self, gui_handler: &mut GuiHandler<'_>) -> Result<Option<String>> {
self.text.write().unwrap().pop();
self.text_changed_through_write(gui_handler)?;

View file

@ -9,9 +9,9 @@ use std::sync::{
};
pub trait ModifyText: Send + Sync {
fn set_text(&self, gui_handler: &mut GuiHandler, text: String) -> Result<()>;
fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<String>;
fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<Option<String>>;
fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: String) -> Result<()>;
fn add_letter(&self, gui_handler: &mut GuiHandler<'_>, letter: char) -> Result<String>;
fn remove_last(&self, gui_handler: &mut GuiHandler<'_>) -> Result<Option<String>>;
}
/// `Writeable` gives the ability to modify the text inside an `Textable`
@ -19,8 +19,7 @@ pub struct Writeable {
modifyable: Arc<dyn ModifyText>,
text_change_executable: Arc<Executable<Option<String>>>,
activation_changed_executable:
RwLock<Option<Box<dyn Fn(&mut GuiHandler, bool) -> Result<()> + Send + Sync>>>,
activation_changed_executable: RwLock<Option<Box<dyn Fn(bool) -> Result<()> + Send + Sync>>>,
ui_layer: AtomicI32,
}
@ -41,19 +40,19 @@ impl Writeable {
}))
}
pub fn set_active(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn set_active(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
if gui_handler.set_active_writeable(self.clone())? {
if let Some(exec) = &*self.activation_changed_executable.read().unwrap() {
exec(gui_handler, true)?;
exec(true)?;
}
}
Ok(())
}
pub(crate) fn inactivation_event(&self, gui_handler: &mut GuiHandler) -> Result<()> {
pub(crate) fn inactivation_event(&self) -> Result<()> {
if let Some(exec) = &*self.activation_changed_executable.read().unwrap() {
exec(gui_handler, false)?;
exec(false)?;
}
Ok(())
@ -61,7 +60,7 @@ impl Writeable {
pub fn set_activation_changed<F>(&self, f: F)
where
F: Fn(&mut GuiHandler, bool) -> Result<()> + Send + Sync + 'static,
F: Fn(bool) -> Result<()> + Send + Sync + 'static,
{
*self.activation_changed_executable.write().unwrap() = Some(Box::new(f));
}
@ -71,7 +70,7 @@ impl Writeable {
/// # Arguments
///
/// * `writeable` is a `&Arc<Writeable>` instance that is going to be added
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.add_writeable(self.ui_layer.load(SeqCst), self.clone())
}
@ -80,7 +79,7 @@ impl Writeable {
/// # Arguments
///
/// * `writeable` is a `&Arc<Writeable>` instance that is going to be deleted
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
gui_handler.delete_writeable(self.ui_layer.load(SeqCst), self)
}
@ -93,7 +92,7 @@ impl Writeable {
/// # Arguments
///
/// * `text` that replaces the current text
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: String) -> Result<()> {
pub fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: String) -> Result<()> {
self.modifyable.set_text(gui_handler, text.clone())?;
self.text_change_executable
@ -107,17 +106,19 @@ impl Writeable {
/// # Arguments
///
/// * `letter` the letter thats going to be added
pub fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<()> {
let s = self.modifyable.add_letter(gui_handler, letter)?;
self.text_change_executable.execute(gui_handler, Some(s))?;
pub fn add_letter(&self, gui_handler: &mut GuiHandler<'_>, letter: char) -> Result<()> {
self.text_change_executable.execute(
gui_handler,
Some(self.modifyable.add_letter(gui_handler, letter)?),
)?;
Ok(())
}
/// Removes the last letter
pub fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<()> {
let s = self.modifyable.remove_last(gui_handler)?;
self.text_change_executable.execute(gui_handler, s)?;
pub fn remove_last(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
self.text_change_executable
.execute(gui_handler, self.modifyable.remove_last(gui_handler)?)?;
Ok(())
}

View file

@ -180,7 +180,7 @@ impl TextToScreen {
}
}
pub struct GuiHandler {
pub struct GuiHandler<'a> {
device: Arc<Device>,
queue: Arc<Mutex<Queue>>,
@ -239,14 +239,14 @@ pub struct GuiHandler {
current_writeable: Option<Arc<Writeable>>,
current_hoverable: Option<Arc<Hoverable>>,
current_clickable: Option<Arc<Clickable>>,
current_selectable: Option<Arc<Selectable>>,
current_selectable: Option<Arc<Selectable<'a>>>,
text_sample_count: VkSampleCountFlags,
callback_list: Vec<Box<dyn FnOnce(&mut Self) -> Result<()> + Send + Sync>>,
callback_list: Vec<Box<dyn FnOnce() -> Result<()> + Send + Sync>>,
}
impl GuiHandler {
impl<'a> GuiHandler<'a> {
pub fn new(
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
context: &impl ContextInterface,
@ -710,7 +710,7 @@ impl GuiHandler {
Ok(false)
}
pub fn current_selectable(&self) -> Option<Arc<Selectable>> {
pub fn current_selectable(&self) -> Option<Arc<Selectable<'a>>> {
self.current_selectable.clone()
}
@ -860,19 +860,14 @@ impl GuiHandler {
self.tooltip_ui = tooltip.into();
}
pub(crate) fn add_callback<F: FnOnce(&mut Self) -> Result<()> + Send + Sync + 'static>(
&mut self,
f: F,
) {
pub(crate) fn add_callback<F: FnOnce() -> Result<()> + Send + Sync + 'static>(&mut self, f: F) {
self.callback_list.push(Box::new(f));
}
pub fn process_callbacks(&mut self) -> Result<()> {
let callbacks = mem::take(&mut self.callback_list);
callbacks
.into_iter()
.try_for_each(|callback| callback(self))
callbacks.into_iter().try_for_each(|callback| callback())
}
fn render(
@ -1050,7 +1045,7 @@ macro_rules! remove_element {
}
// object handling
impl<'a> GuiHandler {
impl<'a> GuiHandler<'a> {
// framable
pub(crate) fn add_framable(&mut self, layer: i32, framable: Arc<Framable>) -> Result<()> {
add_element!(self.layers, layer, framable);
@ -1089,7 +1084,11 @@ impl<'a> GuiHandler {
}
// selectable
pub(crate) fn add_selectable(&mut self, layer: i32, selectable: Arc<Selectable>) -> Result<()> {
pub(crate) fn add_selectable(
&mut self,
layer: i32,
selectable: Arc<Selectable<'_>>,
) -> Result<()> {
add_element!(self.layers, layer, selectable);
Ok(())
@ -1098,7 +1097,7 @@ impl<'a> GuiHandler {
pub(crate) fn delete_selectable(
&mut self,
layer: i32,
selectable: &Arc<Selectable>,
selectable: &Arc<Selectable<'a>>,
) -> Result<()> {
if self.current_selectable.is_some() {
// unwrap is safe, just tested for `is_some`
@ -1182,15 +1181,13 @@ impl<'a> GuiHandler {
}
pub(crate) fn set_active_writeable(&mut self, writeable: Arc<Writeable>) -> Result<bool> {
let callback_self = unsafe { remove_life_time_mut(self) };
if let Some(current) = self.current_writeable.as_ref() {
// change nothing if both are the same
if Arc::ptr_eq(current, &writeable) {
return Ok(false);
}
current.inactivation_event(callback_self)?;
current.inactivation_event()?;
}
self.current_writeable = Some(writeable);
@ -1203,14 +1200,14 @@ impl<'a> GuiHandler {
layer: i32,
writeable: &Arc<Writeable>,
) -> Result<()> {
let callback_self = unsafe { remove_life_time_mut(self) };
{
if let Some(w) = &self.current_writeable {
if Arc::ptr_eq(w, writeable) {
w.inactivation_event(callback_self)?;
w.inactivation_event()?;
self.current_writeable = None;
}
}
}
remove_element!(self.layers, layer, writeable);
@ -1236,7 +1233,7 @@ impl<'a> GuiHandler {
Ok(())
}
pub(crate) fn set_selectable(&mut self, selectable: Option<Arc<Selectable>>) -> Result<()> {
pub(crate) fn set_selectable(&mut self, selectable: Option<Arc<Selectable<'a>>>) -> Result<()> {
let callback_self = unsafe { remove_life_time_mut(self) };
if let Some(selectable) = &self.current_selectable {
@ -1276,7 +1273,7 @@ impl<'a> GuiHandler {
}
// private - create rendering stuff
impl<'a> GuiHandler {
impl<'a> GuiHandler<'a> {
fn create_render_targets(
device: &Arc<Device>,
target_images: &TargetMode<Vec<Arc<Image>>>,
@ -1590,7 +1587,7 @@ impl<'a> GuiHandler {
}
}
impl<'a> GuiHandler {
impl<'a> GuiHandler<'a> {
pub fn process(
&mut self,
buffer_recorder: &mut CommandBufferRecorder<'_>,
@ -1694,8 +1691,8 @@ impl<'a> GuiHandler {
}
}
impl<'a> From<&'a ecs::World> for &'a GuiHandler {
fn from(world: &'a ecs::World) -> &'a GuiHandler {
world.resources.get::<GuiHandler>()
impl<'a> From<&'a ecs::World> for &'a GuiHandler<'_> {
fn from(world: &'a ecs::World) -> Self {
world.resources.get::<GuiHandler<'_>>()
}
}

View file

@ -32,7 +32,7 @@ pub struct Keyboard {
}
impl Keyboard {
pub fn new(gui_handler: &GuiHandler) -> Result<Arc<Self>> {
pub fn new(gui_handler: &Arc<GuiHandler<'a>>) -> Result<Arc<Self>> {
let text_field_gui: Arc<GuiBuilder> =
GuiBuilder::from_str(gui_handler, include_str!("text_field.xml"))?;