pub struct InputHandler<PageId, ButtonId> {
pub button_selected: Option<ButtonId>,
pub mouse_position: (f32, f32),
pub cursor_position: usize,
pub text_selection_range: Option<(usize, usize)>,
/* private fields */
}Fields§
§mouse_position: (f32, f32)§cursor_position: usize§text_selection_range: Option<(usize, usize)>Implementations§
Source§impl<PageId: Copy + Eq + Debug, ButtonId: Copy + Eq + Debug> InputHandler<PageId, ButtonId>
impl<PageId: Copy + Eq + Debug, ButtonId: Copy + Eq + Debug> InputHandler<PageId, ButtonId>
Sourcepub fn new(enable_rollback_pages: bool) -> Self
pub fn new(enable_rollback_pages: bool) -> Self
Examples found in repository?
examples/SimpleExample/demo.rs (line 42)
22fn main()
23{
24 // To Be Ignored, Just An Setup To Configure The Build
25 setup_build();
26 let window_config = WindowConfig
27 {
28 window_title: "SimpleExample".to_string(),
29 icon: (None, None),
30 // Recommended to start with 16:9 aspect ratio
31 start_window_size: (800, 450),
32 // Recommended to have minimum size with 16:9 aspect ratio
33 window_minimum_size: (800, 450),
34 resizable: true,
35 centered: true,
36 // By Default SDL_LOGICAL_PRESENTATION_STRETCH Is Set, Only Setting It Here For Demonstration Purpose
37 different_sdl_presentation_mode: Some(SDL_LOGICAL_PRESENTATION_STRETCH),
38 font: ("JetBrainsMono".to_string(), Some("Bold".to_string()))
39 };
40
41 let mut window_modules = create_window(window_config);
42 let mut input_handler = InputHandler::new(true);
43 let mut app_state = AppState::new(PageId::Page1, window_modules.canvas.window().size(), window_modules.stretch_mode_status);
44 let mut page_data = PageData::new(&app_state);
45 let renderer_config = RendererConfig { canvas: window_modules.canvas, texture_creator: &window_modules.texture_creator, ttf_context: &window_modules.ttf_context, font_path: &window_modules.font_path, decrease_color_when_selected: Some((25, 25, 25)), selection_color: Some((0, 0, 200, 125)), assets_dir: None };
46 let mut renderer = Renderer::new(renderer_config);
47
48 populate_page_data(&mut page_data);
49
50 // Wrap the button_action function in a mutable closure so it can capture
51 // additional context if needed. Passing a closure here allows the
52 // button handler API to accept additional arguments beyond the default.
53 let mut button_action_closure = |app_state: &mut AppState<PageId, ButtonId>, button_id: &ButtonId, page_data: &mut PageData<PageId, ButtonId>| button_action(app_state, button_id, page_data);
54
55 loop
56 {
57 println!("{:?}", page_data.persistent_elements_to_render.is_some());
58 //using 900 / your_refresh_rate to a very crispy experience
59 std::thread::sleep(Duration::from_millis(900 / get_monitor_refresh_rate()));
60 app_state.update_window_size(renderer.canvas.window().size().0, renderer.canvas.window().size().1);
61 input_handler.handle_input(&mut window_modules.event_pump, &mut window_modules.clipboard_system, &mut page_data, &mut app_state, &mut button_action_closure);
62 page_data.create_current_page(&mut app_state);
63 renderer.render(&page_data, &mut app_state, &input_handler);
64 }
65}More examples
examples/AdvancedExample/demo.rs (line 50)
29fn main()
30{
31 // To Be Ignored, Just An Setup To Configure Some Assets
32 setup_build();
33 list_embedded(&ASSETS);
34
35 let window_config = WindowConfig {
36 window_title: "AdvancedExample".to_string(),
37 icon: (Some("image_example/example_2.bmp".to_string()), Some(&ASSETS)),
38 // Recommended to start with 16:9 aspect ratio
39 start_window_size: (800, 450),
40 // Recommended to have minimum size with 16:9 aspect ratio
41 window_minimum_size: (800, 450),
42 resizable: true,
43 centered: true,
44 // By Default SDL_LOGICAL_PRESENTATION_STRETCH Is Set, Only Setting It Here For Demonstration Purpose
45 different_sdl_presentation_mode: Some(SDL_LOGICAL_PRESENTATION_STRETCH),
46 font: ("JetBrainsMono".to_string(), Some("Bold".to_string()))
47 };
48 let mut window_modules = create_window(window_config);
49 //bool is reffered to the rollback pages system, with "Mouse side buttons" or ("Alt" + "Arrows Keys") | (true = Page Rollback On), (false = Page Rollback Off)
50 let mut input_handler = InputHandler::new(true);
51 let mut app_state = AppState::new(PageId::Page1, window_modules.canvas.window().size(), window_modules.stretch_mode_status);
52 let mut page_data = PageData::new(&app_state);
53
54 let renderer_config = RendererConfig { canvas: window_modules.canvas, texture_creator: &window_modules.texture_creator, ttf_context: &window_modules.ttf_context, font_path: &window_modules.font_path, decrease_color_when_selected: Some((25, 25, 25)), selection_color: Some((0, 0, 200, 125)), assets_dir: Some(&ASSETS) };
55 let mut renderer = Renderer::new(renderer_config);
56
57
58 populate_page_data(&mut page_data);
59
60 // Wrap the button_action function in a mutable closure so it can capture
61 // additional context if needed. Passing a closure here allows the
62 // button handler API to accept additional arguments beyond the default.
63 let mut button_action_closure = |app_state: &mut AppState<PageId, ButtonId>, button_id: &ButtonId, page_data: &mut PageData<PageId, ButtonId>| button_action(app_state, button_id, page_data);
64
65 loop
66 {
67 //using (900 / your_refresh_rate) to a very crispy experience
68 std::thread::sleep(Duration::from_millis(900 / get_monitor_refresh_rate()));
69 input_handler.handle_input(&mut window_modules.event_pump, &mut window_modules.clipboard_system, &mut page_data, &mut app_state, &mut button_action_closure);
70 app_state.update_window_size(renderer.canvas.window().size().0, renderer.canvas.window().size().1);
71 page_data.create_current_page(&mut app_state);
72 renderer.render(&page_data, &mut app_state, &input_handler);
73 }
74}pub fn poll(&self, event_pump: &mut EventPump) -> InputEvent
Sourcepub fn handle_input(
&mut self,
event_pump: &mut EventPump,
clipboard_util: &mut ClipboardUtil,
page_data: &mut PageData<PageId, ButtonId>,
app_state: &mut AppState<PageId, ButtonId>,
button_action: &mut dyn Fn(&mut AppState<PageId, ButtonId>, &ButtonId, &mut PageData<PageId, ButtonId>),
)
pub fn handle_input( &mut self, event_pump: &mut EventPump, clipboard_util: &mut ClipboardUtil, page_data: &mut PageData<PageId, ButtonId>, app_state: &mut AppState<PageId, ButtonId>, button_action: &mut dyn Fn(&mut AppState<PageId, ButtonId>, &ButtonId, &mut PageData<PageId, ButtonId>), )
Examples found in repository?
examples/SimpleExample/demo.rs (line 61)
22fn main()
23{
24 // To Be Ignored, Just An Setup To Configure The Build
25 setup_build();
26 let window_config = WindowConfig
27 {
28 window_title: "SimpleExample".to_string(),
29 icon: (None, None),
30 // Recommended to start with 16:9 aspect ratio
31 start_window_size: (800, 450),
32 // Recommended to have minimum size with 16:9 aspect ratio
33 window_minimum_size: (800, 450),
34 resizable: true,
35 centered: true,
36 // By Default SDL_LOGICAL_PRESENTATION_STRETCH Is Set, Only Setting It Here For Demonstration Purpose
37 different_sdl_presentation_mode: Some(SDL_LOGICAL_PRESENTATION_STRETCH),
38 font: ("JetBrainsMono".to_string(), Some("Bold".to_string()))
39 };
40
41 let mut window_modules = create_window(window_config);
42 let mut input_handler = InputHandler::new(true);
43 let mut app_state = AppState::new(PageId::Page1, window_modules.canvas.window().size(), window_modules.stretch_mode_status);
44 let mut page_data = PageData::new(&app_state);
45 let renderer_config = RendererConfig { canvas: window_modules.canvas, texture_creator: &window_modules.texture_creator, ttf_context: &window_modules.ttf_context, font_path: &window_modules.font_path, decrease_color_when_selected: Some((25, 25, 25)), selection_color: Some((0, 0, 200, 125)), assets_dir: None };
46 let mut renderer = Renderer::new(renderer_config);
47
48 populate_page_data(&mut page_data);
49
50 // Wrap the button_action function in a mutable closure so it can capture
51 // additional context if needed. Passing a closure here allows the
52 // button handler API to accept additional arguments beyond the default.
53 let mut button_action_closure = |app_state: &mut AppState<PageId, ButtonId>, button_id: &ButtonId, page_data: &mut PageData<PageId, ButtonId>| button_action(app_state, button_id, page_data);
54
55 loop
56 {
57 println!("{:?}", page_data.persistent_elements_to_render.is_some());
58 //using 900 / your_refresh_rate to a very crispy experience
59 std::thread::sleep(Duration::from_millis(900 / get_monitor_refresh_rate()));
60 app_state.update_window_size(renderer.canvas.window().size().0, renderer.canvas.window().size().1);
61 input_handler.handle_input(&mut window_modules.event_pump, &mut window_modules.clipboard_system, &mut page_data, &mut app_state, &mut button_action_closure);
62 page_data.create_current_page(&mut app_state);
63 renderer.render(&page_data, &mut app_state, &input_handler);
64 }
65}More examples
examples/AdvancedExample/demo.rs (line 69)
29fn main()
30{
31 // To Be Ignored, Just An Setup To Configure Some Assets
32 setup_build();
33 list_embedded(&ASSETS);
34
35 let window_config = WindowConfig {
36 window_title: "AdvancedExample".to_string(),
37 icon: (Some("image_example/example_2.bmp".to_string()), Some(&ASSETS)),
38 // Recommended to start with 16:9 aspect ratio
39 start_window_size: (800, 450),
40 // Recommended to have minimum size with 16:9 aspect ratio
41 window_minimum_size: (800, 450),
42 resizable: true,
43 centered: true,
44 // By Default SDL_LOGICAL_PRESENTATION_STRETCH Is Set, Only Setting It Here For Demonstration Purpose
45 different_sdl_presentation_mode: Some(SDL_LOGICAL_PRESENTATION_STRETCH),
46 font: ("JetBrainsMono".to_string(), Some("Bold".to_string()))
47 };
48 let mut window_modules = create_window(window_config);
49 //bool is reffered to the rollback pages system, with "Mouse side buttons" or ("Alt" + "Arrows Keys") | (true = Page Rollback On), (false = Page Rollback Off)
50 let mut input_handler = InputHandler::new(true);
51 let mut app_state = AppState::new(PageId::Page1, window_modules.canvas.window().size(), window_modules.stretch_mode_status);
52 let mut page_data = PageData::new(&app_state);
53
54 let renderer_config = RendererConfig { canvas: window_modules.canvas, texture_creator: &window_modules.texture_creator, ttf_context: &window_modules.ttf_context, font_path: &window_modules.font_path, decrease_color_when_selected: Some((25, 25, 25)), selection_color: Some((0, 0, 200, 125)), assets_dir: Some(&ASSETS) };
55 let mut renderer = Renderer::new(renderer_config);
56
57
58 populate_page_data(&mut page_data);
59
60 // Wrap the button_action function in a mutable closure so it can capture
61 // additional context if needed. Passing a closure here allows the
62 // button handler API to accept additional arguments beyond the default.
63 let mut button_action_closure = |app_state: &mut AppState<PageId, ButtonId>, button_id: &ButtonId, page_data: &mut PageData<PageId, ButtonId>| button_action(app_state, button_id, page_data);
64
65 loop
66 {
67 //using (900 / your_refresh_rate) to a very crispy experience
68 std::thread::sleep(Duration::from_millis(900 / get_monitor_refresh_rate()));
69 input_handler.handle_input(&mut window_modules.event_pump, &mut window_modules.clipboard_system, &mut page_data, &mut app_state, &mut button_action_closure);
70 app_state.update_window_size(renderer.canvas.window().size().0, renderer.canvas.window().size().1);
71 page_data.create_current_page(&mut app_state);
72 renderer.render(&page_data, &mut app_state, &input_handler);
73 }
74}pub fn insert_text( &mut self, text_to_insert: &str, app_state: &AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, _is_paste: bool, )
pub fn backspace( &mut self, app_state: &mut AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, )
pub fn copy( &mut self, clipboard_util_option: Option<&mut ClipboardUtil>, app_state: &AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, is_cut_operation: bool, )
pub fn select_all( &mut self, app_state: &AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, )
pub fn delete_all( &mut self, app_state: &AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, )
pub fn move_cursor( &mut self, move_right: bool, shift_held: bool, app_state: &AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, )
pub fn paste( &mut self, clipboard_util_option: Option<&mut ClipboardUtil>, app_state: &AppState<PageId, ButtonId>, page_data: &mut PageData<PageId, ButtonId>, )
pub fn push_state(&mut self, page_data: &PageData<PageId, ButtonId>)
pub fn undo(&mut self, page_data: &mut PageData<PageId, ButtonId>)
pub fn get_current_input_length( &self, app_state: &AppState<PageId, ButtonId>, page_data: &PageData<PageId, ButtonId>, button_id: ButtonId, ) -> usize
Auto Trait Implementations§
impl<PageId, ButtonId> Freeze for InputHandler<PageId, ButtonId>where
ButtonId: Freeze,
impl<PageId, ButtonId> RefUnwindSafe for InputHandler<PageId, ButtonId>where
ButtonId: RefUnwindSafe,
PageId: RefUnwindSafe,
impl<PageId, ButtonId> Send for InputHandler<PageId, ButtonId>
impl<PageId, ButtonId> Sync for InputHandler<PageId, ButtonId>
impl<PageId, ButtonId> Unpin for InputHandler<PageId, ButtonId>
impl<PageId, ButtonId> UnwindSafe for InputHandler<PageId, ButtonId>where
ButtonId: UnwindSafe,
PageId: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.