-
Notifications
You must be signed in to change notification settings - Fork 713
NOT FUNCTIONAL: muda
context menu support
#8803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
29e6363
92a37d6
d095406
59f1e73
7a9507f
7a6a588
084d2e4
41f9bf6
12cf3d0
11300e3
086c867
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2764,8 +2764,7 @@ fn compile_builtin_function_call( | |||||
} | ||||||
} | ||||||
BuiltinFunction::ShowPopupMenu => { | ||||||
let [Expression::PropertyReference(context_menu_ref), entries, position, Expression::BoolLiteral(no_native)] = | ||||||
arguments | ||||||
let [Expression::PropertyReference(context_menu_ref), entries, position] = arguments | ||||||
else { | ||||||
panic!("internal error: invalid args to ShowPopupMenu {arguments:?}") | ||||||
}; | ||||||
|
@@ -2836,6 +2835,8 @@ fn compile_builtin_function_call( | |||||
matches!(entries.ty(ctx), Type::Array(ty) if matches!(&*ty, Type::Struct{..})) | ||||||
); | ||||||
let entries = compile_expression(entries, ctx); | ||||||
let inner_component_id = | ||||||
self::inner_component_id(ctx.current_sub_component().unwrap()); | ||||||
let forward_callback = |access, cb| { | ||||||
let call = context_menu | ||||||
.clone() | ||||||
|
@@ -2850,9 +2851,44 @@ fn compile_builtin_function_call( | |||||
}); | ||||||
) | ||||||
}; | ||||||
let fw_sub_menu = forward_callback(access_sub_menu, quote!(sub_menu)); | ||||||
let fw_sub_menu = forward_callback(access_sub_menu.clone(), quote!(sub_menu)); | ||||||
let fw_activated = forward_callback(access_activated, quote!(activated)); | ||||||
quote! { | ||||||
let context_menu_item_tree = if sp::WindowInner::from_pub(#window_adapter_tokens.window()).supports_native_menu_bar() { | ||||||
// May seem overkill to have an instance of the struct for each call, but there should only be one call per component anyway | ||||||
struct ContextMenuWrapper(sp::VWeakMapped<sp::ItemTreeVTable, #inner_component_id>); | ||||||
const _ : () = { | ||||||
use slint::private_unstable_api::re_exports::*; | ||||||
MenuVTable_static!(static VT for ContextMenuWrapper); | ||||||
}; | ||||||
impl sp::Menu for ContextMenuWrapper { | ||||||
fn sub_menu(&self, parent: sp::Option<&sp::MenuEntry>, result: &mut sp::SharedVector<sp::MenuEntry>) { | ||||||
let Some(self_rc) = self.0.upgrade() else { return }; | ||||||
let _self = self_rc.as_pin_ref(); | ||||||
let model = match parent { | ||||||
None => #entries, | ||||||
Some(parent) => { | ||||||
// PROBLEM - how do I wrie this up to the submenu? | ||||||
// #access_sub_menu.call(&(parent.clone(),)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that line should work. Do you get a comilation error there? Same for activate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When uncommenting that on
I get a virtually identical error when uncommenting that on
I assume there is a straight forward way to walk the object hierarchy to get what we want? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the problem, access_sub_menu / access_activated are in the context of the menu. |
||||||
todo!() | ||||||
} | ||||||
}; | ||||||
*result = model.iter().map(|v| v.try_into().unwrap()).collect(); | ||||||
} | ||||||
fn activate(&self, entry: &sp::MenuEntry) { | ||||||
let Some(self_rc) = self.0.upgrade() else { return }; | ||||||
let _self = self_rc.as_pin_ref(); | ||||||
// PROBLEM - how do I wire this up to the activated callback? | ||||||
// #access_activated.call(&(entry.clone(),)) | ||||||
todo!() | ||||||
} | ||||||
} | ||||||
Some(sp::VBox::new(ContextMenuWrapper(_self.self_weak.get().unwrap().clone()))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to do something like that; it wasn't clear what I need to change
|
||||||
} | ||||||
else { | ||||||
None | ||||||
}; | ||||||
|
||||||
let entries = #entries; | ||||||
{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we only need this part when not using the native context menu (fallback) |
||||||
let _self = popup_instance_vrc.as_pin_ref(); | ||||||
|
@@ -2870,24 +2906,15 @@ fn compile_builtin_function_call( | |||||
}; | ||||||
let context_menu = context_menu.unwrap(); | ||||||
|
||||||
let native_impl = if *no_native { | ||||||
quote!() | ||||||
} else { | ||||||
quote!(if sp::WindowInner::from_pub(#window_adapter_tokens.window()).supports_native_menu_bar() { | ||||||
sp::WindowInner::from_pub(#window_adapter_tokens.window()).show_context_menu(sp::VBox::new(popup_instance_menu), #position); | ||||||
} else) | ||||||
}; | ||||||
|
||||||
quote!({ | ||||||
let position = #position; | ||||||
let popup_instance = #popup_id::new(_self.globals.get().unwrap().clone()).unwrap(); | ||||||
let popup_instance_vrc = sp::VRc::map(popup_instance.clone(), |x| x); | ||||||
{ | ||||||
let parent_weak = _self.self_weak.get().unwrap().clone(); | ||||||
#init_popup | ||||||
let popup_instance_menu = sp::ContextMenuFromItemTree::new(sp::VRc::into_dyn(popup_instance.clone()), entries.clone()); | ||||||
#native_impl | ||||||
/* else */ { | ||||||
|
||||||
if !sp::WindowInner::from_pub(#window_adapter_tokens.window()).show_native_popup_menu(context_menu_item_tree.unwrap(), #position) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the .unwrap() here seems bad, as it would panic when supports_native_menu_bar returns false. |
||||||
#close_popup | ||||||
let id = sp::WindowInner::from_pub(#window_adapter_tokens.window()).show_popup( | ||||||
&sp::VRc::into_dyn(popup_instance.into()), | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.