Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appcui-proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "appcui_proc_macro"
version = "0.2.5"
version = "0.2.6"
edition = "2021"
authors = ["Gavrilut Dragos <[email protected]>"]
description = "Procedural macros for the AppCUI TUI framework."
Expand Down
2 changes: 1 addition & 1 deletion appcui-proc-macro/src/controls/graphview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::control_builder::ControlBuilder;
use crate::parameter_parser::*;
use proc_macro::*;

static FLAGS: FlagsSignature = FlagsSignature::new(&["ScrollBars", "SearchBar"]);
static FLAGS: FlagsSignature = FlagsSignature::new(&["ScrollBars", "SearchBar", "MultiSelect"]);

static POSILITIONAL_PARAMETERS: &[PositionalParameter] = &[];
static NAMED_PARAMETERS: &[NamedParameter] = &[
Expand Down
13 changes: 11 additions & 2 deletions appcui-proc-macro/src/procmacro_builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,25 @@ fn generate_graphview_events(a: &mut Arguments) -> String {
}
let mut on_current_node_changed_code = String::new();
let mut on_node_action_code = String::new();
let mut on_request_new_node_code = String::new();
let mut on_request_new_edge_code = String::new();
let mut on_selection_changed_code = String::new();
for trait_name in a.template_events[&AppCUITrait::GenericGraphViewEvents].iter() {
on_current_node_changed_code.push_str(templates::GRAPHVIEW_ON_CURRENT_NODE_CHANGED_DEF.replace("$(TYPE)", trait_name).as_str());
on_node_action_code.push_str(templates::GRAPHVIEW_ON_NODE_ACTION_DEF.replace("$(TYPE)", trait_name).as_str());
on_request_new_node_code.push_str(templates::GRAPHVIEW_ON_REQUEST_NEW_NODE_DEF.replace("$(TYPE)", trait_name).as_str());
on_request_new_edge_code.push_str(templates::GRAPHVIEW_ON_REQUEST_NEW_EDGE_DEF.replace("$(TYPE)", trait_name).as_str());
on_selection_changed_code.push_str(templates::GRAPHVIEW_ON_SELECTION_CHANGED_DEF.replace("$(TYPE)", trait_name).as_str());
}
templates::GRAPHVIEW_TRAIT_DEF
.replace(
"$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_CURRENT_NODE_CHANGED)",
&on_current_node_changed_code,
)
.replace("$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_NODE_ACTION)", &on_node_action_code)
.replace("$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_REQUEST_NEW_NODE)", &on_request_new_node_code)
.replace("$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_REQUEST_NEW_EDGE)", &on_request_new_edge_code)
.replace("$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_SELECTION_CHANGED)", &on_selection_changed_code)
}

fn generate_backgroundtask_events(a: &mut Arguments) -> String {
Expand Down Expand Up @@ -291,7 +300,7 @@ pub(crate) fn build(args: TokenStream, input: TokenStream, base_control: BaseCon
AppCUITrait::GenericNumericSelectorEvents => code.push_str(generate_numeric_selector_events(&mut a).as_str()),
AppCUITrait::GenericListViewEvents => code.push_str(generate_listview_events(&mut a).as_str()),
AppCUITrait::GenericTreeViewEvents => code.push_str(generate_treeview_events(&mut a).as_str()),
AppCUITrait::GenericBackgroundTaskEvents=> code.push_str(generate_backgroundtask_events(&mut a).as_str()),
AppCUITrait::GenericBackgroundTaskEvents => code.push_str(generate_backgroundtask_events(&mut a).as_str()),
AppCUITrait::GenericGraphViewEvents => code.push_str(generate_graphview_events(&mut a).as_str()),
_ => {}
}
Expand Down Expand Up @@ -319,7 +328,7 @@ pub(crate) fn build(args: TokenStream, input: TokenStream, base_control: BaseCon
// add the MenudBar events wrapper if needed
if config.get(AppCUITrait::MenuEvents) == TraitImplementation::None {
code.push_str(templates::MENU_EVENTS);
}
}
// add raise events support
if !a.emitted_events.is_empty() {
code.push_str(templates::RAISE_EVENTS_TEMPLATE);
Expand Down
44 changes: 44 additions & 0 deletions appcui-proc-macro/src/procmacro_builder/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ if std::any::TypeId::of::<$(TYPE)>() == type_id {
}
";

pub(crate) static GRAPHVIEW_ON_REQUEST_NEW_NODE_DEF: &str = "
if std::any::TypeId::of::<$(TYPE)>() == type_id {
let h: Handle<GraphView<$(TYPE)>> = unsafe { handle.unsafe_cast() };
return GraphViewEvents::<$(TYPE)>::on_request_new_node(self, h, point);
}
";

pub(crate) static GRAPHVIEW_ON_REQUEST_NEW_EDGE_DEF: &str = "
if std::any::TypeId::of::<$(TYPE)>() == type_id {
let h: Handle<GraphView<$(TYPE)>> = unsafe { handle.unsafe_cast() };
return GraphViewEvents::<$(TYPE)>::on_request_new_edge(self, h, from, to);
}
";

pub(crate) static GRAPHVIEW_ON_SELECTION_CHANGED_DEF: &str = "
if std::any::TypeId::of::<$(TYPE)>() == type_id {
let h: Handle<GraphView<$(TYPE)>> = unsafe { handle.unsafe_cast() };
return GraphViewEvents::<$(TYPE)>::on_selection_changed(self, h);
}
";

pub(crate) static GRAPHVIEW_TRAIT_DEF: &str = "
trait GraphViewEvents<T: graphview::GraphNode+'static> {
fn on_current_node_changed(&mut self, handle: Handle<GraphView<T>>) -> EventProcessStatus {
Expand All @@ -412,6 +433,15 @@ trait GraphViewEvents<T: graphview::GraphNode+'static> {
fn on_node_action(&mut self, handle: Handle<GraphView<T>>, item_index: usize) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_request_new_node(&mut self, handle: Handle<GraphView<T>>, point: Point) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_request_new_edge(&mut self, handle: Handle<GraphView<T>>, from: u32, to: u32) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_selection_changed(&mut self, handle: Handle<GraphView<T>>) -> EventProcessStatus {
EventProcessStatus::Ignored
}
}
impl$(TEMPLATE_TYPE) GenericGraphViewEvents for $(STRUCT_NAME)$(TEMPLATE_DEF) {

Expand All @@ -425,6 +455,20 @@ impl$(TEMPLATE_TYPE) GenericGraphViewEvents for $(STRUCT_NAME)$(TEMPLATE_DEF) {
return EventProcessStatus::Ignored;
}

fn on_request_new_node(&mut self, handle: Handle<()>, type_id: std::any::TypeId, point: Point) -> EventProcessStatus {
$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_REQUEST_NEW_NODE)
return EventProcessStatus::Ignored;
}

fn on_request_new_edge(&mut self, handle: Handle<()>, type_id: std::any::TypeId, from: u32, to: u32) -> EventProcessStatus {
$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_REQUEST_NEW_EDGE)
return EventProcessStatus::Ignored;
}

fn on_selection_changed(&mut self, handle: Handle<()>, type_id: std::any::TypeId) -> EventProcessStatus {
$(TYPE_ID_TRANSLATION_FOR_GRAPHVIEW_ON_SELECTION_CHANGED)
return EventProcessStatus::Ignored;
}
}
";

Expand Down
4 changes: 2 additions & 2 deletions appcui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ categories = ["gui", "command-line-interface", "command-line-utilities"]
EnumBitFlags = "1.0.10"
flat_string = "1.0.0"
chrono = {version = "0.4.38", features = ["wasmbind"]}
appcui_proc_macro = "0.2.5"
# appcui_proc_macro = { path = "../appcui-proc-macro" }
# appcui_proc_macro = "0.2.5"
appcui_proc_macro = { path = "../appcui-proc-macro" }

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
9 changes: 9 additions & 0 deletions appcui/src/ui/common/control_event_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ impl ControlEvent {
graphview::events::GraphViewEventTypes::NodeAction(index) => {
GenericGraphViewEvents::on_node_action(receiver, self.emitter.cast(), data.type_id, index)
}
graphview::events::GraphViewEventTypes::RequestNewNode(p) => {
GenericGraphViewEvents::on_request_new_node(receiver, self.emitter.cast(), data.type_id, p)
}
graphview::events::GraphViewEventTypes::RequestNewEdge(from, to) => {
GenericGraphViewEvents::on_request_new_edge(receiver, self.emitter.cast(), data.type_id, from, to)
}
graphview::events::GraphViewEventTypes::SelectionChanged => {
GenericGraphViewEvents::on_selection_changed(receiver, self.emitter.cast(), data.type_id)
}
},
}
}
Expand Down
14 changes: 13 additions & 1 deletion appcui/src/ui/graphview/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::any::TypeId;
use crate::{system::Handle, ui::common::traits::EventProcessStatus};
use crate::{prelude::Point, system::Handle, ui::common::traits::EventProcessStatus};

pub trait GenericGraphViewEvents {
fn on_current_node_changed(&mut self, _handle: Handle<()>, _type_id: TypeId) -> EventProcessStatus {
Expand All @@ -8,11 +8,23 @@ pub trait GenericGraphViewEvents {
fn on_node_action(&mut self, _handle: Handle<()>, _type_id: TypeId, _node_index: usize) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_request_new_node(&mut self, _handle: Handle<()>, _type_id: TypeId, _p: Point) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_request_new_edge(&mut self, _handle: Handle<()>, _type_id: TypeId, _from: u32, _to: u32) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_selection_changed(&mut self, _handle: Handle<()>, _type_id: TypeId) -> EventProcessStatus {
EventProcessStatus::Ignored
}
}
#[derive(Copy,Clone)]
pub(crate) enum GraphViewEventTypes {
CurrentNodeChanged,
NodeAction(usize),
RequestNewNode(Point),
RequestNewEdge(u32, u32),
SelectionChanged,
}

#[derive(Copy, Clone)]
Expand Down
Loading
Loading