dash-frontend: toast messages, 📦📎

This commit is contained in:
Aleksander
2025-12-08 22:42:05 +01:00
parent e7746f5981
commit b0985e33af
28 changed files with 316 additions and 80 deletions

View File

@@ -52,7 +52,7 @@ rodio = { version = "0.21.1", default-features = false, features = [
"hound",
] }
rosc = { version = "0.11.4", optional = true }
serde = { version = "1.0.225", features = ["derive", "rc"] }
serde = { version = "1.0.228", features = ["derive", "rc"] }
serde_json = "1.0.145"
serde_yaml = "0.9.34"
slotmap = { workspace = true }

View File

@@ -1,4 +1,3 @@
pub mod asset;
pub mod panel;
pub mod timer;
mod timestep;

View File

@@ -1,7 +1,7 @@
use std::{cell::RefCell, rc::Rc};
use button::setup_custom_button;
use glam::{vec2, Affine2, Vec2};
use glam::{Affine2, Vec2, vec2};
use label::setup_custom_label;
use wgui::{
assets::AssetPath,
@@ -15,19 +15,20 @@ use wgui::{
layout::{Layout, LayoutParams, WidgetID},
parser::{CustomAttribsInfoOwned, ParserState},
renderer_vk::context::Context as WguiContext,
widget::{label::WidgetLabel, rectangle::WidgetRectangle, EventResult},
widget::{EventResult, label::WidgetLabel, rectangle::WidgetRectangle},
};
use wlx_common::timestep::Timestep;
use crate::{
backend::input::{Haptics, HoverResult, PointerHit, PointerMode},
state::AppState,
subsystem::hid::WheelDelta,
windowing::backend::{
ui_transform, FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender,
FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender, ui_transform,
},
};
use super::{timer::GuiTimer, timestep::Timestep};
use super::timer::GuiTimer;
pub mod button;
mod helper;

View File

@@ -1,70 +0,0 @@
use std::{sync::LazyLock, time::Instant};
static TIME_START: LazyLock<Instant> = LazyLock::new(Instant::now);
pub fn get_micros() -> u64 {
TIME_START.elapsed().as_micros() as u64
}
#[derive(Default)]
pub struct Timestep {
current_time_us: u64,
accumulator: f32,
time_micros: u64,
ticks: u32,
speed: f32,
pub alpha: f32,
delta: f32,
loopnum: u8,
}
impl Timestep {
pub fn new() -> Self {
let mut timestep = Self {
speed: 1.0,
..Default::default()
};
timestep.reset();
timestep
}
fn calculate_alpha(&mut self) {
self.alpha = (self.accumulator / self.delta).clamp(0.0, 1.0);
}
pub fn set_tps(&mut self, tps: f32) {
self.delta = 1000.0 / tps;
}
pub fn reset(&mut self) {
self.current_time_us = get_micros();
self.accumulator = 0.0;
}
pub fn on_tick(&mut self) -> bool {
let newtime = get_micros();
let frametime = newtime - self.current_time_us;
self.time_micros += frametime;
self.current_time_us = newtime;
self.accumulator += frametime as f32 * self.speed / 1000.0;
self.calculate_alpha();
if self.accumulator >= self.delta {
self.accumulator -= self.delta;
self.loopnum += 1;
self.ticks += 1;
if self.loopnum > 5 {
// cannot keep up!
self.loopnum = 0;
self.accumulator = 0.0;
return false;
}
true
} else {
self.loopnum = 0;
false
}
}
}

View File

@@ -14,7 +14,7 @@ use wgui::{
parser::Fetchable,
renderer_vk::text::custom_glyph::CustomGlyphData,
taffy,
widget::{sprite::WidgetSprite, EventResult},
widget::{EventResult, sprite::WidgetSprite},
};
use wlx_common::windowing::{OverlayWindowState, Positioning};
@@ -24,16 +24,16 @@ use crate::{
task::{ManagerTask, TaskType},
},
gui::{
panel::{button::BUTTON_EVENTS, GuiPanel, NewGuiPanelParams, OnCustomAttribFunc},
panel::{GuiPanel, NewGuiPanelParams, OnCustomAttribFunc, button::BUTTON_EVENTS},
timer::GuiTimer,
},
overlays::edit::LongPressButtonState,
state::AppState,
windowing::{
OverlaySelector, Z_ORDER_WATCH,
backend::{OverlayEventData, OverlayMeta},
manager::MAX_OVERLAY_SETS,
window::{OverlayWindowConfig, OverlayWindowData},
OverlaySelector, Z_ORDER_WATCH,
},
};
@@ -205,7 +205,7 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
if idx >= num_children {
let mut params: HashMap<Rc<str>, Rc<str>> = HashMap::new();
params.insert("idx".into(), idx.to_string().into());
params.insert("src".into(), "".to_string().into());
params.insert("src".into(), String::new().into());
parser_state.instantiate_template(
doc_params, "Device", layout, widget, params,
)?;
@@ -309,7 +309,7 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
} else {
com.alterables
.set_style(*div, StyleSetRequest::Display(taffy::Display::None));
};
}
}
}
}