fix keycap scaling anim
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::{collections::HashMap, rc::Rc};
|
use std::{collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
use crate::{gui::panel::GuiPanel, state::AppState, subsystem::hid::XkbKeymap};
|
use crate::{gui::panel::GuiPanel, state::AppState, subsystem::hid::XkbKeymap};
|
||||||
use glam::{FloatExt, Mat4, Vec2, Vec3, vec2};
|
use glam::{FloatExt, Mat4, Vec2, vec2, vec3};
|
||||||
use wgui::{
|
use wgui::{
|
||||||
animation::{Animation, AnimationEasing},
|
animation::{Animation, AnimationEasing},
|
||||||
assets::AssetPath,
|
assets::AssetPath,
|
||||||
@@ -171,6 +171,8 @@ pub(super) fn create_keyboard_panel(
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let width_mul = 1. / my_size_f32;
|
||||||
|
|
||||||
panel.add_event_listener(
|
panel.add_event_listener(
|
||||||
widget_id,
|
widget_id,
|
||||||
EventListenerKind::MouseEnter,
|
EventListenerKind::MouseEnter,
|
||||||
@@ -178,7 +180,14 @@ pub(super) fn create_keyboard_panel(
|
|||||||
let k = key_state.clone();
|
let k = key_state.clone();
|
||||||
move |common, data, _app, _state| {
|
move |common, data, _app, _state| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
on_enter_anim(k.clone(), common, data, accent_color, anim_mult);
|
on_enter_anim(
|
||||||
|
k.clone(),
|
||||||
|
common,
|
||||||
|
data,
|
||||||
|
accent_color,
|
||||||
|
anim_mult,
|
||||||
|
width_mul,
|
||||||
|
);
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -190,7 +199,14 @@ pub(super) fn create_keyboard_panel(
|
|||||||
let k = key_state.clone();
|
let k = key_state.clone();
|
||||||
move |common, data, _app, _state| {
|
move |common, data, _app, _state| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
on_leave_anim(k.clone(), common, data, accent_color, anim_mult);
|
on_leave_anim(
|
||||||
|
k.clone(),
|
||||||
|
common,
|
||||||
|
data,
|
||||||
|
accent_color,
|
||||||
|
anim_mult,
|
||||||
|
width_mul,
|
||||||
|
);
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -256,11 +272,14 @@ pub(super) fn create_keyboard_panel(
|
|||||||
|
|
||||||
const BUTTON_HOVER_SCALE: f32 = 0.1;
|
const BUTTON_HOVER_SCALE: f32 = 0.1;
|
||||||
|
|
||||||
fn get_anim_transform(pos: f32, widget_size: Vec2) -> Mat4 {
|
fn get_anim_transform(pos: f32, widget_size: Vec2, width_mult: f32) -> Mat4 {
|
||||||
util::centered_matrix(
|
let scale = vec3(
|
||||||
widget_size,
|
(BUTTON_HOVER_SCALE * width_mult).mul_add(pos, 1.0),
|
||||||
&Mat4::from_scale(Vec3::splat(BUTTON_HOVER_SCALE.mul_add(pos, 1.0))),
|
BUTTON_HOVER_SCALE.mul_add(pos, 1.0),
|
||||||
)
|
1.0,
|
||||||
|
);
|
||||||
|
|
||||||
|
util::centered_matrix(widget_size, &Mat4::from_scale(scale))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_anim_color(
|
fn set_anim_color(
|
||||||
@@ -294,6 +313,7 @@ fn on_enter_anim(
|
|||||||
data: &event::CallbackData,
|
data: &event::CallbackData,
|
||||||
accent_color: drawing::Color,
|
accent_color: drawing::Color,
|
||||||
anim_mult: f32,
|
anim_mult: f32,
|
||||||
|
width_mult: f32,
|
||||||
) {
|
) {
|
||||||
common.alterables.animate(Animation::new(
|
common.alterables.animate(Animation::new(
|
||||||
data.widget_id,
|
data.widget_id,
|
||||||
@@ -302,7 +322,8 @@ fn on_enter_anim(
|
|||||||
Box::new(move |common, data| {
|
Box::new(move |common, data| {
|
||||||
let rect = data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
let rect = data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||||
set_anim_color(&key_state, rect, data.pos, accent_color);
|
set_anim_color(&key_state, rect, data.pos, accent_color);
|
||||||
data.data.transform = get_anim_transform(data.pos, data.widget_boundary.size);
|
data.data.transform =
|
||||||
|
get_anim_transform(data.pos, data.widget_boundary.size, width_mult);
|
||||||
common.alterables.mark_redraw();
|
common.alterables.mark_redraw();
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
@@ -314,6 +335,7 @@ fn on_leave_anim(
|
|||||||
data: &event::CallbackData,
|
data: &event::CallbackData,
|
||||||
accent_color: drawing::Color,
|
accent_color: drawing::Color,
|
||||||
anim_mult: f32,
|
anim_mult: f32,
|
||||||
|
width_mult: f32,
|
||||||
) {
|
) {
|
||||||
common.alterables.animate(Animation::new(
|
common.alterables.animate(Animation::new(
|
||||||
data.widget_id,
|
data.widget_id,
|
||||||
@@ -322,7 +344,8 @@ fn on_leave_anim(
|
|||||||
Box::new(move |common, data| {
|
Box::new(move |common, data| {
|
||||||
let rect = data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
let rect = data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||||
set_anim_color(&key_state, rect, 1.0 - data.pos, accent_color);
|
set_anim_color(&key_state, rect, 1.0 - data.pos, accent_color);
|
||||||
data.data.transform = get_anim_transform(1.0 - data.pos, data.widget_boundary.size);
|
data.data.transform =
|
||||||
|
get_anim_transform(1.0 - data.pos, data.widget_boundary.size, width_mult);
|
||||||
common.alterables.mark_redraw();
|
common.alterables.mark_redraw();
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user