Compare commits

..

1 commit

Author SHA1 Message Date
86be46a050 Update Rust crate quick-xml to 0.37.0
Some checks failed
Gavania Merge Build / build (pull_request) Has been cancelled
2025-04-15 09:05:12 +00:00
13 changed files with 76 additions and 169 deletions

View file

@ -10,15 +10,12 @@ serde = { version = "1.0.203", features = ["derive"] }
serde_json = { version = "1.0.120" }
paste = "1.0.15"
anyhow = { version = "1.0.86", features = ["backtrace"] }
itertools = "0.14.0"
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
ecs = { git = "https://gavania.de/hodasemi/ecs.git" }
ui_proc_macro = { path = "../ui_proc_macro" }
# optional
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }

View file

@ -203,8 +203,7 @@ impl Functionality for GuiBuilder {
let suffix_less_function_name = handle_function_suffix(function_name);
let button: Arc<Button> = self.element(&suffix_less_function_name)?;
todo!()
// button.set_callback(callback);
button.set_callback(callback);
}
Ok(())

View file

@ -181,8 +181,7 @@ impl Functionality for GuiSnippet {
let suffix_less_function_name = handle_function_suffix(function_name);
let button: Arc<Button> = self.element(&suffix_less_function_name)?;
todo!()
// button.set_callback(callback);
button.set_callback(callback);
}
Ok(())

View file

@ -271,9 +271,9 @@ pub struct Button {
#[cfg(feature = "audio")]
_hover_sound: Option<Arc<Audible>>,
pub(crate) click_executable: Arc<Executable<()>>,
pub(crate) select_executable: Arc<Executable<bool>>,
pub(crate) on_select_executable: Arc<Executable<bool>>,
click_executable: Arc<Executable<()>>,
select_executable: Arc<Executable<bool>>,
on_select_executable: Arc<Executable<bool>>,
normal: FillType,
selected: FillType,
@ -313,23 +313,26 @@ impl Button {
self.selectable.select(gui_handler)
}
// pub fn set_callback<F>(&self, callback: F)
// where
// F: Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
// {
// self.click_executable.set_callback(
// move |commands: &mut Commands, gui_handler: &mut GuiHandler, _: ()| {
// callback(commands, gui_handler)
// },
// );
// }
pub fn set_callback<F>(&self, callback: F)
where
F: Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
{
self.click_executable.set_callback(
move |commands: &mut Commands, gui_handler: &mut GuiHandler, _: ()| {
callback(commands, gui_handler)
},
);
}
pub fn set_select_callback<F>(&self, callback: F)
where
F: Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync + 'static,
{
todo!()
// self.on_select_executable.set_callback(callback);
self.on_select_executable.set_callback(
move |commands: &mut Commands, gui_handler: &mut GuiHandler, select: bool| {
callback(commands, gui_handler, select)
},
);
}
pub fn set_custom_callback<F>(&self, callback: F)
@ -590,10 +593,8 @@ impl Button {
fn create_selected_changed_callback(button: Arc<Button>) {
let button_weak = Arc::downgrade(&button);
let selected_changed = move |_world: &mut World,
_commands: &mut Commands,
gui_handler: &mut GuiHandler,
selected: bool| {
let selected_changed =
move |_commands: &mut Commands, gui_handler: &mut GuiHandler, selected: bool| {
if let Some(button) = button_weak.upgrade() {
if selected {
button.set_button_state(gui_handler, ButtonState::Selected)?;

View file

@ -1,22 +0,0 @@
use anyhow::Result;
use ecs::{resources::Resource as ResourceTrait, *};
use itertools::Itertools;
use ui_proc_macro::implement_callbacks;
use crate::prelude::*;
use std::marker::PhantomData;
pub trait SetCallback<T, R, Func, Filter> {
fn set_callback(&self, func: Func);
}
pub trait SetSelectCallback<T, R, Func, Filter> {
fn set_select_callback(&self, func: Func);
}
pub trait SetCustomCallback<T, R, Func, Filter> {
fn set_custom_callback(&self, func: Func);
}
implement_callbacks!(2, 0);

View file

@ -18,7 +18,6 @@ pub mod ui_element;
pub mod traits;
mod callback_builder;
pub mod callback_impl;
pub mod prelude;
mod wrapper;

View file

@ -101,10 +101,7 @@ impl MultiLineTextFieldBuilder {
multi_line_text_field.text_changed_exec.set_callback({
let weak_tf = Arc::downgrade(&multi_line_text_field);
move |_world: &mut World,
_commands: &mut Commands,
gui_handler: &mut GuiHandler,
_text| {
move |_commands: &mut Commands, gui_handler: &mut GuiHandler, _text| {
if let Some(tf) = weak_tf.upgrade() {
tf.update_text(gui_handler)?;
}

View file

@ -172,8 +172,7 @@ impl TextField {
where
F: Fn(&mut Commands, &mut GuiHandler, Option<String>) -> Result<()> + Send + Sync + 'static,
{
todo!()
// self.text_changed_executable.set_callback(f);
self.text_changed_executable.set_callback(f);
}
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {

View file

@ -9,11 +9,8 @@ use crate::prelude::*;
/// `Executable` holds a closure which can be executed
pub struct Executable<I: Send + Sync> {
callback: RwLock<
Option<
Arc<dyn Fn(&mut World, &mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync>,
>,
>,
callback:
RwLock<Option<Arc<dyn Fn(&mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync>>>,
}
impl<I: Send + Sync + 'static> Executable<I> {
@ -31,7 +28,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 World, &mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync + 'static,
F: Fn(&mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync + 'static,
{
let mut function = self.callback.write().unwrap();
@ -46,8 +43,8 @@ impl<I: Send + Sync + 'static> Executable<I> {
if let Some(callback) = self.callback.read().unwrap().as_ref() {
let callback = callback.clone();
gui_handler.add_callback(move |world, commands, gui_handler| {
(callback)(world, commands, gui_handler, input)
gui_handler.add_callback(move |commands, gui_handler| {
(callback)(commands, gui_handler, input)
});
}

View file

@ -245,9 +245,7 @@ pub struct GuiHandler {
text_sample_count: VkSampleCountFlags,
callback_list: Vec<
Box<dyn FnOnce(&mut World, &mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
>,
callback_list: Vec<Box<dyn FnOnce(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>>,
}
impl GuiHandler {
@ -929,7 +927,7 @@ impl GuiHandler {
}
pub(crate) fn add_callback<
F: FnOnce(&mut World, &mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
F: FnOnce(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
>(
&mut self,
f: F,
@ -937,17 +935,12 @@ impl GuiHandler {
self.callback_list.push(Box::new(f));
}
pub fn process_callbacks(&mut self, world: &mut World) -> Result<()> {
pub fn process_callbacks(&mut self, commands: &mut Commands) -> Result<()> {
let callbacks = mem::take(&mut self.callback_list);
let mut commands = Commands::new(world.now());
callbacks
.into_iter()
.try_for_each(|callback| callback(world, &mut commands, self))?;
commands.apply_deferred(world);
Ok(())
.try_for_each(|callback| callback(commands, self))
}
fn render(

View file

@ -376,20 +376,19 @@ impl Keyboard {
let weak_textfield = Arc::downgrade(&textfield);
let weak_button = Arc::downgrade(&button_ref);
todo!();
// button_ref.set_callback(Box::new(
// move |_world: &mut World, _commands: &mut Commands, gui_handler: &mut GuiHandler| {
// if let Some(textfield) = weak_textfield.upgrade() {
// if let Some(button) = weak_button.upgrade() {
// if let Some(text) = button.text()? {
// textfield.add_letter(gui_handler, text.as_bytes()[0] as char)?;
// }
// }
// }
button_ref.set_callback(Box::new(
move |_commands: &mut Commands, gui_handler: &mut GuiHandler| {
if let Some(textfield) = weak_textfield.upgrade() {
if let Some(button) = weak_button.upgrade() {
if let Some(text) = button.text()? {
textfield.add_letter(gui_handler, text.as_bytes()[0] as char)?;
}
}
}
// Ok(())
// },
// ));
Ok(())
},
));
Ok(())
}

View file

@ -3,8 +3,9 @@ mod update;
use update::update;
use proc_macro::TokenStream;
use quote::quote;
use syn::{
LitInt, Result,
DeriveInput, LitInt, Result,
parse::{Parse, ParseStream},
parse_macro_input,
token::Comma,
@ -29,7 +30,7 @@ impl Parse for UpdateInfo {
}
#[proc_macro]
pub fn implement_callbacks(input: TokenStream) -> TokenStream {
pub fn implement_updates(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as UpdateInfo);
update(input.max_components, input.max_resources)

View file

@ -1,6 +1,4 @@
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use update_macro_base::*;
fn resource_only_events_and_systems(update: &Update) -> TokenStream2 {
@ -13,7 +11,7 @@ fn resource_only_events_and_systems(update: &Update) -> TokenStream2 {
let resource_store = &resource_tokens.resource_store;
let resource_idents = &resource_tokens.resource_idents;
quote! {}
todo!()
}
fn events_and_systems(update: &Update) -> TokenStream2 {
@ -42,77 +40,29 @@ fn events_and_systems(update: &Update) -> TokenStream2 {
let resource_store = &resource_tokens.resource_store;
let resource_idents = &resource_tokens.resource_idents;
quote! {
impl<Func, #filter_type_impls #query_type_impls #resource_type_impls> SetCallback<#query_types, #resource_types, Func, #filter_types> for Button
where
Func: Fn(&mut Commands, &mut GuiHandler, #( #queries, )* #resources ) -> Result<()> + Send + Sync + 'static,
#filter_requirements
#component_requirements
#resource_requirement
{
fn set_callback(&self, func: Func) {
#( #verify_dedup )*
self.click_executable.set_callback(
move |world: &mut World, commands: &mut Commands, gui_handler: &mut GuiHandler, _: ()| -> Result<()> {
let mut complying_entities: Vec<Vec<&EntityObject>> = vec![Vec::new(); #query_count];
for entity in unsafe { utilities::prelude::remove_life_time(world).entities() } {
let mut comply_queries = Vec::new();
#( #check_entities )*
if !comply_queries.is_empty() {
comply_queries
.into_iter()
.for_each(|q| complying_entities[q].push(entity));
}
}
// check if one of the queries could not be fullfilled
for queryable_entities in complying_entities.iter() {
if queryable_entities.is_empty() {
return Ok(());
}
}
#resource_store
for entities in complying_entities.into_iter().multi_cartesian_product() {
#( #component_stores )*
#( #query_structs )*
func(commands, gui_handler, #( #query_idents, )* #( #resource_idents, )*)?;
}
Ok(())
}
)
}
}
}
todo!()
}
pub fn update(max_components: usize, max_resources: usize) -> TokenStream {
fn update(max_components: usize, max_resources: usize) -> TokenStream2 {
let mut queries: Vec<Vec<usize>> = Vec::new();
for c in Update::MIN_COMPONENTS..=max_components {
queries.push(vec![c]);
}
// for x in Update::MIN_COMPONENTS..=max_components {
// for y in Update::MIN_COMPONENTS..=max_components {
// queries.push(vec![x, y]);
// }
// }
for x in Update::MIN_COMPONENTS..=max_components {
for y in Update::MIN_COMPONENTS..=max_components {
queries.push(vec![x, y]);
}
}
// for x in Update::MIN_COMPONENTS..=max_components {
// for y in Update::MIN_COMPONENTS..=max_components {
// for z in Update::MIN_COMPONENTS..=max_components {
// queries.push(vec![x, y, z]);
// }
// }
// }
for x in Update::MIN_COMPONENTS..=max_components {
for y in Update::MIN_COMPONENTS..=max_components {
for z in Update::MIN_COMPONENTS..=max_components {
queries.push(vec![x, y, z]);
}
}
}
let mut resources = Vec::new();
@ -140,18 +90,16 @@ pub fn update(max_components: usize, max_resources: usize) -> TokenStream {
events.push(q);
}
// updates.push(events_and_systems(&Update::new(vec![2].into_iter(), 0)));
// updates.push(Update::new(vec![1].into_iter(), 0));
// let q = quote! {
// #( #updates )*
// };
let q = quote! {
// panic!("{q}");
TokenStream::from(quote! {
#( #updates )*
#( #events )*
};
panic!("{q}");
TokenStream::from(q)
})
}