Struct r3bl_rs_utils::DialogComponent
source · pub struct DialogComponent<S, A>where
S: Debug + Default + Clone + PartialEq + Sync + Send,
A: Debug + Default + Clone + Sync + Send,{
pub id: FlexBoxId,
pub dialog_engine: DialogEngine,
pub on_dialog_press_handler: Option<fn(_: DialogChoice, _: &Arc<RwLock<Store<S, A>>>)>,
pub on_dialog_editor_change_handler: Option<fn(_: EditorBuffer, _: &Arc<RwLock<Store<S, A>>>)>,
}Expand description
This is a shim which allows the reusable DialogEngine to be used in the context of Component and r3bl_redux::Store. The main methods here simply pass thru all their arguments to the DialogEngine.
Fields§
§id: FlexBoxId§dialog_engine: DialogEngine§on_dialog_press_handler: Option<fn(_: DialogChoice, _: &Arc<RwLock<Store<S, A>>>)>Make sure to dispatch actions to handle the user’s dialog choice DialogChoice.
on_dialog_editor_change_handler: Option<fn(_: EditorBuffer, _: &Arc<RwLock<Store<S, A>>>)>Make sure to dispatch an action to update the dialog buffer’s editor buffer.
Implementations§
source§impl<S, A> DialogComponent<S, A>where
S: Debug + Default + Clone + PartialEq + Sync + Send,
A: Debug + Default + Clone + Sync + Send,
impl<S, A> DialogComponent<S, A>where S: Debug + Default + Clone + PartialEq + Sync + Send, A: Debug + Default + Clone + Sync + Send,
sourcepub fn new(
id: FlexBoxId,
dialog_options: DialogEngineConfigOptions,
editor_options: EditorEngineConfig,
on_dialog_press_handler: fn(_: DialogChoice, _: &Arc<RwLock<Store<S, A>>>),
on_dialog_editor_change_handler: fn(_: EditorBuffer, _: &Arc<RwLock<Store<S, A>>>)
) -> DialogComponent<S, A>
pub fn new( id: FlexBoxId, dialog_options: DialogEngineConfigOptions, editor_options: EditorEngineConfig, on_dialog_press_handler: fn(_: DialogChoice, _: &Arc<RwLock<Store<S, A>>>), on_dialog_editor_change_handler: fn(_: EditorBuffer, _: &Arc<RwLock<Store<S, A>>>) ) -> DialogComponent<S, A>
The on_dialog_press_handler is a lambda that is called if the user presses enter or escape. Typically this results in a Redux action being created and then dispatched to the given store.
Trait Implementations§
source§impl<S, A> Clone for DialogComponent<S, A>where
S: Clone + Debug + Default + PartialEq + Sync + Send,
A: Clone + Debug + Default + Sync + Send,
impl<S, A> Clone for DialogComponent<S, A>where S: Clone + Debug + Default + PartialEq + Sync + Send, A: Clone + Debug + Default + Sync + Send,
source§fn clone(&self) -> DialogComponent<S, A>
fn clone(&self) -> DialogComponent<S, A>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<S, A> Component<S, A> for DialogComponent<S, A>where
S: HasDialogBuffers + Default + Clone + PartialEq + Debug + Sync + Send,
A: Debug + Default + Clone + Sync + Send,
impl<S, A> Component<S, A> for DialogComponent<S, A>where S: HasDialogBuffers + Default + Clone + PartialEq + Debug + Sync + Send, A: Debug + Default + Clone + Sync + Send,
source§fn render<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
args: ComponentScopeArgs<'life1, S, A>,
_current_box: &'life2 FlexBox,
surface_bounds: SurfaceBounds
) -> Pin<Box<dyn Future<Output = Result<RenderPipeline, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
DialogComponent<S, A>: 'async_trait,
fn render<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, args: ComponentScopeArgs<'life1, S, A>, _current_box: &'life2 FlexBox, surface_bounds: SurfaceBounds ) -> Pin<Box<dyn Future<Output = Result<RenderPipeline, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, DialogComponent<S, A>: 'async_trait,
This shim simply calls DialogEngineApi::render_engine w/ all the necessary arguments:
- Global scope: r3bl_redux::SharedStore, SharedGlobalData.
- App scope:
S, ComponentRegistry<S, A>. - User input (from main_event_loop): InputEvent.
Note:
- The 3rd argument
_current_boxFlexBox is ignored since the dialog component breaks out of whatever box the layout places it in, and ends up painting itself over the entire screen. - However,
SurfaceBoundsis saved for later use. And it is used to restrict where the dialog can be placed on the screen.
source§fn handle_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
args: ComponentScopeArgs<'life1, S, A>,
input_event: &'life2 InputEvent
) -> Pin<Box<dyn Future<Output = Result<EventPropagation, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
DialogComponent<S, A>: 'async_trait,
fn handle_event<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, args: ComponentScopeArgs<'life1, S, A>, input_event: &'life2 InputEvent ) -> Pin<Box<dyn Future<Output = Result<EventPropagation, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, DialogComponent<S, A>: 'async_trait,
This shim simply calls DialogEngineApi::apply_event w/ all the necessary arguments:
- Global scope: r3bl_redux::SharedStore, SharedGlobalData.
- App scope:
S, ComponentRegistry<S, A>. - User input (from main_event_loop): InputEvent.
Usually a component must have focus in order for the App to route_event_to_focused_component in the first place.