mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-04 07:08:53 +00:00
feat: stateless action macro
This commit is contained in:
parent
2272f02fa3
commit
7535a834f9
2 changed files with 38 additions and 46 deletions
|
@ -36,7 +36,7 @@ use crate::ui::build_window::BuildWindowMsg;
|
||||||
use crate::ui::debug_view::DebugViewInit;
|
use crate::ui::debug_view::DebugViewInit;
|
||||||
use crate::ui::libsurvive_setup_window::LibsurviveSetupMsg;
|
use crate::ui::libsurvive_setup_window::LibsurviveSetupMsg;
|
||||||
use crate::ui::main_view::{MainView, MainViewInit, MainViewOutMsg};
|
use crate::ui::main_view::{MainView, MainViewInit, MainViewOutMsg};
|
||||||
use crate::withclones;
|
use crate::{withclones, stateless_action};
|
||||||
use crate::xr_devices::XRDevices;
|
use crate::xr_devices::XRDevices;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use relm4::actions::{AccelsPlus, ActionGroupName, RelmAction, RelmActionGroup};
|
use relm4::actions::{AccelsPlus, ActionGroupName, RelmAction, RelmActionGroup};
|
||||||
|
@ -596,71 +596,56 @@ impl SimpleComponent for App {
|
||||||
|
|
||||||
let mut actions = RelmActionGroup::<AppActionGroup>::new();
|
let mut actions = RelmActionGroup::<AppActionGroup>::new();
|
||||||
|
|
||||||
let buildprofile_action = {
|
{
|
||||||
withclones![sender];
|
withclones![sender];
|
||||||
RelmAction::<BuildProfileAction>::new_stateless(move |_| {
|
stateless_action!(actions, BuildProfileAction, {
|
||||||
sender.input_sender().emit(Msg::BuildProfile(false));
|
sender.input_sender().emit(Msg::BuildProfile(false));
|
||||||
})
|
});
|
||||||
};
|
}
|
||||||
|
{
|
||||||
let buildprofileclean_action = {
|
|
||||||
withclones![sender];
|
withclones![sender];
|
||||||
RelmAction::<BuildProfileCleanAction>::new_stateless(move |_| {
|
stateless_action!(actions, BuildProfileCleanAction, {
|
||||||
sender.input_sender().emit(Msg::BuildProfile(true));
|
sender.input_sender().emit(Msg::BuildProfile(true));
|
||||||
})
|
});
|
||||||
};
|
}
|
||||||
|
{
|
||||||
let about_action = {
|
|
||||||
let abd_sender = model.about_dialog.sender().clone();
|
let abd_sender = model.about_dialog.sender().clone();
|
||||||
RelmAction::<AboutAction>::new_stateless(move |_| {
|
stateless_action!(actions, AboutAction, {
|
||||||
abd_sender.send(()).unwrap();
|
abd_sender.send(()).unwrap();
|
||||||
})
|
});
|
||||||
};
|
}
|
||||||
|
{
|
||||||
let libsurvive_setup_action = {
|
|
||||||
withclones![sender];
|
withclones![sender];
|
||||||
RelmAction::<LibsurviveSetupAction>::new_stateless(move |_| {
|
stateless_action!(actions, LibsurviveSetupAction, {
|
||||||
sender.input(Msg::OpenLibsurviveSetup);
|
sender.input(Msg::OpenLibsurviveSetup);
|
||||||
})
|
});
|
||||||
};
|
}
|
||||||
|
{
|
||||||
let quit_action = {
|
|
||||||
withclones![sender];
|
withclones![sender];
|
||||||
RelmAction::<QuitAction>::new_stateless(move |_| {
|
stateless_action!(actions, QuitAction, {
|
||||||
sender.input(Msg::Quit);
|
sender.input(Msg::Quit);
|
||||||
})
|
});
|
||||||
};
|
}
|
||||||
|
{
|
||||||
let debug_view_toggle_action: RelmAction<DebugViewToggleAction> = {
|
|
||||||
withclones![sender];
|
withclones![sender];
|
||||||
RelmAction::<DebugViewToggleAction>::new_stateful(
|
actions.add_action(RelmAction::<DebugViewToggleAction>::new_stateful(
|
||||||
&model.enable_debug_view,
|
&model.enable_debug_view,
|
||||||
move |_, state| {
|
move |_, state| {
|
||||||
let s = *state;
|
let s = *state;
|
||||||
*state = !s;
|
*state = !s;
|
||||||
sender.input(Msg::EnableDebugViewChanged(*state));
|
sender.input(Msg::EnableDebugViewChanged(*state));
|
||||||
},
|
},
|
||||||
)
|
))
|
||||||
};
|
}
|
||||||
|
|
||||||
actions.add_action(about_action);
|
|
||||||
actions.add_action(quit_action);
|
|
||||||
actions.add_action(buildprofile_action);
|
|
||||||
actions.add_action(buildprofileclean_action);
|
|
||||||
actions.add_action(debug_view_toggle_action);
|
|
||||||
actions.add_action(libsurvive_setup_action);
|
|
||||||
|
|
||||||
root.insert_action_group(AppActionGroup::NAME, Some(&actions.into_action_group()));
|
root.insert_action_group(AppActionGroup::NAME, Some(&actions.into_action_group()));
|
||||||
|
|
||||||
model
|
{
|
||||||
.application
|
let app = &model.application;
|
||||||
.set_accelerators_for_action::<QuitAction>(&["<Control>q"]);
|
app.set_accelerators_for_action::<QuitAction>(&["<Control>q"]);
|
||||||
model
|
app.set_accelerators_for_action::<BuildProfileAction>(&["F5"]);
|
||||||
.application
|
app.set_accelerators_for_action::<BuildProfileCleanAction>(&["<Control>F5"]);
|
||||||
.set_accelerators_for_action::<BuildProfileAction>(&["F5"]);
|
}
|
||||||
model
|
|
||||||
.application
|
|
||||||
.set_accelerators_for_action::<BuildProfileCleanAction>(&["<Control>F5"]);
|
|
||||||
|
|
||||||
model.main_view.sender().emit(MainViewMsg::UpdateProfiles(
|
model.main_view.sender().emit(MainViewMsg::UpdateProfiles(
|
||||||
model.profiles.clone(),
|
model.profiles.clone(),
|
||||||
|
|
|
@ -4,3 +4,10 @@ macro_rules! withclones {
|
||||||
$(let $var = $var.clone();)+
|
$(let $var = $var.clone();)+
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! stateless_action {
|
||||||
|
($group:ident, $name:ident, $ex:expr) => {
|
||||||
|
$group.add_action(RelmAction::<$name>::new_stateless(move |_| $ex));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue