Struct tuirealm::Application
source · pub struct Application<ComponentId, Msg, UserEvent>where
ComponentId: Eq + PartialEq + Clone + Hash,
Msg: PartialEq,
UserEvent: Eq + PartialEq + Clone + PartialOrd + Send + 'static,{ /* private fields */ }
Expand description
The application defines a tui-realm application.
It will handle events, subscriptions and the view too.
It provides functions to interact with the view (mount, umount, query, etc), but also
the main function: tick()
. See tick
Implementations§
source§impl<K, Msg, UserEvent> Application<K, Msg, UserEvent>
impl<K, Msg, UserEvent> Application<K, Msg, UserEvent>
sourcepub fn init(listener_cfg: EventListenerCfg<UserEvent>) -> Self
pub fn init(listener_cfg: EventListenerCfg<UserEvent>) -> Self
Initialize a new Application
.
The event listener is immediately created and started.
sourcepub fn restart_listener(
&mut self,
listener_cfg: EventListenerCfg<UserEvent>
) -> ApplicationResult<()>
pub fn restart_listener( &mut self, listener_cfg: EventListenerCfg<UserEvent> ) -> ApplicationResult<()>
Restart listener in case the previous listener has died or if you want to start a new one with a new configuration.
The listener has died if you received a
ApplicationError::Listener(ListenerError::ListenerDied))
sourcepub fn lock_ports(&mut self) -> ApplicationResult<()>
pub fn lock_ports(&mut self) -> ApplicationResult<()>
Lock ports. As long as Ports are locked, ports won’t be polled. Locking ports will also prevent Tick events from being generated.
sourcepub fn unlock_ports(&mut self) -> ApplicationResult<()>
pub fn unlock_ports(&mut self) -> ApplicationResult<()>
Unlock Ports. Once called, the event listener will resume polling Ports.
sourcepub fn tick(&mut self, strategy: PollStrategy) -> ApplicationResult<Vec<Msg>>
pub fn tick(&mut self, strategy: PollStrategy) -> ApplicationResult<Vec<Msg>>
The tick method makes the application to run once. The workflow of the tick method is the following one:
- The event listener is fetched according to the provided
PollStrategy
- All the received events are sent to the current active component
- All the received events are forwarded to the subscribed components which satisfy the received events and conditions.
- Returns messages to process
As soon as function returns, you should call the view()
method.
You can also call
view
from theupdate()
if you need it
sourcepub fn add_injector(&mut self, injector: Box<dyn Injector<K>>)
pub fn add_injector(&mut self, injector: Box<dyn Injector<K>>)
Add an injector to the view
sourcepub fn mount(
&mut self,
id: K,
component: Box<dyn Component<Msg, UserEvent>>,
subs: Vec<Sub<K, UserEvent>>
) -> ApplicationResult<()>
pub fn mount( &mut self, id: K, component: Box<dyn Component<Msg, UserEvent>>, subs: Vec<Sub<K, UserEvent>> ) -> ApplicationResult<()>
Mount component to view and associate subscriptions for it. Returns error if component is already mounted NOTE: if subs vector contains duplicated, these will be discarded
sourcepub fn umount(&mut self, id: &K) -> ApplicationResult<()>
pub fn umount(&mut self, id: &K) -> ApplicationResult<()>
Umount component associated to id
and remove ALL its SUBSCRIPTIONS.
Returns Error if the component doesn’t exist
sourcepub fn remount(
&mut self,
id: K,
component: Box<dyn Component<Msg, UserEvent>>,
subs: Vec<Sub<K, UserEvent>>
) -> ApplicationResult<()>
pub fn remount( &mut self, id: K, component: Box<dyn Component<Msg, UserEvent>>, subs: Vec<Sub<K, UserEvent>> ) -> ApplicationResult<()>
Remount provided component. Returns Err if failed to mount. It ignores whether the component already exists or not. If component had focus, focus is preserved
sourcepub fn umount_all(&mut self)
pub fn umount_all(&mut self)
Umount all components in the view and removed all associated subscriptions
sourcepub fn query(
&self,
id: &K,
query: Attribute
) -> ApplicationResult<Option<AttrValue>>
pub fn query( &self, id: &K, query: Attribute ) -> ApplicationResult<Option<AttrValue>>
Query view component for a certain AttrValue
Returns error if the component doesn’t exist
Returns None if the attribute doesn’t exist.
sourcepub fn attr(
&mut self,
id: &K,
attr: Attribute,
value: AttrValue
) -> ApplicationResult<()>
pub fn attr( &mut self, id: &K, attr: Attribute, value: AttrValue ) -> ApplicationResult<()>
Set attribute for component id
Returns error if the component doesn’t exist
sourcepub fn state(&self, id: &K) -> ApplicationResult<State>
pub fn state(&self, id: &K) -> ApplicationResult<State>
Get state for component id
.
Returns Err
if component doesn’t exist
sourcepub fn active(&mut self, id: &K) -> ApplicationResult<()>
pub fn active(&mut self, id: &K) -> ApplicationResult<()>
Shorthand for attr(id, Attribute::Focus(AttrValue::Flag(true)))
.
It also sets the component as the current one having focus.
Previous active component, if any, GETS PUSHED to the STACK
Returns error: if component doesn’t exist. Use mounted()
to check if component exists
NOTE: users should always use this function to give focus to components.
sourcepub fn blur(&mut self) -> ApplicationResult<()>
pub fn blur(&mut self) -> ApplicationResult<()>
Blur selected element AND DON’T PUSH CURRENT ACTIVE ELEMENT INTO THE STACK
Shorthand for attr(id, Attribute::Focus(AttrValue::Flag(false)))
.
It also unset the current focus and give it to the first element in stack.
Returns error: if no component has focus
NOTE: users should always use this function to remove focus to components.
sourcepub fn focus(&self) -> Option<&K>
pub fn focus(&self) -> Option<&K>
Get a reference to the id of the current active component in the view
sourcepub fn subscribe(
&mut self,
id: &K,
sub: Sub<K, UserEvent>
) -> ApplicationResult<()>
pub fn subscribe( &mut self, id: &K, sub: Sub<K, UserEvent> ) -> ApplicationResult<()>
Subscribe component to a certain event. Returns Error if the component doesn’t exist or if the component is already subscribed to this event
sourcepub fn unsubscribe(
&mut self,
id: &K,
ev: SubEventClause<UserEvent>
) -> ApplicationResult<()>
pub fn unsubscribe( &mut self, id: &K, ev: SubEventClause<UserEvent> ) -> ApplicationResult<()>
Unsubscribe a component from a certain event. Returns error if the component doesn’t exist or if the component is not subscribed to this event
sourcepub fn lock_subs(&mut self)
pub fn lock_subs(&mut self)
Lock subscriptions. As long as the subscriptions are locked, events won’t be propagated to subscriptions.
sourcepub fn unlock_subs(&mut self)
pub fn unlock_subs(&mut self)
Unlock subscriptions. Application will now resume propagating events to subscriptions.