Compare commits
2 commits
85afd978ac
...
16c32f6dbe
Author | SHA1 | Date | |
---|---|---|---|
16c32f6dbe | |||
f160914fce |
44 changed files with 90 additions and 95 deletions
|
@ -2,10 +2,10 @@
|
||||||
name = "ui"
|
name = "ui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["hodasemi <michaelh.95@t-online.de>"]
|
authors = ["hodasemi <michaelh.95@t-online.de>"]
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quick-xml = "0.31.0"
|
quick-xml = "0.37.0"
|
||||||
serde = { version = "1.0.203", features = ["derive"] }
|
serde = { version = "1.0.203", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.120" }
|
serde_json = { version = "1.0.120" }
|
||||||
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||||
|
@ -18,3 +18,4 @@ anyhow = { version = "1.0.86", features = ["backtrace"] }
|
||||||
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["audio"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::guihandler::gui::displayable::DisplayableFillType;
|
use crate::gui_handler::gui::displayable::DisplayableFillType;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::guihandler::gui::displayable::DisplayableFillType;
|
use crate::gui_handler::gui::displayable::DisplayableFillType;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assetpath::AssetPath;
|
use assetpath::AssetPath;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::guihandler::gui::displayable::DisplayableFillType;
|
use crate::gui_handler::gui::displayable::DisplayableFillType;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use utilities::prelude::*;
|
use utilities::prelude::*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::guihandler::gui::displayable::DisplayableFillType;
|
use crate::gui_handler::gui::displayable::DisplayableFillType;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
builder::validator::buttoninfo::ButtonInfo, guihandler::gui::iconizable::IconizablePositioning,
|
builder::validator::buttoninfo::ButtonInfo,
|
||||||
prelude::*,
|
gui_handler::gui::iconizable::IconizablePositioning, prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
guihandler::gui::displayable::{DisplayableFillType, DisplayableType},
|
gui_handler::gui::displayable::{DisplayableFillType, DisplayableType},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
builder::validator::iconinfo::IconInfo, guihandler::gui::iconizable::IconizablePositioning,
|
builder::validator::iconinfo::IconInfo, gui_handler::gui::iconizable::IconizablePositioning,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
builder::validator::labelinfo::LabelInfo, guihandler::gui::iconizable::IconizablePositioning,
|
builder::validator::labelinfo::LabelInfo, gui_handler::gui::iconizable::IconizablePositioning,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{guihandler::gui::iconizable::IconBuilderType, prelude::*};
|
use crate::{gui_handler::gui::iconizable::IconBuilderType, prelude::*};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ pub mod multi_line_label;
|
||||||
pub mod multi_line_textfield;
|
pub mod multi_line_textfield;
|
||||||
pub mod progress_bar;
|
pub mod progress_bar;
|
||||||
pub mod textfield;
|
pub mod textfield;
|
||||||
pub mod uielement;
|
pub mod ui_element;
|
||||||
|
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
builder::validator::multi_line_text_field_info::MultiLineTextFieldInfo,
|
builder::validator::multi_line_text_field_info::MultiLineTextFieldInfo,
|
||||||
guihandler::gui::{displayable::DisplayableFillType, writeable::ModifyText},
|
gui_handler::gui::{displayable::DisplayableFillType, writeable::ModifyText},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,5 +10,5 @@ pub use super::{
|
||||||
progress_bar::{GrowDirection, ProgressBar, ProgressBarBuilder},
|
progress_bar::{GrowDirection, ProgressBar, ProgressBarBuilder},
|
||||||
textfield::TextField,
|
textfield::TextField,
|
||||||
traits::*,
|
traits::*,
|
||||||
uielement::*,
|
ui_element::*,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
guihandler::gui::iconizable::{IconBuilderType, IconizablePositioning},
|
gui_handler::gui::iconizable::{IconBuilderType, IconizablePositioning},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
52
src/gui_handler/gui/audible.rs
Normal file
52
src/gui_handler/gui/audible.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,8 +15,8 @@ use super::{
|
||||||
use cgmath::{ortho, vec2};
|
use cgmath::{ortho, vec2};
|
||||||
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
|
|
||||||
Arc, Mutex, RwLock,
|
Arc, Mutex, RwLock,
|
||||||
|
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, ptr};
|
use std::{collections::HashMap, ptr};
|
||||||
use std::{mem, sync::Weak};
|
use std::{mem, sync::Weak};
|
||||||
|
@ -191,8 +191,6 @@ impl TextToScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GuiHandler {
|
pub struct GuiHandler {
|
||||||
_context: Arc<dyn ContextInterface>,
|
|
||||||
|
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
queue: Arc<Mutex<Queue>>,
|
queue: Arc<Mutex<Queue>>,
|
||||||
|
|
||||||
|
@ -264,7 +262,7 @@ pub struct GuiHandler {
|
||||||
impl GuiHandler {
|
impl GuiHandler {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
|
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
|
||||||
context: &Arc<dyn ContextInterface>,
|
context: &impl ContextInterface,
|
||||||
) -> Result<Arc<GuiHandler>> {
|
) -> Result<Arc<GuiHandler>> {
|
||||||
let device = context.device();
|
let device = context.device();
|
||||||
let queue = context.queue();
|
let queue = context.queue();
|
||||||
|
@ -311,8 +309,6 @@ impl GuiHandler {
|
||||||
.build(device.clone())?;
|
.build(device.clone())?;
|
||||||
|
|
||||||
Ok(Arc::new(GuiHandler {
|
Ok(Arc::new(GuiHandler {
|
||||||
_context: context.clone(),
|
|
||||||
|
|
||||||
device: device.clone(),
|
device: device.clone(),
|
||||||
queue: queue.clone(),
|
queue: queue.clone(),
|
||||||
|
|
||||||
|
@ -418,11 +414,6 @@ impl GuiHandler {
|
||||||
&self.queue
|
&self.queue
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "audio")]
|
|
||||||
pub(crate) fn context(&self) -> &Arc<dyn ContextInterface> {
|
|
||||||
&self._context
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn width(&self) -> u32 {
|
pub fn width(&self) -> u32 {
|
||||||
self.width.load(SeqCst)
|
self.width.load(SeqCst)
|
||||||
}
|
}
|
||||||
|
@ -1437,8 +1428,8 @@ impl GuiHandler {
|
||||||
.build(device.clone())?;
|
.build(device.clone())?;
|
||||||
|
|
||||||
// --- pipeline creation ---
|
// --- pipeline creation ---
|
||||||
let vertex_shader_text = include_bytes!("guishader/text.vert.spv");
|
let vertex_shader_text = include_bytes!("gui_shader/text.vert.spv");
|
||||||
let fragment_shader_text = include_bytes!("guishader/text.frag.spv");
|
let fragment_shader_text = include_bytes!("gui_shader/text.frag.spv");
|
||||||
|
|
||||||
let vertex_shader = ShaderModule::from_slice(device.clone(), vertex_shader_text)?;
|
let vertex_shader = ShaderModule::from_slice(device.clone(), vertex_shader_text)?;
|
||||||
let fragment_shader = ShaderModule::from_slice(device.clone(), fragment_shader_text)?;
|
let fragment_shader = ShaderModule::from_slice(device.clone(), fragment_shader_text)?;
|
||||||
|
@ -1482,9 +1473,9 @@ impl GuiHandler {
|
||||||
|
|
||||||
// pipeline creation
|
// pipeline creation
|
||||||
let vertex_shader =
|
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 =
|
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| {
|
render_targets.execute(|render_target| {
|
||||||
Ok(GuiSeparator {
|
Ok(GuiSeparator {
|
||||||
|
@ -1522,10 +1513,10 @@ impl GuiHandler {
|
||||||
|
|
||||||
// pipeline creation
|
// pipeline creation
|
||||||
let vertex_shader =
|
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(
|
let fragment_shader = ShaderModule::from_slice(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
include_bytes!("guishader/input_rect.frag.spv"),
|
include_bytes!("gui_shader/input_rect.frag.spv"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
render_targets.execute(|render_target| {
|
render_targets.execute(|render_target| {
|
||||||
|
@ -1565,11 +1556,11 @@ impl GuiHandler {
|
||||||
// pipeline creation
|
// pipeline creation
|
||||||
let vertex_shader = ShaderModule::from_slice(
|
let vertex_shader = ShaderModule::from_slice(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
include_bytes!("guishader/single_color.vert.spv"),
|
include_bytes!("gui_shader/single_color.vert.spv"),
|
||||||
)?;
|
)?;
|
||||||
let fragment_shader = ShaderModule::from_slice(
|
let fragment_shader = ShaderModule::from_slice(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
include_bytes!("guishader/single_color.frag.spv"),
|
include_bytes!("gui_shader/single_color.frag.spv"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
render_targets.execute(|render_target| {
|
render_targets.execute(|render_target| {
|
||||||
|
@ -1650,20 +1641,20 @@ impl GuiHandler {
|
||||||
text_objects,
|
text_objects,
|
||||||
rectangle_objects,
|
rectangle_objects,
|
||||||
single_color_object,
|
single_color_object,
|
||||||
&&&index,
|
index,
|
||||||
text_pipeline,
|
text_pipeline,
|
||||||
text_descriptor,
|
text_descriptor,
|
||||||
)| {
|
)| {
|
||||||
self.render(
|
self.render(
|
||||||
buffer_recorder,
|
buffer_recorder,
|
||||||
&command_buffers[index],
|
&command_buffers[****index],
|
||||||
&*render_target.read().unwrap(),
|
&*render_target.read().unwrap(),
|
||||||
single_color_object,
|
single_color_object,
|
||||||
rectangle_objects,
|
rectangle_objects,
|
||||||
text_objects,
|
text_objects,
|
||||||
text_pipeline,
|
text_pipeline,
|
||||||
text_descriptor,
|
text_descriptor,
|
||||||
index,
|
****index,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
|
@ -1,5 +1,5 @@
|
||||||
pub mod gui;
|
pub mod gui;
|
||||||
pub mod guihandler;
|
pub mod gui_handler;
|
||||||
|
|
||||||
mod elements;
|
mod elements;
|
||||||
|
|
|
@ -16,4 +16,4 @@ pub use super::gui::{
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
pub use super::gui::audible::Audible;
|
pub use super::gui::audible::Audible;
|
||||||
|
|
||||||
pub use super::guihandler::{Font, GuiHandler, GuiHandlerCreateInfo};
|
pub use super::gui_handler::{Font, GuiHandler, GuiHandlerCreateInfo};
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
pub mod builder;
|
pub mod builder;
|
||||||
pub mod elements;
|
pub mod elements;
|
||||||
pub mod guihandler;
|
pub mod gui_handler;
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod states;
|
pub mod states;
|
||||||
pub mod tab_control;
|
pub mod tab_control;
|
||||||
|
@ -10,8 +10,8 @@ pub mod tab_control;
|
||||||
mod context_interface;
|
mod context_interface;
|
||||||
mod controller_button;
|
mod controller_button;
|
||||||
mod element_creator;
|
mod element_creator;
|
||||||
mod guidirection;
|
mod gui_direction;
|
||||||
mod mousebutton;
|
mod mouse_button;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
pub type CustomCallback<I, O> = dyn Fn(I) -> anyhow::Result<O> + Send + Sync;
|
pub type CustomCallback<I, O> = dyn Fn(I) -> anyhow::Result<O> + Send + Sync;
|
||||||
|
|
|
@ -3,10 +3,10 @@ pub use super::context_interface::{ContextInterface, TargetMode, Unfold};
|
||||||
pub use super::controller_button::ControllerButton;
|
pub use super::controller_button::ControllerButton;
|
||||||
pub use super::element_creator::*;
|
pub use super::element_creator::*;
|
||||||
pub use super::elements::prelude::*;
|
pub use super::elements::prelude::*;
|
||||||
pub use super::guidirection::GuiDirection;
|
pub use super::gui_direction::GuiDirection;
|
||||||
pub use super::guihandler::prelude::*;
|
pub use super::gui_handler::prelude::*;
|
||||||
pub use super::keyboard::Keyboard;
|
pub use super::keyboard::Keyboard;
|
||||||
pub use super::mousebutton::MouseButton;
|
pub use super::mouse_button::MouseButton;
|
||||||
pub use super::states::*;
|
pub use super::states::*;
|
||||||
pub use super::tab_control::TabControl;
|
pub use super::tab_control::TabControl;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue