settings for text+bg colors, anim speed, rounding
This commit is contained in:
@@ -124,7 +124,7 @@ impl ToastManager {
|
|||||||
// show-up animation
|
// show-up animation
|
||||||
layout.animations.add(Animation::new(
|
layout.animations.add(Animation::new(
|
||||||
rect.id,
|
rect.id,
|
||||||
160,
|
160, // does not use anim_mult
|
||||||
AnimationEasing::Linear,
|
AnimationEasing::Linear,
|
||||||
Box::new(move |common, data| {
|
Box::new(move |common, data| {
|
||||||
let pos_showup = AnimationEasing::OutQuint.interpolate((data.pos * 4.0).min(1.0));
|
let pos_showup = AnimationEasing::OutQuint.interpolate((data.pos * 4.0).min(1.0));
|
||||||
|
|||||||
@@ -1,29 +1,30 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
animation::{Animation, AnimationEasing},
|
animation::{Animation, AnimationEasing},
|
||||||
assets::AssetPath,
|
assets::AssetPath,
|
||||||
components::{self, Component, ComponentBase, ComponentTrait, RefreshData, tooltip::ComponentTooltip},
|
components::{self, tooltip::ComponentTooltip, Component, ComponentBase, ComponentTrait, RefreshData},
|
||||||
drawing::{self, Boundary, Color},
|
drawing::{self, Boundary, Color},
|
||||||
event::{CallbackDataCommon, EventListenerCollection, EventListenerID, EventListenerKind},
|
event::{CallbackDataCommon, EventListenerCollection, EventListenerID, EventListenerKind},
|
||||||
i18n::Translation,
|
i18n::Translation,
|
||||||
layout::{LayoutTask, WidgetID, WidgetPair},
|
layout::{LayoutTask, WidgetID, WidgetPair},
|
||||||
renderer_vk::{
|
renderer_vk::{
|
||||||
text::{
|
text::{
|
||||||
FontWeight, TextStyle,
|
|
||||||
custom_glyph::{CustomGlyphContent, CustomGlyphData},
|
custom_glyph::{CustomGlyphContent, CustomGlyphData},
|
||||||
|
FontWeight, TextStyle,
|
||||||
},
|
},
|
||||||
util::centered_matrix,
|
util::centered_matrix,
|
||||||
},
|
},
|
||||||
widget::{
|
widget::{
|
||||||
self, ConstructEssentials, EventResult, WidgetData,
|
self,
|
||||||
label::{WidgetLabel, WidgetLabelParams},
|
label::{WidgetLabel, WidgetLabelParams},
|
||||||
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
||||||
sprite::{WidgetSprite, WidgetSpriteParams},
|
sprite::{WidgetSprite, WidgetSpriteParams},
|
||||||
util::WLength,
|
util::WLength,
|
||||||
|
ConstructEssentials, EventResult, WidgetData,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use glam::{Mat4, Vec3};
|
use glam::{Mat4, Vec3};
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
use taffy::{AlignItems, JustifyContent, prelude::length};
|
use taffy::{prelude::length, AlignItems, JustifyContent};
|
||||||
|
|
||||||
pub struct Params<'a> {
|
pub struct Params<'a> {
|
||||||
pub text: Option<Translation>, // if unset, label will not be populated
|
pub text: Option<Translation>, // if unset, label will not be populated
|
||||||
@@ -170,10 +171,13 @@ impl ComponentButton {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let anim_mult = common.state.globals.defaults().animation_mult;
|
||||||
|
let anim_ticks = if sticky_down { 5. } else { 10. };
|
||||||
|
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
let anim = Animation::new(
|
let anim = Animation::new(
|
||||||
self.data.id_rect,
|
self.data.id_rect,
|
||||||
if sticky_down { 5 } else { 10 },
|
(anim_ticks * anim_mult) as _,
|
||||||
AnimationEasing::OutCubic,
|
AnimationEasing::OutCubic,
|
||||||
Box::new(move |common, anim_data| {
|
Box::new(move |common, anim_data| {
|
||||||
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||||
@@ -227,10 +231,10 @@ fn anim_hover(
|
|||||||
rect.params.border_color = init_border_color.lerp(&colors.hover_border_color, mult);
|
rect.params.border_color = init_border_color.lerp(&colors.hover_border_color, mult);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anim_hover_create(state: Rc<RefCell<State>>, widget_id: WidgetID, fade_in: bool) -> Animation {
|
fn anim_hover_create(state: Rc<RefCell<State>>, widget_id: WidgetID, fade_in: bool, anim_mult: f32) -> Animation {
|
||||||
Animation::new(
|
Animation::new(
|
||||||
widget_id,
|
widget_id,
|
||||||
if fade_in { 5 } else { 10 },
|
((if fade_in { 5. } else { 10. }) * anim_mult) as _,
|
||||||
AnimationEasing::OutCubic,
|
AnimationEasing::OutCubic,
|
||||||
Box::new(move |common, anim_data| {
|
Box::new(move |common, anim_data| {
|
||||||
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||||
@@ -254,6 +258,7 @@ fn register_event_mouse_enter(
|
|||||||
state: Rc<RefCell<State>>,
|
state: Rc<RefCell<State>>,
|
||||||
listeners: &mut EventListenerCollection,
|
listeners: &mut EventListenerCollection,
|
||||||
info: Option<components::tooltip::TooltipInfo>,
|
info: Option<components::tooltip::TooltipInfo>,
|
||||||
|
anim_mult: f32,
|
||||||
) -> EventListenerID {
|
) -> EventListenerID {
|
||||||
listeners.register(
|
listeners.register(
|
||||||
EventListenerKind::MouseEnter,
|
EventListenerKind::MouseEnter,
|
||||||
@@ -262,7 +267,7 @@ fn register_event_mouse_enter(
|
|||||||
common.alterables.mark_redraw();
|
common.alterables.mark_redraw();
|
||||||
common
|
common
|
||||||
.alterables
|
.alterables
|
||||||
.animate(anim_hover_create(state.clone(), event_data.widget_id, true));
|
.animate(anim_hover_create(state.clone(), event_data.widget_id, true, anim_mult));
|
||||||
|
|
||||||
if let Some(info) = info.clone() {
|
if let Some(info) = info.clone() {
|
||||||
common.alterables.tasks.push(LayoutTask::ModifyLayoutState({
|
common.alterables.tasks.push(LayoutTask::ModifyLayoutState({
|
||||||
@@ -282,14 +287,18 @@ fn register_event_mouse_enter(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_event_mouse_leave(state: Rc<RefCell<State>>, listeners: &mut EventListenerCollection) -> EventListenerID {
|
fn register_event_mouse_leave(
|
||||||
|
state: Rc<RefCell<State>>,
|
||||||
|
listeners: &mut EventListenerCollection,
|
||||||
|
anim_mult: f32,
|
||||||
|
) -> EventListenerID {
|
||||||
listeners.register(
|
listeners.register(
|
||||||
EventListenerKind::MouseLeave,
|
EventListenerKind::MouseLeave,
|
||||||
Box::new(move |common, event_data, (), ()| {
|
Box::new(move |common, event_data, (), ()| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
common
|
common
|
||||||
.alterables
|
.alterables
|
||||||
.animate(anim_hover_create(state.clone(), event_data.widget_id, false));
|
.animate(anim_hover_create(state.clone(), event_data.widget_id, false, anim_mult));
|
||||||
let mut state = state.borrow_mut();
|
let mut state = state.borrow_mut();
|
||||||
state.active_tooltip = None;
|
state.active_tooltip = None;
|
||||||
state.hovered = false;
|
state.hovered = false;
|
||||||
@@ -510,9 +519,16 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
|
|||||||
id: root.id,
|
id: root.id,
|
||||||
lhandles: {
|
lhandles: {
|
||||||
let mut widget = ess.layout.state.widgets.get(id_rect).unwrap().state();
|
let mut widget = ess.layout.state.widgets.get(id_rect).unwrap().state();
|
||||||
|
let anim_mult = ess.layout.state.globals.defaults().animation_mult;
|
||||||
vec![
|
vec![
|
||||||
register_event_mouse_enter(data.clone(), state.clone(), &mut widget.event_listeners, params.tooltip),
|
register_event_mouse_enter(
|
||||||
register_event_mouse_leave(state.clone(), &mut widget.event_listeners),
|
data.clone(),
|
||||||
|
state.clone(),
|
||||||
|
&mut widget.event_listeners,
|
||||||
|
params.tooltip,
|
||||||
|
anim_mult,
|
||||||
|
),
|
||||||
|
register_event_mouse_leave(state.clone(), &mut widget.event_listeners, anim_mult),
|
||||||
register_event_mouse_press(state.clone(), &mut widget.event_listeners),
|
register_event_mouse_press(state.clone(), &mut widget.event_listeners),
|
||||||
register_event_mouse_release(data.clone(), state.clone(), &mut widget.event_listeners),
|
register_event_mouse_release(data.clone(), state.clone(), &mut widget.event_listeners),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
use taffy::{
|
use taffy::{
|
||||||
AlignItems,
|
|
||||||
prelude::{length, percent},
|
prelude::{length, percent},
|
||||||
|
AlignItems,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -13,10 +13,10 @@ use crate::{
|
|||||||
layout::{self, WidgetID, WidgetPair},
|
layout::{self, WidgetID, WidgetPair},
|
||||||
renderer_vk::text::{FontWeight, TextStyle},
|
renderer_vk::text::{FontWeight, TextStyle},
|
||||||
widget::{
|
widget::{
|
||||||
ConstructEssentials, EventResult,
|
|
||||||
label::{WidgetLabel, WidgetLabelParams},
|
label::{WidgetLabel, WidgetLabelParams},
|
||||||
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
||||||
util::WLength,
|
util::WLength,
|
||||||
|
ConstructEssentials, EventResult,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,10 +120,10 @@ fn anim_hover(rect: &mut WidgetRectangle, pos: f32, pressed: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anim_hover_in(state: Rc<RefCell<State>>, widget_id: WidgetID) -> Animation {
|
fn anim_hover_in(state: Rc<RefCell<State>>, widget_id: WidgetID, anim_mult: f32) -> Animation {
|
||||||
Animation::new(
|
Animation::new(
|
||||||
widget_id,
|
widget_id,
|
||||||
5,
|
(5. * anim_mult) as _,
|
||||||
AnimationEasing::OutQuad,
|
AnimationEasing::OutQuad,
|
||||||
Box::new(move |common, anim_data| {
|
Box::new(move |common, anim_data| {
|
||||||
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||||
@@ -133,10 +133,10 @@ fn anim_hover_in(state: Rc<RefCell<State>>, widget_id: WidgetID) -> Animation {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anim_hover_out(state: Rc<RefCell<State>>, widget_id: WidgetID) -> Animation {
|
fn anim_hover_out(state: Rc<RefCell<State>>, widget_id: WidgetID, anim_mult: f32) -> Animation {
|
||||||
Animation::new(
|
Animation::new(
|
||||||
widget_id,
|
widget_id,
|
||||||
8,
|
(8. * anim_mult) as _,
|
||||||
AnimationEasing::OutQuad,
|
AnimationEasing::OutQuad,
|
||||||
Box::new(move |common, anim_data| {
|
Box::new(move |common, anim_data| {
|
||||||
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
let rect = anim_data.obj.get_as_mut::<WidgetRectangle>().unwrap();
|
||||||
@@ -146,28 +146,36 @@ fn anim_hover_out(state: Rc<RefCell<State>>, widget_id: WidgetID) -> Animation {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_event_mouse_enter(state: Rc<RefCell<State>>, listeners: &mut EventListenerCollection) -> EventListenerID {
|
fn register_event_mouse_enter(
|
||||||
|
state: Rc<RefCell<State>>,
|
||||||
|
listeners: &mut EventListenerCollection,
|
||||||
|
anim_mult: f32,
|
||||||
|
) -> EventListenerID {
|
||||||
listeners.register(
|
listeners.register(
|
||||||
EventListenerKind::MouseEnter,
|
EventListenerKind::MouseEnter,
|
||||||
Box::new(move |common, event_data, (), ()| {
|
Box::new(move |common, event_data, (), ()| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
common
|
common
|
||||||
.alterables
|
.alterables
|
||||||
.animate(anim_hover_in(state.clone(), event_data.widget_id));
|
.animate(anim_hover_in(state.clone(), event_data.widget_id, anim_mult));
|
||||||
state.borrow_mut().hovered = true;
|
state.borrow_mut().hovered = true;
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_event_mouse_leave(state: Rc<RefCell<State>>, listeners: &mut EventListenerCollection) -> EventListenerID {
|
fn register_event_mouse_leave(
|
||||||
|
state: Rc<RefCell<State>>,
|
||||||
|
listeners: &mut EventListenerCollection,
|
||||||
|
anim_mult: f32,
|
||||||
|
) -> EventListenerID {
|
||||||
listeners.register(
|
listeners.register(
|
||||||
EventListenerKind::MouseLeave,
|
EventListenerKind::MouseLeave,
|
||||||
Box::new(move |common, event_data, (), ()| {
|
Box::new(move |common, event_data, (), ()| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
common
|
common
|
||||||
.alterables
|
.alterables
|
||||||
.animate(anim_hover_out(state.clone(), event_data.widget_id));
|
.animate(anim_hover_out(state.clone(), event_data.widget_id, anim_mult));
|
||||||
state.borrow_mut().hovered = false;
|
state.borrow_mut().hovered = false;
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}),
|
}),
|
||||||
@@ -341,9 +349,10 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
|
|||||||
id: root.id,
|
id: root.id,
|
||||||
lhandles: {
|
lhandles: {
|
||||||
let mut widget = ess.layout.state.widgets.get(id_container).unwrap().state();
|
let mut widget = ess.layout.state.widgets.get(id_container).unwrap().state();
|
||||||
|
let anim_mult = ess.layout.state.globals.defaults().animation_mult;
|
||||||
vec![
|
vec![
|
||||||
register_event_mouse_enter(state.clone(), &mut widget.event_listeners),
|
register_event_mouse_enter(state.clone(), &mut widget.event_listeners, anim_mult),
|
||||||
register_event_mouse_leave(state.clone(), &mut widget.event_listeners),
|
register_event_mouse_leave(state.clone(), &mut widget.event_listeners, anim_mult),
|
||||||
register_event_mouse_press(state.clone(), &mut widget.event_listeners),
|
register_event_mouse_press(state.clone(), &mut widget.event_listeners),
|
||||||
register_event_mouse_release(data.clone(), state.clone(), &mut widget.event_listeners),
|
register_event_mouse_release(data.clone(), state.clone(), &mut widget.event_listeners),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ use crate::{
|
|||||||
util,
|
util,
|
||||||
},
|
},
|
||||||
widget::{
|
widget::{
|
||||||
ConstructEssentials, EventResult,
|
|
||||||
div::WidgetDiv,
|
div::WidgetDiv,
|
||||||
label::{WidgetLabel, WidgetLabelParams},
|
label::{WidgetLabel, WidgetLabelParams},
|
||||||
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
rectangle::{WidgetRectangle, WidgetRectangleParams},
|
||||||
util::WLength,
|
util::WLength,
|
||||||
|
ConstructEssentials, EventResult,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -263,10 +263,10 @@ fn anim_rect(rect: &mut WidgetRectangle, pos: f32) {
|
|||||||
rect.params.border_color = drawing::Color::lerp(&HANDLE_BORDER_COLOR, &HANDLE_BORDER_COLOR_HOVERED, pos);
|
rect.params.border_color = drawing::Color::lerp(&HANDLE_BORDER_COLOR, &HANDLE_BORDER_COLOR_HOVERED, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter_anim(common: &mut event::CallbackDataCommon, handle_id: WidgetID) {
|
fn on_enter_anim(common: &mut event::CallbackDataCommon, handle_id: WidgetID, anim_mult: f32) {
|
||||||
common.alterables.animate(Animation::new(
|
common.alterables.animate(Animation::new(
|
||||||
handle_id,
|
handle_id,
|
||||||
20,
|
(20. * anim_mult) as _,
|
||||||
AnimationEasing::OutBack,
|
AnimationEasing::OutBack,
|
||||||
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();
|
||||||
@@ -277,10 +277,10 @@ fn on_enter_anim(common: &mut event::CallbackDataCommon, handle_id: WidgetID) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_leave_anim(common: &mut event::CallbackDataCommon, handle_id: WidgetID) {
|
fn on_leave_anim(common: &mut event::CallbackDataCommon, handle_id: WidgetID, anim_mult: f32) {
|
||||||
common.alterables.animate(Animation::new(
|
common.alterables.animate(Animation::new(
|
||||||
handle_id,
|
handle_id,
|
||||||
10,
|
(10. * anim_mult) as _,
|
||||||
AnimationEasing::OutQuad,
|
AnimationEasing::OutQuad,
|
||||||
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();
|
||||||
@@ -295,13 +295,14 @@ fn register_event_mouse_enter(
|
|||||||
data: Rc<Data>,
|
data: Rc<Data>,
|
||||||
state: Rc<RefCell<State>>,
|
state: Rc<RefCell<State>>,
|
||||||
listeners: &mut EventListenerCollection,
|
listeners: &mut EventListenerCollection,
|
||||||
|
anim_mult: f32,
|
||||||
) -> event::EventListenerID {
|
) -> event::EventListenerID {
|
||||||
listeners.register(
|
listeners.register(
|
||||||
EventListenerKind::MouseEnter,
|
EventListenerKind::MouseEnter,
|
||||||
Box::new(move |common, _data, (), ()| {
|
Box::new(move |common, _data, (), ()| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
state.borrow_mut().hovered = true;
|
state.borrow_mut().hovered = true;
|
||||||
on_enter_anim(common, data.slider_handle_rect_id);
|
on_enter_anim(common, data.slider_handle_rect_id, anim_mult);
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -311,13 +312,14 @@ fn register_event_mouse_leave(
|
|||||||
data: Rc<Data>,
|
data: Rc<Data>,
|
||||||
state: Rc<RefCell<State>>,
|
state: Rc<RefCell<State>>,
|
||||||
listeners: &mut EventListenerCollection,
|
listeners: &mut EventListenerCollection,
|
||||||
|
anim_mult: f32,
|
||||||
) -> event::EventListenerID {
|
) -> event::EventListenerID {
|
||||||
listeners.register(
|
listeners.register(
|
||||||
EventListenerKind::MouseLeave,
|
EventListenerKind::MouseLeave,
|
||||||
Box::new(move |common, _data, (), ()| {
|
Box::new(move |common, _data, (), ()| {
|
||||||
common.alterables.trigger_haptics();
|
common.alterables.trigger_haptics();
|
||||||
state.borrow_mut().hovered = false;
|
state.borrow_mut().hovered = false;
|
||||||
on_leave_anim(common, data.slider_handle_rect_id);
|
on_leave_anim(common, data.slider_handle_rect_id, anim_mult);
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -500,12 +502,12 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
|
|||||||
id: root.id,
|
id: root.id,
|
||||||
lhandles: {
|
lhandles: {
|
||||||
let mut widget = ess.layout.state.widgets.get(body_id).unwrap().state();
|
let mut widget = ess.layout.state.widgets.get(body_id).unwrap().state();
|
||||||
|
let anim_mult = ess.layout.state.globals.defaults().animation_mult;
|
||||||
vec![
|
vec![
|
||||||
register_event_mouse_enter(data.clone(), state.clone(), &mut widget.event_listeners),
|
register_event_mouse_enter(data.clone(), state.clone(), &mut widget.event_listeners, anim_mult),
|
||||||
register_event_mouse_leave(data.clone(), state.clone(), &mut widget.event_listeners),
|
register_event_mouse_leave(data.clone(), state.clone(), &mut widget.event_listeners, anim_mult),
|
||||||
register_event_mouse_motion(data.clone(), state.clone(), &mut widget.event_listeners),
|
register_event_mouse_motion(data.clone(), state.clone(), &mut widget.event_listeners),
|
||||||
register_event_mouse_press(data.clone(), state.clone(), &mut widget.event_listeners),
|
register_event_mouse_press(data.clone(), state.clone(), &mut widget.event_listeners),
|
||||||
register_event_mouse_leave(data.clone(), state.clone(), &mut widget.event_listeners),
|
|
||||||
register_event_mouse_release(state.clone(), &mut widget.event_listeners),
|
register_event_mouse_release(state.clone(), &mut widget.event_listeners),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ pub struct Defaults {
|
|||||||
pub accent_color: drawing::Color,
|
pub accent_color: drawing::Color,
|
||||||
pub danger_color: drawing::Color,
|
pub danger_color: drawing::Color,
|
||||||
pub faded_color: drawing::Color,
|
pub faded_color: drawing::Color,
|
||||||
|
pub bg_color: drawing::Color,
|
||||||
pub translucent_alpha: f32,
|
pub translucent_alpha: f32,
|
||||||
|
pub animation_mult: f32,
|
||||||
|
pub rounding_mult: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Defaults {
|
impl Default for Defaults {
|
||||||
@@ -34,7 +37,10 @@ impl Default for Defaults {
|
|||||||
accent_color: drawing::Color::new(0.0, 0.54, 1.0, 1.0),
|
accent_color: drawing::Color::new(0.0, 0.54, 1.0, 1.0),
|
||||||
danger_color: drawing::Color::new(0.8, 0.0, 0.0, 1.0),
|
danger_color: drawing::Color::new(0.8, 0.0, 0.0, 1.0),
|
||||||
faded_color: drawing::Color::new(0.4, 0.5, 0.6, 1.0),
|
faded_color: drawing::Color::new(0.4, 0.5, 0.6, 1.0),
|
||||||
|
bg_color: drawing::Color::new(0.0039, 0.0078, 0.0235, 0.8352),
|
||||||
translucent_alpha: 0.25,
|
translucent_alpha: 0.25,
|
||||||
|
animation_mult: 1.0,
|
||||||
|
rounding_mult: 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
assets::AssetPath,
|
assets::AssetPath,
|
||||||
components::{Component, button, tooltip},
|
components::{button, tooltip, Component},
|
||||||
drawing::Color,
|
drawing::Color,
|
||||||
i18n::Translation,
|
i18n::Translation,
|
||||||
layout::WidgetID,
|
layout::WidgetID,
|
||||||
parser::{
|
parser::{
|
||||||
AttribPair, ParserContext, ParserFile, parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib,
|
parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib, process_component,
|
||||||
process_component,
|
|
||||||
style::{parse_color_opt, parse_round, parse_style, parse_text_style},
|
style::{parse_color_opt, parse_round, parse_style, parse_text_style},
|
||||||
|
AttribPair, ParserContext, ParserFile,
|
||||||
},
|
},
|
||||||
widget::util::WLength,
|
widget::util::WLength,
|
||||||
};
|
};
|
||||||
@@ -45,7 +45,7 @@ pub fn parse_component_button<'a>(
|
|||||||
translation = Some(Translation::from_translation_key(value));
|
translation = Some(Translation::from_translation_key(value));
|
||||||
}
|
}
|
||||||
"round" => {
|
"round" => {
|
||||||
parse_round(value, &mut round);
|
parse_round(value, &mut round, ctx.doc_params.globals.get().defaults.rounding_mult);
|
||||||
}
|
}
|
||||||
"color" => {
|
"color" => {
|
||||||
parse_color_opt(value, &mut color);
|
parse_color_opt(value, &mut color);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ mod widget_rectangle;
|
|||||||
mod widget_sprite;
|
mod widget_sprite;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assets::{AssetPath, AssetPathOwned, normalize_path},
|
assets::{normalize_path, AssetPath, AssetPathOwned},
|
||||||
components::{Component, ComponentWeak},
|
components::{Component, ComponentWeak},
|
||||||
drawing::{self},
|
drawing::{self},
|
||||||
globals::WguiGlobals,
|
globals::WguiGlobals,
|
||||||
@@ -400,6 +400,7 @@ impl ParserContext<'_> {
|
|||||||
insert_color_vars!(self, "accent", def.accent_color, def.translucent_alpha);
|
insert_color_vars!(self, "accent", def.accent_color, def.translucent_alpha);
|
||||||
insert_color_vars!(self, "danger", def.danger_color, def.translucent_alpha);
|
insert_color_vars!(self, "danger", def.danger_color, def.translucent_alpha);
|
||||||
insert_color_vars!(self, "faded", def.faded_color, def.translucent_alpha);
|
insert_color_vars!(self, "faded", def.faded_color, def.translucent_alpha);
|
||||||
|
insert_color_vars!(self, "bg", def.bg_color, def.translucent_alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ use taffy::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
drawing,
|
drawing,
|
||||||
parser::{
|
parser::{
|
||||||
AttribPair, is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val,
|
is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val, print_invalid_attrib,
|
||||||
print_invalid_attrib, print_invalid_value,
|
print_invalid_value, AttribPair,
|
||||||
},
|
},
|
||||||
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
|
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
|
||||||
widget::util::WLength,
|
widget::util::WLength,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn parse_round(value: &str, round: &mut WLength) {
|
pub fn parse_round(value: &str, round: &mut WLength, multiplier: f32) {
|
||||||
if is_percent(value) {
|
if is_percent(value) {
|
||||||
if let Some(val) = parse_percent(value) {
|
if let Some(val) = parse_percent(value) {
|
||||||
*round = WLength::Percent(val);
|
*round = WLength::Percent((val * multiplier).clamp(0., 1.));
|
||||||
} else {
|
} else {
|
||||||
print_invalid_value(value);
|
print_invalid_value(value);
|
||||||
}
|
}
|
||||||
} else if let Some(val) = parse_f32(value) {
|
} else if let Some(val) = parse_f32(value) {
|
||||||
*round = WLength::Units(val);
|
*round = WLength::Units((val * multiplier).max(0.));
|
||||||
} else {
|
} else {
|
||||||
print_invalid_value(value);
|
print_invalid_value(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ use crate::{
|
|||||||
drawing::GradientMode,
|
drawing::GradientMode,
|
||||||
layout::WidgetID,
|
layout::WidgetID,
|
||||||
parser::{
|
parser::{
|
||||||
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, print_invalid_attrib,
|
parse_children, parse_widget_universal, print_invalid_attrib,
|
||||||
style::{parse_color, parse_round, parse_style},
|
style::{parse_color, parse_round, parse_style},
|
||||||
|
AttribPair, ParserContext, ParserFile,
|
||||||
},
|
},
|
||||||
widget::rectangle::{WidgetRectangle, WidgetRectangleParams},
|
widget::rectangle::{WidgetRectangle, WidgetRectangleParams},
|
||||||
};
|
};
|
||||||
@@ -40,7 +41,11 @@ pub fn parse_widget_rectangle<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"round" => {
|
"round" => {
|
||||||
parse_round(value, &mut params.round);
|
parse_round(
|
||||||
|
value,
|
||||||
|
&mut params.round,
|
||||||
|
ctx.doc_params.globals.get().defaults.rounding_mult,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
"border" => {
|
"border" => {
|
||||||
params.border = value.parse().unwrap_or_else(|_| {
|
params.border = value.parse().unwrap_or_else(|_| {
|
||||||
|
|||||||
@@ -92,9 +92,18 @@ pub struct GeneralConfig {
|
|||||||
#[serde(default = "def_theme_path")]
|
#[serde(default = "def_theme_path")]
|
||||||
pub theme_path: Arc<str>,
|
pub theme_path: Arc<str>,
|
||||||
|
|
||||||
|
pub color_text: Option<String>,
|
||||||
pub color_accent: Option<String>,
|
pub color_accent: Option<String>,
|
||||||
pub color_danger: Option<String>,
|
pub color_danger: Option<String>,
|
||||||
pub color_faded: Option<String>,
|
pub color_faded: Option<String>,
|
||||||
|
pub color_background: Option<String>,
|
||||||
|
|
||||||
|
#[serde(default = "def_one")]
|
||||||
|
pub animation_speed: f32,
|
||||||
|
|
||||||
|
#[serde(default = "def_one")]
|
||||||
|
pub round_multiplier: f32,
|
||||||
|
|
||||||
pub default_keymap: Option<String>,
|
pub default_keymap: Option<String>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<template name="KeySpecial">
|
<template name="KeySpecial">
|
||||||
<div macro="keycap_div">
|
<div macro="keycap_div">
|
||||||
<rectangle id="${id}" macro="keycap_rect">
|
<rectangle id="${id}" macro="keycap_rect">
|
||||||
<sprite width="32" height="32" src="keyboard/${text}.svg" />
|
<sprite color="~color_text" width="32" height="32" src="keyboard/${text}.svg" />
|
||||||
</rectangle>
|
</rectangle>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ impl InteractLockHandler {
|
|||||||
&mut self,
|
&mut self,
|
||||||
common: &mut CallbackDataCommon,
|
common: &mut CallbackDataCommon,
|
||||||
app: &mut AppState,
|
app: &mut AppState,
|
||||||
|
anim_mult: f32,
|
||||||
) -> Box<ModifyOverlayTask> {
|
) -> Box<ModifyOverlayTask> {
|
||||||
let defaults = app.wgui_globals.get().defaults.clone();
|
let defaults = app.wgui_globals.get().defaults.clone();
|
||||||
let rect_color = self.color;
|
let rect_color = self.color;
|
||||||
@@ -63,7 +64,7 @@ impl InteractLockHandler {
|
|||||||
let anim = if self.interactable {
|
let anim = if self.interactable {
|
||||||
Animation::new(
|
Animation::new(
|
||||||
self.id,
|
self.id,
|
||||||
10,
|
(10. * anim_mult) as _,
|
||||||
AnimationEasing::OutQuad,
|
AnimationEasing::OutQuad,
|
||||||
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();
|
||||||
@@ -79,7 +80,7 @@ impl InteractLockHandler {
|
|||||||
} else {
|
} else {
|
||||||
Animation::new(
|
Animation::new(
|
||||||
self.id,
|
self.id,
|
||||||
10,
|
(10. * anim_mult) as _,
|
||||||
AnimationEasing::OutBack,
|
AnimationEasing::OutBack,
|
||||||
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();
|
||||||
|
|||||||
@@ -282,6 +282,8 @@ fn make_edit_panel(app: &mut AppState) -> anyhow::Result<EditModeWrapPanel> {
|
|||||||
mouse: SpriteTabHandler::default(),
|
mouse: SpriteTabHandler::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let anim_mult = app.wgui_globals.defaults().animation_mult;
|
||||||
|
|
||||||
let on_custom_attrib: OnCustomAttribFunc = Box::new(move |layout, attribs, _app| {
|
let on_custom_attrib: OnCustomAttribFunc = Box::new(move |layout, attribs, _app| {
|
||||||
for (name, kind, test_btn) in &BUTTON_EVENTS {
|
for (name, kind, test_btn) in &BUTTON_EVENTS {
|
||||||
let Some(action) = attribs.get_value(name) else {
|
let Some(action) = attribs.get_value(name) else {
|
||||||
@@ -300,7 +302,7 @@ fn make_edit_panel(app: &mut AppState) -> anyhow::Result<EditModeWrapPanel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sel = OverlaySelector::Id(*state.id.borrow());
|
let sel = OverlaySelector::Id(*state.id.borrow());
|
||||||
let task = state.lock.toggle(common, app);
|
let task = state.lock.toggle(common, app, anim_mult);
|
||||||
app.tasks
|
app.tasks
|
||||||
.enqueue(TaskType::Overlay(OverlayTask::Modify(sel, task)));
|
.enqueue(TaskType::Overlay(OverlayTask::Modify(sel, task)));
|
||||||
Ok(EventResult::Consumed)
|
Ok(EventResult::Consumed)
|
||||||
|
|||||||
@@ -39,11 +39,13 @@ pub(super) fn create_keyboard_panel(
|
|||||||
let globals = app.wgui_globals.clone();
|
let globals = app.wgui_globals.clone();
|
||||||
let accent_color = globals.get().defaults.accent_color;
|
let accent_color = globals.get().defaults.accent_color;
|
||||||
|
|
||||||
|
let anim_mult = globals.defaults().animation_mult;
|
||||||
|
|
||||||
let (background, _) = panel.layout.add_child(
|
let (background, _) = panel.layout.add_child(
|
||||||
panel.layout.content_root_widget,
|
panel.layout.content_root_widget,
|
||||||
WidgetRectangle::create(WidgetRectangleParams {
|
WidgetRectangle::create(WidgetRectangleParams {
|
||||||
color: wgui::drawing::Color::new(0., 0., 0., 0.75),
|
color: globals.defaults().bg_color,
|
||||||
round: WLength::Units(16.0),
|
round: WLength::Units((16.0 * globals.defaults().rounding_mult).max(0.)),
|
||||||
border: 2.0,
|
border: 2.0,
|
||||||
border_color: accent_color,
|
border_color: accent_color,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -176,7 +178,7 @@ 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);
|
on_enter_anim(k.clone(), common, data, accent_color, anim_mult);
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -188,7 +190,7 @@ 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);
|
on_leave_anim(k.clone(), common, data, accent_color, anim_mult);
|
||||||
Ok(EventResult::Pass)
|
Ok(EventResult::Pass)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -291,10 +293,11 @@ fn on_enter_anim(
|
|||||||
common: &mut event::CallbackDataCommon,
|
common: &mut event::CallbackDataCommon,
|
||||||
data: &event::CallbackData,
|
data: &event::CallbackData,
|
||||||
accent_color: drawing::Color,
|
accent_color: drawing::Color,
|
||||||
|
anim_mult: f32,
|
||||||
) {
|
) {
|
||||||
common.alterables.animate(Animation::new(
|
common.alterables.animate(Animation::new(
|
||||||
data.widget_id,
|
data.widget_id,
|
||||||
10,
|
(10. * anim_mult) as _,
|
||||||
AnimationEasing::OutBack,
|
AnimationEasing::OutBack,
|
||||||
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();
|
||||||
@@ -310,10 +313,11 @@ fn on_leave_anim(
|
|||||||
common: &mut event::CallbackDataCommon,
|
common: &mut event::CallbackDataCommon,
|
||||||
data: &event::CallbackData,
|
data: &event::CallbackData,
|
||||||
accent_color: drawing::Color,
|
accent_color: drawing::Color,
|
||||||
|
anim_mult: f32,
|
||||||
) {
|
) {
|
||||||
common.alterables.animate(Animation::new(
|
common.alterables.animate(Animation::new(
|
||||||
data.widget_id,
|
data.widget_id,
|
||||||
15,
|
(15. * anim_mult) as _,
|
||||||
AnimationEasing::OutQuad,
|
AnimationEasing::OutQuad,
|
||||||
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();
|
||||||
|
|||||||
@@ -91,9 +91,17 @@
|
|||||||
#theme_path: "theme"
|
#theme_path: "theme"
|
||||||
|
|
||||||
## These can be used to control the color theme of WlxOverlay-S.
|
## These can be used to control the color theme of WlxOverlay-S.
|
||||||
|
#color_text: "#ffffff"
|
||||||
#color_accent: "#008cff"
|
#color_accent: "#008cff"
|
||||||
#color_danger: "#ff3300"
|
#color_danger: "#ff3300"
|
||||||
#color_faded: "#668299"
|
#color_faded: "#668299"
|
||||||
|
#color_background: "#010206",
|
||||||
|
|
||||||
|
## Multiplier for animation speed. 2.0 → double speed, 0.5 → half speed
|
||||||
|
#animation_speed: 1.0
|
||||||
|
|
||||||
|
## Adjust this between 0..1 for a more rectangular feel.
|
||||||
|
#round_multiplier: 1.0
|
||||||
|
|
||||||
## Path to custom skybox texture, relative to `~/.config/wlxoverlay`
|
## Path to custom skybox texture, relative to `~/.config/wlxoverlay`
|
||||||
#skybox_texture: ""
|
#skybox_texture: ""
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use idmap::IdMap;
|
|||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wgui::{
|
use wgui::{
|
||||||
font_config::WguiFontConfig, gfx::WGfx, globals::WguiGlobals, parser::parse_color_hex,
|
drawing, font_config::WguiFontConfig, gfx::WGfx, globals::WguiGlobals, parser::parse_color_hex,
|
||||||
renderer_vk::context::SharedContext as WSharedContext,
|
renderer_vk::context::SharedContext as WSharedContext,
|
||||||
};
|
};
|
||||||
use wlx_common::{
|
use wlx_common::{
|
||||||
@@ -96,26 +96,21 @@ impl AppState {
|
|||||||
let theme = session.config.theme_path.clone();
|
let theme = session.config.theme_path.clone();
|
||||||
|
|
||||||
let mut defaults = wgui::globals::Defaults::default();
|
let mut defaults = wgui::globals::Defaults::default();
|
||||||
defaults.accent_color = session
|
|
||||||
.config
|
|
||||||
.color_accent
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|c| parse_color_hex(&c))
|
|
||||||
.unwrap_or(defaults.accent_color);
|
|
||||||
|
|
||||||
defaults.danger_color = session
|
fn apply_color(default: &mut drawing::Color, value: &Option<String>) {
|
||||||
.config
|
if let Some(parsed) = value.as_ref().and_then(|c| parse_color_hex(c)) {
|
||||||
.color_danger
|
*default = parsed;
|
||||||
.as_ref()
|
}
|
||||||
.and_then(|c| parse_color_hex(&c))
|
}
|
||||||
.unwrap_or(defaults.danger_color);
|
|
||||||
|
|
||||||
defaults.faded_color = session
|
apply_color(&mut defaults.text_color, &session.config.color_text);
|
||||||
.config
|
apply_color(&mut defaults.accent_color, &session.config.color_accent);
|
||||||
.color_faded
|
apply_color(&mut defaults.danger_color, &session.config.color_danger);
|
||||||
.as_ref()
|
apply_color(&mut defaults.faded_color, &session.config.color_faded);
|
||||||
.and_then(|c| parse_color_hex(&c))
|
apply_color(&mut defaults.bg_color, &session.config.color_background);
|
||||||
.unwrap_or(defaults.faded_color);
|
|
||||||
|
defaults.animation_mult = 1. / session.config.animation_speed;
|
||||||
|
defaults.rounding_mult = session.config.round_multiplier;
|
||||||
|
|
||||||
let dbus = DbusConnector::default();
|
let dbus = DbusConnector::default();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user