pub struct DynamicUi<T: DynamicUiWrapper> {
ui_list: RefCell<Vec<PluginData<T>>>,
event_queue: RefCell<VecDeque<Box<dyn FnOnce(&Rc<T>)>>>,
delay_events: Cell<bool>,
should_destroy: Cell<bool>,
event_handlers: RefCell<Vec<EventHandlerData>>,
prevent_recursive_events: Cell<bool>,
self_wrapper_ty: PhantomData<T>,
}
Expand description
Stores many [nwg::PartialUi
] type. Usually behind an Rc
pointer stored
inside DynamicUiRef
.
Fields§
§ui_list: RefCell<Vec<PluginData<T>>>
Can be mutably borrowed when rebuilding. The type id indicates which plugin owns the parent control.
§Lock pattern
For write locks:
- Check if
Self::delay_events
is set and if so don’t acquire a lock. - Create a
DelayEventsGuard
that sets theSelf::delay_events
field totrue
(and then tofalse
when dropped) - Acquiring the
std::cell::RefMut
guard. - Don’t call into plugin hooks while holding the guard.
For read locks:
These should be okay everywhere except in functions that use
DelayEventsGuard
.
event_queue: RefCell<VecDeque<Box<dyn FnOnce(&Rc<T>)>>>
Used to store events that should be handled after rebuilding some plugins.
delay_events: Cell<bool>
Used to delay events while rebuilding. We take mutable references to plugins while rebuilding so this prevents issues where events are handled recursively while building new UI elements.
should_destroy: Cell<bool>
true
if the UI should be destroyed.
event_handlers: RefCell<Vec<EventHandlerData>>
Event handlers that are bound to plugin windows.
Raw event handlers can fail to be registered in which case we ignore the error (this only happens if raw event handler was registered previously with the same id for the same window).
prevent_recursive_events: Cell<bool>
Prevent recursive event handling.
self_wrapper_ty: PhantomData<T>
Implementations§
Source§impl<T> DynamicUi<T>where
T: DynamicUiWrapper,
impl<T> DynamicUi<T>where
T: DynamicUiWrapper,
pub fn new(ui_list: Vec<Box<T::Hooks>>) -> Self
pub fn set_prevent_recursive_events(&self, value: bool)
Sourcepub fn with_paused_events<R>(&self, f: impl FnOnce() -> R) -> R
pub fn with_paused_events<R>(&self, f: impl FnOnce() -> R) -> R
Run some code while delaying other event handlers.
Sourcepub fn get_ui<U: DynamicUiHooks<T>>(&self) -> Option<Ref<'_, U>>
pub fn get_ui<U: DynamicUiHooks<T>>(&self) -> Option<Ref<'_, U>>
Get a reference to a ui item managed by this dynamic ui.
Warning: the returned ui item might not have been built.
pub fn with_all_ui<R>( &self, f: impl FnOnce(&mut dyn Iterator<Item = &T::Hooks>) -> R, ) -> R
pub fn for_each_ui(&self, f: impl FnMut(&T::Hooks))
Sourcepub fn maybe_preform_action<R>(
wrapper: &Rc<T>,
action: impl FnOnce(&Rc<T>) -> R,
) -> Option<R>
pub fn maybe_preform_action<R>( wrapper: &Rc<T>, action: impl FnOnce(&Rc<T>) -> R, ) -> Option<R>
Preforms an action and rebuilds the UI if needed. The action will be skipped if the UI is currently being rebuilt.
Sourcepub fn preform_action<R>(
wrapper: &Rc<T>,
action: impl FnOnce(&Rc<T>, bool) -> R + 'static,
) -> Option<R>
pub fn preform_action<R>( wrapper: &Rc<T>, action: impl FnOnce(&Rc<T>, bool) -> R + 'static, ) -> Option<R>
Preforms an action and then rebuilds the UI if needed. The action will be queued if UI is currently being rebuilt.
The action will be called with the wrapper
and a bool
that is true
if the action was delayed.
pub fn preform_action_adv<S>( wrapper: &Rc<T>, state: S, delay_action: impl FnOnce(S) -> Option<Box<dyn FnOnce(&Rc<T>) + 'static>>, preform_action: impl FnOnce(S), )
fn preform_action_and_maybe_rebuild( wrapper: &Rc<T>, action: Option<&mut dyn FnMut(&Rc<T>)>, )
fn initial_build(wrapper: &Rc<T>) -> Result<(), NwgError>
fn all_handles(wrapper: &Rc<T>) -> Vec<(TypeId, bool, ControlHandle)>
fn process_events_for_plugin_and_children( wrapper: &Rc<T>, plugin_id: TypeId, f: impl FnMut(&PluginData<T>), )
fn process_event( wrapper: &Rc<T>, evt: Event, evt_data: &EventData, handle: ControlHandle, window: ControlHandle, plugin_id: TypeId, )
fn process_raw_event( wrapper: &Rc<T>, hwnd: isize, msg: u32, w: usize, l: isize, window: ControlHandle, plugin_id: TypeId, ) -> Option<isize>
fn unbind_specific_event_handlers( wrapper: &Rc<T>, window_handles: &[&ControlHandle], )
fn unbind_event_handlers(wrapper: &Rc<T>)
fn bind_event_handlers(wrapper: &Rc<T>)
Sourcefn destroy_ui(wrapper: &Rc<T>)
fn destroy_ui(wrapper: &Rc<T>)
To make sure that everything is freed without issues, the default handler must be unbound.
Trait Implementations§
Source§impl<T> Debug for DynamicUi<T>where
T: DynamicUiWrapper,
impl<T> Debug for DynamicUi<T>where
T: DynamicUiWrapper,
Auto Trait Implementations§
impl<T> !Freeze for DynamicUi<T>
impl<T> !RefUnwindSafe for DynamicUi<T>
impl<T> !Send for DynamicUi<T>
impl<T> !Sync for DynamicUi<T>
impl<T> Unpin for DynamicUi<T>where
T: Unpin,
impl<T> !UnwindSafe for DynamicUi<T>
Blanket Implementations§
§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Source§impl<T> DynWithDefault for T
impl<T> DynWithDefault for T
Source§fn with_default_mut(
&mut self,
f: &mut dyn FnMut(&mut dyn DynWithDefault, &mut (dyn Any + 'static)),
)
fn with_default_mut( &mut self, f: &mut dyn FnMut(&mut dyn DynWithDefault, &mut (dyn Any + 'static)), )
self
and the second argument
is the new temporary default value. The callback can then modify the
value as needed.Source§fn clear_and_inspect_old(
&mut self,
f: &mut dyn FnMut(&mut dyn DynWithDefault, &mut (dyn Any + 'static)),
)
fn clear_and_inspect_old( &mut self, f: &mut dyn FnMut(&mut dyn DynWithDefault, &mut (dyn Any + 'static)), )
self
to a new default value and inspect the previous value as the
second argument to the callback.fn clear(&mut self)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.