Add touchscreen support with onscreen keyboard (#1)
Possible that framebuffer doesn't update without actual keypress (eg, volume down). But, works.
This commit is contained in:
@@ -7,6 +7,7 @@ use crate::window_manager::DrawInstructions;
|
||||
pub mod toggle_button;
|
||||
pub mod highlight_button;
|
||||
pub mod paragraph;
|
||||
pub mod press_button;
|
||||
|
||||
pub trait Component<T> {
|
||||
fn handle_message(&mut self, message: WindowMessage) -> Option<T>;
|
||||
@@ -17,6 +18,7 @@ pub trait Component<T> {
|
||||
//focusing for components is purely to give a visual representation
|
||||
fn focusable(&self) -> bool;
|
||||
fn clickable(&self) -> bool;
|
||||
//fn pressable(&self) -> bool; //touch
|
||||
fn name(&self) -> &String; //should be unique
|
||||
}
|
||||
|
||||
|
||||
69
src/components/press_button.rs
Normal file
69
src/components/press_button.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use std::vec;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::components::Component;
|
||||
use crate::framebuffer::{ Dimensions, Point };
|
||||
use crate::themes::ThemeInfo;
|
||||
use crate::messages::WindowMessage;
|
||||
use crate::window_manager::{ DrawInstructions };
|
||||
|
||||
const MONO_WIDTH: u8 = 10;
|
||||
|
||||
pub struct PressButton<T> {
|
||||
pub top_left: Point,
|
||||
pub size: Dimensions,
|
||||
text: String,
|
||||
press_return: T,
|
||||
}
|
||||
|
||||
impl<T: Clone> Component<T> for PressButton<T> {
|
||||
//
|
||||
fn handle_message(&mut self, message: WindowMessage) -> Option<T> {
|
||||
match message {
|
||||
WindowMessage::Touch(_, _) => {
|
||||
//assume that the parent window-like passed it to us intentionally and checked already
|
||||
//we can check again, but why?
|
||||
Some(self.press_return.clone())
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
|
||||
let half = self.size[0] / 2 - self.text.len() * MONO_WIDTH as usize / 2;
|
||||
vec![
|
||||
DrawInstructions::Rect(self.top_left, [self.size[0], 1], theme_info.border_left_top),
|
||||
DrawInstructions::Rect(self.top_left, [1, self.size[1]], theme_info.border_left_top),
|
||||
DrawInstructions::Rect([self.top_left[0], self.top_left[1] + self.size[1]], [self.size[0], 1], theme_info.border_right_bottom),
|
||||
DrawInstructions::Rect([self.top_left[0] + self.size[0], self.top_left[1]], [1, self.size[1]], theme_info.border_right_bottom),
|
||||
//assume normal background colour
|
||||
DrawInstructions::Text([self.top_left[0] + half, self.top_left[1] + 8], vec!["times-new-romono".to_string()], self.text.clone(), theme_info.text, theme_info.background, Some(0), Some(MONO_WIDTH)),
|
||||
]
|
||||
}
|
||||
|
||||
//properties
|
||||
fn focusable(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn clickable(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn name(&self) -> &String {
|
||||
//sorry
|
||||
&self.text
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PressButton<T> {
|
||||
pub fn new(top_left: Point, size: Dimensions, text: String, press_return: T) -> Self {
|
||||
Self {
|
||||
top_left,
|
||||
size,
|
||||
text,
|
||||
press_return,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user