Compare commits
1 commit
492d57b856
...
86be46a050
Author | SHA1 | Date | |
---|---|---|---|
86be46a050 |
13 changed files with 76 additions and 169 deletions
|
@ -10,15 +10,12 @@ serde = { version = "1.0.203", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.120" }
|
serde_json = { version = "1.0.120" }
|
||||||
paste = "1.0.15"
|
paste = "1.0.15"
|
||||||
anyhow = { version = "1.0.86", features = ["backtrace"] }
|
anyhow = { version = "1.0.86", features = ["backtrace"] }
|
||||||
itertools = "0.14.0"
|
|
||||||
|
|
||||||
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||||
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
|
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
|
||||||
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||||
ecs = { git = "https://gavania.de/hodasemi/ecs.git" }
|
ecs = { git = "https://gavania.de/hodasemi/ecs.git" }
|
||||||
|
|
||||||
ui_proc_macro = { path = "../ui_proc_macro" }
|
|
||||||
|
|
||||||
# optional
|
# optional
|
||||||
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
||||||
|
|
||||||
|
|
|
@ -203,8 +203,7 @@ impl Functionality for GuiBuilder {
|
||||||
let suffix_less_function_name = handle_function_suffix(function_name);
|
let suffix_less_function_name = handle_function_suffix(function_name);
|
||||||
|
|
||||||
let button: Arc<Button> = self.element(&suffix_less_function_name)?;
|
let button: Arc<Button> = self.element(&suffix_less_function_name)?;
|
||||||
todo!()
|
button.set_callback(callback);
|
||||||
// button.set_callback(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -181,8 +181,7 @@ impl Functionality for GuiSnippet {
|
||||||
let suffix_less_function_name = handle_function_suffix(function_name);
|
let suffix_less_function_name = handle_function_suffix(function_name);
|
||||||
|
|
||||||
let button: Arc<Button> = self.element(&suffix_less_function_name)?;
|
let button: Arc<Button> = self.element(&suffix_less_function_name)?;
|
||||||
todo!()
|
button.set_callback(callback);
|
||||||
// button.set_callback(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -271,9 +271,9 @@ pub struct Button {
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
_hover_sound: Option<Arc<Audible>>,
|
_hover_sound: Option<Arc<Audible>>,
|
||||||
|
|
||||||
pub(crate) click_executable: Arc<Executable<()>>,
|
click_executable: Arc<Executable<()>>,
|
||||||
pub(crate) select_executable: Arc<Executable<bool>>,
|
select_executable: Arc<Executable<bool>>,
|
||||||
pub(crate) on_select_executable: Arc<Executable<bool>>,
|
on_select_executable: Arc<Executable<bool>>,
|
||||||
|
|
||||||
normal: FillType,
|
normal: FillType,
|
||||||
selected: FillType,
|
selected: FillType,
|
||||||
|
@ -313,23 +313,26 @@ impl Button {
|
||||||
self.selectable.select(gui_handler)
|
self.selectable.select(gui_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn set_callback<F>(&self, callback: F)
|
pub fn set_callback<F>(&self, callback: F)
|
||||||
// where
|
where
|
||||||
// F: Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
|
F: Fn(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync + 'static,
|
||||||
// {
|
{
|
||||||
// self.click_executable.set_callback(
|
self.click_executable.set_callback(
|
||||||
// move |commands: &mut Commands, gui_handler: &mut GuiHandler, _: ()| {
|
move |commands: &mut Commands, gui_handler: &mut GuiHandler, _: ()| {
|
||||||
// callback(commands, gui_handler)
|
callback(commands, gui_handler)
|
||||||
// },
|
},
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
pub fn set_select_callback<F>(&self, callback: F)
|
pub fn set_select_callback<F>(&self, callback: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync + 'static,
|
F: Fn(&mut Commands, &mut GuiHandler, bool) -> Result<()> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
todo!()
|
self.on_select_executable.set_callback(
|
||||||
// self.on_select_executable.set_callback(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)
|
pub fn set_custom_callback<F>(&self, callback: F)
|
||||||
|
@ -590,10 +593,8 @@ impl Button {
|
||||||
fn create_selected_changed_callback(button: Arc<Button>) {
|
fn create_selected_changed_callback(button: Arc<Button>) {
|
||||||
let button_weak = Arc::downgrade(&button);
|
let button_weak = Arc::downgrade(&button);
|
||||||
|
|
||||||
let selected_changed = move |_world: &mut World,
|
let selected_changed =
|
||||||
_commands: &mut Commands,
|
move |_commands: &mut Commands, gui_handler: &mut GuiHandler, selected: bool| {
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
selected: bool| {
|
|
||||||
if let Some(button) = button_weak.upgrade() {
|
if let Some(button) = button_weak.upgrade() {
|
||||||
if selected {
|
if selected {
|
||||||
button.set_button_state(gui_handler, ButtonState::Selected)?;
|
button.set_button_state(gui_handler, ButtonState::Selected)?;
|
||||||
|
|
|
@ -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);
|
|
|
@ -18,7 +18,6 @@ pub mod ui_element;
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
|
|
||||||
mod callback_builder;
|
mod callback_builder;
|
||||||
pub mod callback_impl;
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod wrapper;
|
mod wrapper;
|
||||||
|
|
||||||
|
|
|
@ -101,10 +101,7 @@ impl MultiLineTextFieldBuilder {
|
||||||
multi_line_text_field.text_changed_exec.set_callback({
|
multi_line_text_field.text_changed_exec.set_callback({
|
||||||
let weak_tf = Arc::downgrade(&multi_line_text_field);
|
let weak_tf = Arc::downgrade(&multi_line_text_field);
|
||||||
|
|
||||||
move |_world: &mut World,
|
move |_commands: &mut Commands, gui_handler: &mut GuiHandler, _text| {
|
||||||
_commands: &mut Commands,
|
|
||||||
gui_handler: &mut GuiHandler,
|
|
||||||
_text| {
|
|
||||||
if let Some(tf) = weak_tf.upgrade() {
|
if let Some(tf) = weak_tf.upgrade() {
|
||||||
tf.update_text(gui_handler)?;
|
tf.update_text(gui_handler)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,8 +172,7 @@ impl TextField {
|
||||||
where
|
where
|
||||||
F: Fn(&mut Commands, &mut GuiHandler, Option<String>) -> Result<()> + Send + Sync + 'static,
|
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<()> {
|
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||||
|
|
|
@ -9,11 +9,8 @@ use crate::prelude::*;
|
||||||
|
|
||||||
/// `Executable` holds a closure which can be executed
|
/// `Executable` holds a closure which can be executed
|
||||||
pub struct Executable<I: Send + Sync> {
|
pub struct Executable<I: Send + Sync> {
|
||||||
callback: RwLock<
|
callback:
|
||||||
Option<
|
RwLock<Option<Arc<dyn Fn(&mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync>>>,
|
||||||
Arc<dyn Fn(&mut World, &mut Commands, &mut GuiHandler, I) -> Result<()> + Send + Sync>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Send + Sync + 'static> Executable<I> {
|
impl<I: Send + Sync + 'static> Executable<I> {
|
||||||
|
@ -31,7 +28,7 @@ impl<I: Send + Sync + 'static> Executable<I> {
|
||||||
/// * `callback` is a `Option<Callback>` closure
|
/// * `callback` is a `Option<Callback>` closure
|
||||||
pub fn set_callback<F>(&self, callback: impl Into<Option<F>>)
|
pub fn set_callback<F>(&self, callback: impl Into<Option<F>>)
|
||||||
where
|
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();
|
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() {
|
if let Some(callback) = self.callback.read().unwrap().as_ref() {
|
||||||
let callback = callback.clone();
|
let callback = callback.clone();
|
||||||
|
|
||||||
gui_handler.add_callback(move |world, commands, gui_handler| {
|
gui_handler.add_callback(move |commands, gui_handler| {
|
||||||
(callback)(world, commands, gui_handler, input)
|
(callback)(commands, gui_handler, input)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,9 +245,7 @@ pub struct GuiHandler {
|
||||||
|
|
||||||
text_sample_count: VkSampleCountFlags,
|
text_sample_count: VkSampleCountFlags,
|
||||||
|
|
||||||
callback_list: Vec<
|
callback_list: Vec<Box<dyn FnOnce(&mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>>,
|
||||||
Box<dyn FnOnce(&mut World, &mut Commands, &mut GuiHandler) -> Result<()> + Send + Sync>,
|
|
||||||
>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuiHandler {
|
impl GuiHandler {
|
||||||
|
@ -929,7 +927,7 @@ impl GuiHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_callback<
|
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,
|
&mut self,
|
||||||
f: F,
|
f: F,
|
||||||
|
@ -937,17 +935,12 @@ impl GuiHandler {
|
||||||
self.callback_list.push(Box::new(f));
|
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 callbacks = mem::take(&mut self.callback_list);
|
||||||
let mut commands = Commands::new(world.now());
|
|
||||||
|
|
||||||
callbacks
|
callbacks
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_for_each(|callback| callback(world, &mut commands, self))?;
|
.try_for_each(|callback| callback(commands, self))
|
||||||
|
|
||||||
commands.apply_deferred(world);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(
|
fn render(
|
||||||
|
|
|
@ -376,20 +376,19 @@ impl Keyboard {
|
||||||
let weak_textfield = Arc::downgrade(&textfield);
|
let weak_textfield = Arc::downgrade(&textfield);
|
||||||
let weak_button = Arc::downgrade(&button_ref);
|
let weak_button = Arc::downgrade(&button_ref);
|
||||||
|
|
||||||
todo!();
|
button_ref.set_callback(Box::new(
|
||||||
// button_ref.set_callback(Box::new(
|
move |_commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
||||||
// move |_world: &mut World, _commands: &mut Commands, gui_handler: &mut GuiHandler| {
|
if let Some(textfield) = weak_textfield.upgrade() {
|
||||||
// if let Some(textfield) = weak_textfield.upgrade() {
|
if let Some(button) = weak_button.upgrade() {
|
||||||
// if let Some(button) = weak_button.upgrade() {
|
if let Some(text) = button.text()? {
|
||||||
// if let Some(text) = button.text()? {
|
textfield.add_letter(gui_handler, text.as_bytes()[0] as char)?;
|
||||||
// textfield.add_letter(gui_handler, text.as_bytes()[0] as char)?;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// Ok(())
|
Ok(())
|
||||||
// },
|
},
|
||||||
// ));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ mod update;
|
||||||
use update::update;
|
use update::update;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
use syn::{
|
use syn::{
|
||||||
LitInt, Result,
|
DeriveInput, LitInt, Result,
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
parse_macro_input,
|
parse_macro_input,
|
||||||
token::Comma,
|
token::Comma,
|
||||||
|
@ -29,7 +30,7 @@ impl Parse for UpdateInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn implement_callbacks(input: TokenStream) -> TokenStream {
|
pub fn implement_updates(input: TokenStream) -> TokenStream {
|
||||||
let input = parse_macro_input!(input as UpdateInfo);
|
let input = parse_macro_input!(input as UpdateInfo);
|
||||||
|
|
||||||
update(input.max_components, input.max_resources)
|
update(input.max_components, input.max_resources)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use proc_macro::TokenStream;
|
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::quote;
|
|
||||||
use update_macro_base::*;
|
use update_macro_base::*;
|
||||||
|
|
||||||
fn resource_only_events_and_systems(update: &Update) -> TokenStream2 {
|
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_store = &resource_tokens.resource_store;
|
||||||
let resource_idents = &resource_tokens.resource_idents;
|
let resource_idents = &resource_tokens.resource_idents;
|
||||||
|
|
||||||
quote! {}
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn events_and_systems(update: &Update) -> TokenStream2 {
|
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_store = &resource_tokens.resource_store;
|
||||||
let resource_idents = &resource_tokens.resource_idents;
|
let resource_idents = &resource_tokens.resource_idents;
|
||||||
|
|
||||||
quote! {
|
todo!()
|
||||||
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
|
fn update(max_components: usize, max_resources: usize) -> TokenStream2 {
|
||||||
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(())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(max_components: usize, max_resources: usize) -> TokenStream {
|
|
||||||
let mut queries: Vec<Vec<usize>> = Vec::new();
|
let mut queries: Vec<Vec<usize>> = Vec::new();
|
||||||
|
|
||||||
for c in Update::MIN_COMPONENTS..=max_components {
|
for c in Update::MIN_COMPONENTS..=max_components {
|
||||||
queries.push(vec![c]);
|
queries.push(vec![c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for x in Update::MIN_COMPONENTS..=max_components {
|
for x in Update::MIN_COMPONENTS..=max_components {
|
||||||
// for y in Update::MIN_COMPONENTS..=max_components {
|
for y in Update::MIN_COMPONENTS..=max_components {
|
||||||
// queries.push(vec![x, y]);
|
queries.push(vec![x, y]);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// for x in Update::MIN_COMPONENTS..=max_components {
|
for x in Update::MIN_COMPONENTS..=max_components {
|
||||||
// for y in Update::MIN_COMPONENTS..=max_components {
|
for y in Update::MIN_COMPONENTS..=max_components {
|
||||||
// for z in Update::MIN_COMPONENTS..=max_components {
|
for z in Update::MIN_COMPONENTS..=max_components {
|
||||||
// queries.push(vec![x, y, z]);
|
queries.push(vec![x, y, z]);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
let mut resources = Vec::new();
|
let mut resources = Vec::new();
|
||||||
|
|
||||||
|
@ -140,18 +90,16 @@ pub fn update(max_components: usize, max_resources: usize) -> TokenStream {
|
||||||
events.push(q);
|
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! {
|
// let q = quote! {
|
||||||
// #( #updates )*
|
// #( #updates )*
|
||||||
// };
|
// };
|
||||||
|
|
||||||
let q = quote! {
|
// panic!("{q}");
|
||||||
|
|
||||||
|
TokenStream::from(quote! {
|
||||||
#( #updates )*
|
#( #updates )*
|
||||||
#( #events )*
|
#( #events )*
|
||||||
};
|
})
|
||||||
|
|
||||||
panic!("{q}");
|
|
||||||
|
|
||||||
TokenStream::from(q)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue