pub trait WidgetActionsApi {
// Required methods
fn widget(&self, path: &[LiveId]) -> WidgetRef;
fn widget_action(&self, path: &[LiveId]) -> Option<&WidgetAction>;
fn find_widget_action_cast<T>(&self, widget_uid: WidgetUid) -> T
where T: Default + Clone + WidgetActionTrait;
fn find_widget_action(&self, widget_uid: WidgetUid) -> Option<&WidgetAction>;
fn filter_widget_actions(
&self,
widget_uid: WidgetUid,
) -> impl Iterator<Item = &WidgetAction>;
fn filter_widget_actions_cast<T>(
&self,
widget_uid: WidgetUid,
) -> impl Iterator<Item = T>
where T: Default + Clone + WidgetActionTrait;
fn filter_actions_data<T>(&self) -> impl Iterator<Item = &T>
where T: Clone + ActionTrait;
fn filter_widget_actions_set(
&self,
set: &WidgetSet,
) -> impl Iterator<Item = &WidgetAction>;
}
Required Methods§
fn widget(&self, path: &[LiveId]) -> WidgetRef
fn widget_action(&self, path: &[LiveId]) -> Option<&WidgetAction>
fn find_widget_action_cast<T>(&self, widget_uid: WidgetUid) -> T
fn find_widget_action(&self, widget_uid: WidgetUid) -> Option<&WidgetAction>
Sourcefn filter_widget_actions(
&self,
widget_uid: WidgetUid,
) -> impl Iterator<Item = &WidgetAction>
fn filter_widget_actions( &self, widget_uid: WidgetUid, ) -> impl Iterator<Item = &WidgetAction>
§Filter all actions by widget uid
this function use to filter all actions from Event::Actions(actions)
,
if multi actions in same widget may happened in the same time, this function will help you get all
and back an Iter
§Attention
If you want to focus on target actions and need to cast directly use filter_widget_action_cast
§Examples
§find and directly do target action without param
you can filter_widget_actions
and then do find to get target action you want,
then do map to do want you what
let actions = cx.capture_actions(|cx| self.super_widget.handle_event(cx, event, scope));
self.gbutton(id!(auto_connect)).borrow().map(|x| {
let mut actions = actions.filter_widget_actions(x.widget_uid());
actions.find(|action| {
if let GButtonEvent::Clicked(_) = action.cast(){
true
}else{
false
}
}).map(|action|{
dbg!(action);
});
});
§find and cast
let actions = cx.capture_actions(|cx| self.super_widget.handle_event(cx, event, scope));
self.gbutton(id!(auto_connect)).borrow().map(|x| {
let actions = actions.filter_widget_actions(x.widget_uid());
actions.for_each(|action| {
if let GButtonEvent::Clicked(param) = action.cast(){
dbg!(param);
}
})
});
Sourcefn filter_widget_actions_cast<T>(
&self,
widget_uid: WidgetUid,
) -> impl Iterator<Item = T>
fn filter_widget_actions_cast<T>( &self, widget_uid: WidgetUid, ) -> impl Iterator<Item = T>
§Filter widget actions by widget id and cast
this function can help you cast the widget actions to the widget you want, the diff is:
- try cast all widget actions (This method is not recommended when a large number of actions occur simultaneously)
- back
Iterator<Item = T>
notIterator<Item = &T>
§Example
self.gbutton(id!(auto_connect)).borrow().map(|x| {
let actions = actions.filter_widget_actions_cast::<GButtonEvent>(x.widget_uid());
actions.for_each(|action| {
if let GButtonEvent::Clicked(param) = action{
dbg!(param);
}
})
});
fn filter_actions_data<T>(&self) -> impl Iterator<Item = &T>where
T: Clone + ActionTrait,
fn filter_widget_actions_set( &self, set: &WidgetSet, ) -> impl Iterator<Item = &WidgetAction>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.