Merge remote-tracking branch 'origin/main' into next-dash-interface
[skip ci]
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
|
||||
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::{
|
||||
animation::{Animation, AnimationEasing},
|
||||
assets::AssetPath,
|
||||
@@ -39,11 +39,13 @@ pub(super) fn create_keyboard_panel(
|
||||
let globals = app.wgui_globals.clone();
|
||||
let accent_color = globals.get().defaults.accent_color;
|
||||
|
||||
let anim_mult = globals.defaults().animation_mult;
|
||||
|
||||
let (background, _) = panel.layout.add_child(
|
||||
panel.layout.content_root_widget,
|
||||
WidgetRectangle::create(WidgetRectangleParams {
|
||||
color: wgui::drawing::Color::new(0., 0., 0., 0.75),
|
||||
round: WLength::Units(16.0),
|
||||
color: globals.defaults().bg_color,
|
||||
round: WLength::Units((16.0 * globals.defaults().rounding_mult).max(0.)),
|
||||
border: 2.0,
|
||||
border_color: accent_color,
|
||||
..Default::default()
|
||||
@@ -169,6 +171,8 @@ pub(super) fn create_keyboard_panel(
|
||||
})
|
||||
};
|
||||
|
||||
let width_mul = 1. / my_size_f32;
|
||||
|
||||
panel.add_event_listener(
|
||||
widget_id,
|
||||
EventListenerKind::MouseEnter,
|
||||
@@ -176,7 +180,14 @@ pub(super) fn create_keyboard_panel(
|
||||
let k = key_state.clone();
|
||||
move |common, data, _app, _state| {
|
||||
common.alterables.trigger_haptics();
|
||||
on_enter_anim(k.clone(), common, data, accent_color);
|
||||
on_enter_anim(
|
||||
k.clone(),
|
||||
common,
|
||||
data,
|
||||
accent_color,
|
||||
anim_mult,
|
||||
width_mul,
|
||||
);
|
||||
Ok(EventResult::Pass)
|
||||
}
|
||||
}),
|
||||
@@ -188,7 +199,14 @@ pub(super) fn create_keyboard_panel(
|
||||
let k = key_state.clone();
|
||||
move |common, data, _app, _state| {
|
||||
common.alterables.trigger_haptics();
|
||||
on_leave_anim(k.clone(), common, data, accent_color);
|
||||
on_leave_anim(
|
||||
k.clone(),
|
||||
common,
|
||||
data,
|
||||
accent_color,
|
||||
anim_mult,
|
||||
width_mul,
|
||||
);
|
||||
Ok(EventResult::Pass)
|
||||
}
|
||||
}),
|
||||
@@ -254,11 +272,14 @@ pub(super) fn create_keyboard_panel(
|
||||
|
||||
const BUTTON_HOVER_SCALE: f32 = 0.1;
|
||||
|
||||
fn get_anim_transform(pos: f32, widget_size: Vec2) -> Mat4 {
|
||||
util::centered_matrix(
|
||||
widget_size,
|
||||
&Mat4::from_scale(Vec3::splat(BUTTON_HOVER_SCALE.mul_add(pos, 1.0))),
|
||||
)
|
||||
fn get_anim_transform(pos: f32, widget_size: Vec2, width_mult: f32) -> Mat4 {
|
||||
let scale = vec3(
|
||||
(BUTTON_HOVER_SCALE * width_mult).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(
|
||||
@@ -291,15 +312,18 @@ fn on_enter_anim(
|
||||
common: &mut event::CallbackDataCommon,
|
||||
data: &event::CallbackData,
|
||||
accent_color: drawing::Color,
|
||||
anim_mult: f32,
|
||||
width_mult: f32,
|
||||
) {
|
||||
common.alterables.animate(Animation::new(
|
||||
data.widget_id,
|
||||
10,
|
||||
(10. * anim_mult) as _,
|
||||
AnimationEasing::OutBack,
|
||||
Box::new(move |common, data| {
|
||||
let rect = data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||
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();
|
||||
}),
|
||||
));
|
||||
@@ -310,15 +334,18 @@ fn on_leave_anim(
|
||||
common: &mut event::CallbackDataCommon,
|
||||
data: &event::CallbackData,
|
||||
accent_color: drawing::Color,
|
||||
anim_mult: f32,
|
||||
width_mult: f32,
|
||||
) {
|
||||
common.alterables.animate(Animation::new(
|
||||
data.widget_id,
|
||||
15,
|
||||
(15. * anim_mult) as _,
|
||||
AnimationEasing::OutQuad,
|
||||
Box::new(move |common, data| {
|
||||
let rect = data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||
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();
|
||||
}),
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user