Trait DynamicUiHooks

Source
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:

  1. DynamicUiHooks::before_partial_build.
    • If the should_build: &mut bool argument is set to false then all steps until the Rebuild 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 like DynamicUi::for_each_ui.
  2. PartialUiDyn::build_partial_dyn.
  3. DynamicUiHooks::after_partial_build.
  4. PartialUiDyn::handles_dyn.
  5. DynamicUiHooks::after_handles.
    • The handles are used to bind event handlers.
  6. DynamicUiHooks::need_raw_events_for_children.

§Process events

  1. DynamicUiHooks::process_raw_event.
  2. PartialUiDyn::process_event_dyn.
  3. DynamicUiHooks::after_process_events.

§Rebuild

After processing events the DynamicUi checks if there are items that need to be rebuilt:

  1. DynamicUiHooks::need_rebuild.
  2. 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:

  1. PartialUiDyn::handles_dyn.
  2. DynamicUiHooks::after_handles.
    • The handles are used to unbind event handlers.
  3. DynamicUiHooks::before_rebuild

After that the same functions as the initial build is used.

Required Methods§

Source

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§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Implementors§