Remove arc from context interface

This commit is contained in:
hodasemi 2025-02-27 10:43:07 +01:00
parent 792e06abdc
commit f160914fce
44 changed files with 89 additions and 94 deletions

View file

@ -2,7 +2,7 @@
name = "ui"
version = "0.1.0"
authors = ["hodasemi <michaelh.95@t-online.de>"]
edition = "2021"
edition = "2024"
[dependencies]
quick-xml = "0.31.0"
@ -18,3 +18,4 @@ anyhow = { version = "1.0.86", features = ["backtrace"] }
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
[features]
default = ["audio"]

View file

@ -1,4 +1,4 @@
use crate::guihandler::gui::displayable::DisplayableFillType;
use crate::gui_handler::gui::displayable::DisplayableFillType;
use crate::prelude::*;
use anyhow::Result;
use utilities::prelude::*;

View file

@ -1,4 +1,4 @@
use crate::guihandler::gui::displayable::DisplayableFillType;
use crate::gui_handler::gui::displayable::DisplayableFillType;
use crate::prelude::*;
use anyhow::Result;
use assetpath::AssetPath;

View file

@ -1,4 +1,4 @@
use crate::guihandler::gui::displayable::DisplayableFillType;
use crate::gui_handler::gui::displayable::DisplayableFillType;
use crate::prelude::*;
use anyhow::Result;
use utilities::prelude::*;

View file

@ -1,4 +1,4 @@
use crate::guihandler::gui::displayable::DisplayableFillType;
use crate::gui_handler::gui::displayable::DisplayableFillType;
use crate::prelude::*;
use anyhow::anyhow;
use anyhow::{Context, Result};

View file

@ -1,6 +1,6 @@
use crate::{
builder::validator::buttoninfo::ButtonInfo, guihandler::gui::iconizable::IconizablePositioning,
prelude::*,
builder::validator::buttoninfo::ButtonInfo,
gui_handler::gui::iconizable::IconizablePositioning, prelude::*,
};
use anyhow::Result;

View file

@ -1,5 +1,5 @@
use crate::{
guihandler::gui::displayable::{DisplayableFillType, DisplayableType},
gui_handler::gui::displayable::{DisplayableFillType, DisplayableType},
prelude::*,
};
use anyhow::Result;

View file

@ -1,5 +1,5 @@
use crate::{
builder::validator::iconinfo::IconInfo, guihandler::gui::iconizable::IconizablePositioning,
builder::validator::iconinfo::IconInfo, gui_handler::gui::iconizable::IconizablePositioning,
prelude::*,
};
use anyhow::Result;

View file

@ -1,5 +1,5 @@
use crate::{
builder::validator::labelinfo::LabelInfo, guihandler::gui::iconizable::IconizablePositioning,
builder::validator::labelinfo::LabelInfo, gui_handler::gui::iconizable::IconizablePositioning,
prelude::*,
};

View file

@ -1,4 +1,4 @@
use crate::{guihandler::gui::iconizable::IconBuilderType, prelude::*};
use crate::{gui_handler::gui::iconizable::IconBuilderType, prelude::*};
use anyhow::Result;
use std::sync::{Arc, RwLock};
@ -13,7 +13,7 @@ pub mod multi_line_label;
pub mod multi_line_textfield;
pub mod progress_bar;
pub mod textfield;
pub mod uielement;
pub mod ui_element;
pub mod traits;

View file

@ -1,6 +1,6 @@
use crate::{
builder::validator::multi_line_text_field_info::MultiLineTextFieldInfo,
guihandler::gui::{displayable::DisplayableFillType, writeable::ModifyText},
gui_handler::gui::{displayable::DisplayableFillType, writeable::ModifyText},
prelude::*,
};

View file

@ -10,5 +10,5 @@ pub use super::{
progress_bar::{GrowDirection, ProgressBar, ProgressBarBuilder},
textfield::TextField,
traits::*,
uielement::*,
ui_element::*,
};

View file

@ -1,5 +1,5 @@
use crate::{
guihandler::gui::iconizable::{IconBuilderType, IconizablePositioning},
gui_handler::gui::iconizable::{IconBuilderType, IconizablePositioning},
prelude::*,
};
use anyhow::Result;

View file

@ -0,0 +1,52 @@
//! `Audible` is a property to play a sound
use crate::prelude::*;
use anyhow::Result;
use assetpath::AssetPath;
// #[cfg(feature = "audio")]
// use audio::*;
use std::sync::Arc;
/// `Audible` gives the ability to play a sound
pub struct Audible {
// gui_handler: Arc<GuiHandler>,
// sound: Arc<Sound>,
}
impl Audible {
pub fn new(gui_handler: Arc<GuiHandler>, mut path: AssetPath) -> Result<Arc<Self>> {
if !path.has_prefix() {
path.set_prefix(&gui_handler.resource_base_path().full_path());
}
// TODO:
// let sound = gui_handler.context().sound_handler().load_sound(
// path,
// "gui",
// SoundInterpretation::Generic,
// )?;
Ok(Arc::new(Audible {
// gui_handler,
// sound
}))
}
pub fn play(&self) -> Result<()> {
// self.sound.play(Some(false))?;
Ok(())
}
}
impl Drop for Audible {
fn drop(&mut self) {
// self.gui_handler
// .context()
// .sound_handler()
// .remove_sound(&self.sound)
// .unwrap();
}
}

View file

@ -15,8 +15,8 @@ use super::{
use cgmath::{ortho, vec2};
use std::sync::{
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
Arc, Mutex, RwLock,
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
};
use std::{collections::HashMap, ptr};
use std::{mem, sync::Weak};
@ -191,8 +191,6 @@ impl TextToScreen {
}
pub struct GuiHandler {
_context: Arc<dyn ContextInterface>,
device: Arc<Device>,
queue: Arc<Mutex<Queue>>,
@ -264,7 +262,7 @@ pub struct GuiHandler {
impl GuiHandler {
pub fn new(
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
context: &Arc<dyn ContextInterface>,
context: &impl ContextInterface,
) -> Result<Arc<GuiHandler>> {
let device = context.device();
let queue = context.queue();
@ -311,8 +309,6 @@ impl GuiHandler {
.build(device.clone())?;
Ok(Arc::new(GuiHandler {
_context: context.clone(),
device: device.clone(),
queue: queue.clone(),
@ -418,11 +414,6 @@ impl GuiHandler {
&self.queue
}
#[cfg(feature = "audio")]
pub(crate) fn context(&self) -> &Arc<dyn ContextInterface> {
&self._context
}
pub fn width(&self) -> u32 {
self.width.load(SeqCst)
}
@ -1437,8 +1428,8 @@ impl GuiHandler {
.build(device.clone())?;
// --- pipeline creation ---
let vertex_shader_text = include_bytes!("guishader/text.vert.spv");
let fragment_shader_text = include_bytes!("guishader/text.frag.spv");
let vertex_shader_text = include_bytes!("gui_shader/text.vert.spv");
let fragment_shader_text = include_bytes!("gui_shader/text.frag.spv");
let vertex_shader = ShaderModule::from_slice(device.clone(), vertex_shader_text)?;
let fragment_shader = ShaderModule::from_slice(device.clone(), fragment_shader_text)?;
@ -1482,9 +1473,9 @@ impl GuiHandler {
// pipeline creation
let vertex_shader =
ShaderModule::from_slice(device.clone(), include_bytes!("guishader/rect.vert.spv"))?;
ShaderModule::from_slice(device.clone(), include_bytes!("gui_shader/rect.vert.spv"))?;
let fragment_shader =
ShaderModule::from_slice(device.clone(), include_bytes!("guishader/rect.frag.spv"))?;
ShaderModule::from_slice(device.clone(), include_bytes!("gui_shader/rect.frag.spv"))?;
render_targets.execute(|render_target| {
Ok(GuiSeparator {
@ -1522,10 +1513,10 @@ impl GuiHandler {
// pipeline creation
let vertex_shader =
ShaderModule::from_slice(device.clone(), include_bytes!("guishader/rect.vert.spv"))?;
ShaderModule::from_slice(device.clone(), include_bytes!("gui_shader/rect.vert.spv"))?;
let fragment_shader = ShaderModule::from_slice(
device.clone(),
include_bytes!("guishader/input_rect.frag.spv"),
include_bytes!("gui_shader/input_rect.frag.spv"),
)?;
render_targets.execute(|render_target| {
@ -1565,11 +1556,11 @@ impl GuiHandler {
// pipeline creation
let vertex_shader = ShaderModule::from_slice(
device.clone(),
include_bytes!("guishader/single_color.vert.spv"),
include_bytes!("gui_shader/single_color.vert.spv"),
)?;
let fragment_shader = ShaderModule::from_slice(
device.clone(),
include_bytes!("guishader/single_color.frag.spv"),
include_bytes!("gui_shader/single_color.frag.spv"),
)?;
render_targets.execute(|render_target| {
@ -1650,20 +1641,20 @@ impl GuiHandler {
text_objects,
rectangle_objects,
single_color_object,
&&&index,
index,
text_pipeline,
text_descriptor,
)| {
self.render(
buffer_recorder,
&command_buffers[index],
&command_buffers[****index],
&*render_target.read().unwrap(),
single_color_object,
rectangle_objects,
text_objects,
text_pipeline,
text_descriptor,
index,
****index,
)
},
)?;

View file

@ -1,5 +1,5 @@
pub mod gui;
pub mod guihandler;
pub mod gui_handler;
mod elements;

View file

@ -16,4 +16,4 @@ pub use super::gui::{
#[cfg(feature = "audio")]
pub use super::gui::audible::Audible;
pub use super::guihandler::{Font, GuiHandler, GuiHandlerCreateInfo};
pub use super::gui_handler::{Font, GuiHandler, GuiHandlerCreateInfo};

View file

@ -1,49 +0,0 @@
//! `Audible` is a property to play a sound
use crate::prelude::*;
use anyhow::Result;
use assetpath::AssetPath;
#[cfg(feature = "audio")]
use audio::*;
use std::sync::Arc;
/// `Audible` gives the ability to play a sound
pub struct Audible {
gui_handler: Arc<GuiHandler>,
sound: Arc<Sound>,
}
impl Audible {
pub fn new(gui_handler: Arc<GuiHandler>, mut path: AssetPath) -> Result<Arc<Self>> {
if !path.has_prefix() {
path.set_prefix(&gui_handler.resource_base_path().full_path());
}
let sound = gui_handler.context().sound_handler().load_sound(
path,
"gui",
SoundInterpretation::Generic,
)?;
Ok(Arc::new(Audible { gui_handler, sound }))
}
pub fn play(&self) -> Result<()> {
self.sound.play(Some(false))?;
Ok(())
}
}
impl Drop for Audible {
fn drop(&mut self) {
self.gui_handler
.context()
.sound_handler()
.remove_sound(&self.sound)
.unwrap();
}
}

View file

@ -2,7 +2,7 @@
pub mod builder;
pub mod elements;
pub mod guihandler;
pub mod gui_handler;
pub mod keyboard;
pub mod states;
pub mod tab_control;
@ -10,8 +10,8 @@ pub mod tab_control;
mod context_interface;
mod controller_button;
mod element_creator;
mod guidirection;
mod mousebutton;
mod gui_direction;
mod mouse_button;
pub mod prelude;
pub type CustomCallback<I, O> = dyn Fn(I) -> anyhow::Result<O> + Send + Sync;

View file

@ -3,10 +3,10 @@ pub use super::context_interface::{ContextInterface, TargetMode, Unfold};
pub use super::controller_button::ControllerButton;
pub use super::element_creator::*;
pub use super::elements::prelude::*;
pub use super::guidirection::GuiDirection;
pub use super::guihandler::prelude::*;
pub use super::gui_direction::GuiDirection;
pub use super::gui_handler::prelude::*;
pub use super::keyboard::Keyboard;
pub use super::mousebutton::MouseButton;
pub use super::mouse_button::MouseButton;
pub use super::states::*;
pub use super::tab_control::TabControl;