release modifiers on keyboard hide
This commit is contained in:
@@ -52,7 +52,15 @@ impl<D, S> CanvasBuilder<D, S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates a label with fg_color, font_size inherited from the canvas
|
// Creates a label with fg_color, font_size inherited from the canvas
|
||||||
pub fn label(&mut self, x: f32, y: f32, w: f32, h: f32, radius: f32, text: Arc<str>) -> &mut Control<D, S> {
|
pub fn label(
|
||||||
|
&mut self,
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
w: f32,
|
||||||
|
h: f32,
|
||||||
|
radius: f32,
|
||||||
|
text: Arc<str>,
|
||||||
|
) -> &mut Control<D, S> {
|
||||||
let idx = self.canvas.controls.len();
|
let idx = self.canvas.controls.len();
|
||||||
self.canvas.controls.push(Control {
|
self.canvas.controls.push(Control {
|
||||||
rect: Rect { x, y, w, h },
|
rect: Rect { x, y, w, h },
|
||||||
@@ -116,7 +124,15 @@ impl<D, S> CanvasBuilder<D, S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates a button with fg_color, bg_color, font_size inherited from the canvas
|
// Creates a button with fg_color, bg_color, font_size inherited from the canvas
|
||||||
pub fn button(&mut self, x: f32, y: f32, w: f32, h: f32, radius: f32, text: Arc<str>) -> &mut Control<D, S> {
|
pub fn button(
|
||||||
|
&mut self,
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
w: f32,
|
||||||
|
h: f32,
|
||||||
|
radius: f32,
|
||||||
|
text: Arc<str>,
|
||||||
|
) -> &mut Control<D, S> {
|
||||||
let idx = self.canvas.controls.len();
|
let idx = self.canvas.controls.len();
|
||||||
|
|
||||||
self.canvas.interactive_set_idx(x, y, w, h, idx);
|
self.canvas.interactive_set_idx(x, y, w, h, idx);
|
||||||
|
|||||||
@@ -220,6 +220,10 @@ impl<D, S> Canvas<D, S> {
|
|||||||
cmd_buffer.end_render_pass()?;
|
cmd_buffer.end_render_pass()?;
|
||||||
cmd_buffer.build_and_execute_now()
|
cmd_buffer.build_and_execute_now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn data_mut(&mut self) -> &mut D {
|
||||||
|
&mut self.canvas.data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D, S> InteractionHandler for Canvas<D, S> {
|
impl<D, S> InteractionHandler for Canvas<D, S> {
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ use std::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{
|
backend::{
|
||||||
input::PointerMode,
|
input::{InteractionHandler, PointerMode},
|
||||||
overlay::{OverlayData, OverlayState},
|
overlay::{OverlayBackend, OverlayData, OverlayRenderer, OverlayState},
|
||||||
},
|
},
|
||||||
config::{self, ConfigType},
|
config::{self, ConfigType},
|
||||||
gui::{
|
gui::{
|
||||||
canvas::{builder::CanvasBuilder, control::Control},
|
canvas::{builder::CanvasBuilder, control::Control, Canvas},
|
||||||
color_parse, KeyCapType,
|
color_parse, KeyCapType,
|
||||||
},
|
},
|
||||||
hid::{
|
hid::{
|
||||||
@@ -180,7 +180,7 @@ where
|
|||||||
interaction_transform,
|
interaction_transform,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
backend: Box::new(canvas),
|
backend: Box::new(KeyboardBackend { canvas }),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -435,3 +435,68 @@ fn key_events_for_macro(macro_verbs: &Vec<String>) -> Vec<(VirtualKey, bool)> {
|
|||||||
}
|
}
|
||||||
key_events
|
key_events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct KeyboardBackend {
|
||||||
|
canvas: Canvas<KeyboardData, KeyButtonData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OverlayBackend for KeyboardBackend {
|
||||||
|
fn set_interaction(&mut self, interaction: Box<dyn crate::backend::input::InteractionHandler>) {
|
||||||
|
self.canvas.set_interaction(interaction)
|
||||||
|
}
|
||||||
|
fn set_renderer(&mut self, renderer: Box<dyn crate::backend::overlay::OverlayRenderer>) {
|
||||||
|
self.canvas.set_renderer(renderer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InteractionHandler for KeyboardBackend {
|
||||||
|
fn on_pointer(
|
||||||
|
&mut self,
|
||||||
|
app: &mut AppState,
|
||||||
|
hit: &crate::backend::input::PointerHit,
|
||||||
|
pressed: bool,
|
||||||
|
) {
|
||||||
|
self.canvas.on_pointer(app, hit, pressed)
|
||||||
|
}
|
||||||
|
fn on_scroll(
|
||||||
|
&mut self,
|
||||||
|
app: &mut AppState,
|
||||||
|
hit: &crate::backend::input::PointerHit,
|
||||||
|
delta: f32,
|
||||||
|
) {
|
||||||
|
self.canvas.on_scroll(app, hit, delta)
|
||||||
|
}
|
||||||
|
fn on_left(&mut self, app: &mut AppState, pointer: usize) {
|
||||||
|
self.canvas.on_left(app, pointer)
|
||||||
|
}
|
||||||
|
fn on_hover(
|
||||||
|
&mut self,
|
||||||
|
app: &mut AppState,
|
||||||
|
hit: &crate::backend::input::PointerHit,
|
||||||
|
) -> Option<crate::backend::input::Haptics> {
|
||||||
|
self.canvas.on_hover(app, hit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OverlayRenderer for KeyboardBackend {
|
||||||
|
fn init(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||||
|
self.canvas.init(app)
|
||||||
|
}
|
||||||
|
fn render(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||||
|
self.canvas.render(app)
|
||||||
|
}
|
||||||
|
fn extent(&mut self) -> Option<[u32; 3]> {
|
||||||
|
self.canvas.extent()
|
||||||
|
}
|
||||||
|
fn view(&mut self) -> Option<std::sync::Arc<vulkano::image::view::ImageView>> {
|
||||||
|
self.canvas.view()
|
||||||
|
}
|
||||||
|
fn pause(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||||
|
self.canvas.data_mut().modifiers = 0;
|
||||||
|
app.hid_provider.set_modifiers(0);
|
||||||
|
self.canvas.pause(app)
|
||||||
|
}
|
||||||
|
fn resume(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||||
|
self.canvas.resume(app)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user