pub trait DynamicUiHooks<T: ?Sized>:
PartialUiDyn
+ DynWithDefault
+ 'static {
// Required method
fn before_partial_build(
&mut self,
_dynamic_ui: &Rc<T>,
_should_build: &mut bool,
) -> Option<(ControlHandle, TypeId)>;
// Provided methods
fn after_partial_build(&mut self, _dynamic_ui: &Rc<T>) { ... }
fn after_handles<'a>(
&'a self,
_dynamic_ui: &Rc<T>,
_handles: &mut Vec<&'a ControlHandle>,
) { ... }
fn need_raw_events_for_children(&self) -> bool { ... }
fn after_process_events(
&self,
_dynamic_ui: &Rc<T>,
_evt: Event,
_evt_data: &EventData,
_handle: ControlHandle,
_window: ControlHandle,
) { ... }
fn process_raw_event(
&self,
_dynamic_ui: &Rc<T>,
_hwnd: isize,
_msg: u32,
_w: usize,
_l: isize,
_window: ControlHandle,
) -> Option<isize> { ... }
fn need_rebuild(&self, _dynamic_ui: &Rc<T>) -> bool { ... }
fn is_ordered_in_parent(&self) -> bool { ... }
fn before_rebuild(&mut self, _dynamic_ui: &Rc<T>) { ... }
}
Expand description
A trait for [nwg::PartialUi
] types that wants to be managed by
DynamicUi
.
§Lifecycle
§Initial build
For each item (in their specified order) these functions are called:
DynamicUiHooks::before_partial_build
.- If the
should_build: &mut bool
argument is set tofalse
then all steps until theRebuild
section is skipped. So no events will be delivered to items that haven’t been built. Such items will also be skipped by helper methods likeDynamicUi::for_each_ui
.
- If the
PartialUiDyn::build_partial_dyn
.DynamicUiHooks::after_partial_build
.PartialUiDyn::handles_dyn
.DynamicUiHooks::after_handles
.- The handles are used to bind event handlers.
DynamicUiHooks::need_raw_events_for_children
.
§Process events
DynamicUiHooks::process_raw_event
.- This might be called after
DynamicUiHooks::after_process_events
depending on if the last registered event handler gets events first. (The raw event handler is registered last.)
- This might be called after
PartialUiDyn::process_event_dyn
.DynamicUiHooks::after_process_events
.
§Rebuild
After processing events the DynamicUi
checks if there are items that
need to be rebuilt:
DynamicUiHooks::need_rebuild
.DynamicUiHooks::is_ordered_in_parent
if not rebuild was needed but a previous sibling was rebuilt.
If one of the previous predicate functions returned true
or the item’s
parent was rebuilt then the item will be rebuilt:
PartialUiDyn::handles_dyn
.DynamicUiHooks::after_handles
.- The handles are used to unbind event handlers.
DynamicUiHooks::before_rebuild
After that the same functions as the initial build is used.
Required Methods§
Sourcefn before_partial_build(
&mut self,
_dynamic_ui: &Rc<T>,
_should_build: &mut bool,
) -> Option<(ControlHandle, TypeId)>
fn before_partial_build( &mut self, _dynamic_ui: &Rc<T>, _should_build: &mut bool, ) -> Option<(ControlHandle, TypeId)>
Called before the item has been built. The returned parent will be
passed to [nwg::PartialUi::build_partial
] and used by controls in
structs that make use of the [nwd::NwgPartial
] derive macro.
This function should also return the type ID of the dynamic ui that owns the control handle so that this ui is rebuilt in case its parent is rebuilt.
The &mut bool
argument can be set to false
in order to not build
this item.
Provided Methods§
Sourcefn after_partial_build(&mut self, _dynamic_ui: &Rc<T>)
fn after_partial_build(&mut self, _dynamic_ui: &Rc<T>)
Called right after the ui has finished building.
Note: this will also be called after the ui has been rebuilt.
Sourcefn after_handles<'a>(
&'a self,
_dynamic_ui: &Rc<T>,
_handles: &mut Vec<&'a ControlHandle>,
)
fn after_handles<'a>( &'a self, _dynamic_ui: &Rc<T>, _handles: &mut Vec<&'a ControlHandle>, )
Run right after [nwg::PartialUi::handles
] and allows modifying its
result.
Sourcefn need_raw_events_for_children(&self) -> bool
fn need_raw_events_for_children(&self) -> bool
Called after DynamicUiHooks::after_handles
to check if we should
bind raw event handlers for child controls as well.
Sourcefn after_process_events(
&self,
_dynamic_ui: &Rc<T>,
_evt: Event,
_evt_data: &EventData,
_handle: ControlHandle,
_window: ControlHandle,
)
fn after_process_events( &self, _dynamic_ui: &Rc<T>, _evt: Event, _evt_data: &EventData, _handle: ControlHandle, _window: ControlHandle, )
Run right after [nwg::PartialUi::process_event
] and allows easily
doing some extra processing. Useful since the original method might be
implemented by a derive macro which would make it difficult to modify.
Sourcefn process_raw_event(
&self,
_dynamic_ui: &Rc<T>,
_hwnd: isize,
_msg: u32,
_w: usize,
_l: isize,
_window: ControlHandle,
) -> Option<isize>
fn process_raw_event( &self, _dynamic_ui: &Rc<T>, _hwnd: isize, _msg: u32, _w: usize, _l: isize, _window: ControlHandle, ) -> Option<isize>
Listen to raw window events (not filtered or processed by
[native_windows_gui
]). The first result that returns Some
will be
used as the actual return value for the event.
Note that [nwg::bind_raw_event_handler
] only listens for events on the
top most control and not its children which differs from how
[nwg::full_bind_event_handler
] works and therefore you might see less
events in this hook than in DynamicUiHooks::after_process_events
.
Sourcefn need_rebuild(&self, _dynamic_ui: &Rc<T>) -> bool
fn need_rebuild(&self, _dynamic_ui: &Rc<T>) -> bool
Indicate that this item needs to be rebuilt. Maybe because its part of a context menu and its items need to be changed.
This method is called automatically after
DynamicUiHooks::after_process_events
to check if processing the
events changed the UI so that it needs to be rebuilt.
Sourcefn is_ordered_in_parent(&self) -> bool
fn is_ordered_in_parent(&self) -> bool
Indicates if this item has a specific position relative to other items
in its parent. If this returns true
then the item will be rebuilt
after previous siblings (items that share the same parent) are rebuilt.
Defaults to true
since its usually safer to rebuild more often.
Sourcefn before_rebuild(&mut self, _dynamic_ui: &Rc<T>)
fn before_rebuild(&mut self, _dynamic_ui: &Rc<T>)
Do some cleanup before the plugin is built again. By default this resets the state to its default value.