dash and wgui sounds
This commit is contained in:
8
wlx-overlay-s/src/app_misc.rs
Normal file
8
wlx-overlay-s/src/app_misc.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use wgui::layout::LayoutUpdateResult;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
pub fn process_layout_result(app: &mut AppState, res: LayoutUpdateResult) {
|
||||
app.audio_sample_player
|
||||
.play_wgui_samples(&mut app.audio_system, res.sounds_to_play);
|
||||
}
|
||||
BIN
wlx-overlay-s/src/assets/sound/wgui_button_press.mp3
Normal file
BIN
wlx-overlay-s/src/assets/sound/wgui_button_press.mp3
Normal file
Binary file not shown.
BIN
wlx-overlay-s/src/assets/sound/wgui_button_release.mp3
Normal file
BIN
wlx-overlay-s/src/assets/sound/wgui_button_release.mp3
Normal file
Binary file not shown.
BIN
wlx-overlay-s/src/assets/sound/wgui_mouse_enter.mp3
Normal file
BIN
wlx-overlay-s/src/assets/sound/wgui_mouse_enter.mp3
Normal file
Binary file not shown.
@@ -13,7 +13,7 @@ use wgui::{
|
||||
MouseMotionEvent, MouseUpEvent, MouseWheelEvent,
|
||||
},
|
||||
gfx::cmd::WGfxClearMode,
|
||||
layout::{Layout, LayoutParams, WidgetID},
|
||||
layout::{Layout, LayoutParams, LayoutUpdateParams, WidgetID},
|
||||
parser::{CustomAttribsInfoOwned, Fetchable, ParserState},
|
||||
renderer_vk::context::Context as WguiContext,
|
||||
widget::{EventResult, label::WidgetLabel},
|
||||
@@ -22,6 +22,7 @@ use wlx_common::overlays::{BackendAttrib, BackendAttribValue};
|
||||
use wlx_common::timestep::Timestep;
|
||||
|
||||
use crate::{
|
||||
app_misc,
|
||||
backend::input::{Haptics, HoverResult, PointerHit, PointerMode},
|
||||
state::AppState,
|
||||
subsystem::hid::WheelDelta,
|
||||
@@ -211,8 +212,15 @@ impl<S: 'static> GuiPanel<S> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_layout(&mut self) -> anyhow::Result<()> {
|
||||
self.layout.update(self.max_size, 0.0)
|
||||
pub fn update_layout(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||
app_misc::process_layout_result(
|
||||
app,
|
||||
self.layout.update(&mut LayoutUpdateParams {
|
||||
size: self.max_size / self.gui_scale,
|
||||
timestep_alpha: self.timestep.alpha,
|
||||
})?,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn push_event(&mut self, app: &mut AppState, event: &WguiEvent) -> EventResult {
|
||||
@@ -236,9 +244,9 @@ impl<S: 'static> GuiPanel<S> {
|
||||
}
|
||||
|
||||
impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
||||
fn init(&mut self, _app: &mut AppState) -> anyhow::Result<()> {
|
||||
fn init(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||
if self.layout.content_size.x * self.layout.content_size.y != 0.0 {
|
||||
self.update_layout()?;
|
||||
self.update_layout(app)?;
|
||||
self.interaction_transform = Some(ui_transform([
|
||||
self.layout.content_size.x as _,
|
||||
self.layout.content_size.y as _,
|
||||
@@ -297,9 +305,7 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
||||
fn render(&mut self, app: &mut AppState, rdr: &mut RenderResources) -> anyhow::Result<()> {
|
||||
self.context
|
||||
.update_viewport(&mut app.wgui_shared, rdr.extent, self.gui_scale)?;
|
||||
self.layout
|
||||
.update(self.max_size / self.gui_scale, self.timestep.alpha)?;
|
||||
|
||||
self.update_layout(app)?;
|
||||
let globals = self.layout.state.globals.clone(); // sorry
|
||||
let mut globals = globals.get();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
clippy::cargo_common_metadata,
|
||||
clippy::option_if_let_else
|
||||
)]
|
||||
mod app_misc;
|
||||
mod backend;
|
||||
mod config;
|
||||
mod config_io;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub static ANCHOR_NAME: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("anchor"
|
||||
|
||||
pub fn create_anchor(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
let mut panel = GuiPanel::new_from_template(app, "gui/anchor.xml", (), Default::default())?;
|
||||
panel.update_layout()?;
|
||||
panel.update_layout(app)?;
|
||||
|
||||
Ok(OverlayWindowConfig {
|
||||
name: ANCHOR_NAME.clone(),
|
||||
@@ -41,7 +41,7 @@ pub static GRAB_HELP_NAME: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("grab
|
||||
|
||||
pub fn create_grab_help(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
let mut panel = GuiPanel::new_from_template(app, "gui/grab-help.xml", (), Default::default())?;
|
||||
panel.update_layout()?;
|
||||
panel.update_layout(app)?;
|
||||
|
||||
let id_watch = panel.parser_state.data.get_widget_id("grabbing_watch")?;
|
||||
let id_static = panel.parser_state.data.get_widget_id("grabbing_static")?;
|
||||
|
||||
@@ -42,7 +42,7 @@ pub fn create_custom(app: &mut AppState, name: Arc<str>) -> Option<OverlayWindow
|
||||
.ok()?;
|
||||
|
||||
panel
|
||||
.update_layout()
|
||||
.update_layout(app)
|
||||
.inspect_err(|e| log::warn!("Error layouting '{name}': {e:?}"))
|
||||
.ok()?;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use dash_frontend::{
|
||||
frontend,
|
||||
frontend::{self, FrontendUpdateParams},
|
||||
settings::{self, SettingsIO},
|
||||
};
|
||||
use glam::{Affine2, Affine3A, Vec2, vec2, vec3};
|
||||
@@ -27,6 +27,7 @@ use wlx_common::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
app_misc,
|
||||
backend::{
|
||||
input::{Haptics, HoverResult, PointerHit, PointerMode},
|
||||
task::{OverlayTask, PlayspaceTask, TaskType},
|
||||
@@ -103,10 +104,13 @@ impl DashFrontend {
|
||||
let settings = SimpleSettingsIO::new();
|
||||
let interface = DashInterfaceLive::new();
|
||||
|
||||
let frontend = frontend::Frontend::new(frontend::InitParams {
|
||||
let mut frontend = frontend::Frontend::new(frontend::InitParams {
|
||||
settings: Box::new(settings),
|
||||
interface: Box::new(interface),
|
||||
})?;
|
||||
|
||||
frontend.play_startup_sound(&mut app.audio_system, &mut app.audio_sample_player)?;
|
||||
|
||||
let context = WguiContext::new(&mut app.wgui_shared, 1.0)?;
|
||||
Ok(Self {
|
||||
inner: frontend,
|
||||
@@ -119,12 +123,14 @@ impl DashFrontend {
|
||||
}
|
||||
|
||||
fn update(&mut self, app: &mut AppState, timestep_alpha: f32) -> anyhow::Result<()> {
|
||||
self.inner.update(
|
||||
app,
|
||||
DASH_RES_VEC2.x / GUI_SCALE,
|
||||
DASH_RES_VEC2.y / GUI_SCALE,
|
||||
let res = self.inner.update(FrontendUpdateParams {
|
||||
data: app,
|
||||
width: DASH_RES_VEC2.x / GUI_SCALE,
|
||||
height: DASH_RES_VEC2.y / GUI_SCALE,
|
||||
timestep_alpha,
|
||||
)
|
||||
})?;
|
||||
app_misc::process_layout_result(app, res);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn push_event(&mut self, event: &WguiEvent) -> EventResult {
|
||||
|
||||
@@ -167,7 +167,7 @@ impl OverlayBackend for EditModeBackendWrapper {
|
||||
|
||||
let gui_scale = (new_size.x / 750.0).min(new_size.y / 300.0);
|
||||
self.panel.gui_scale = (gui_scale * 4.0).round() / 4.0;
|
||||
self.panel.update_layout()?;
|
||||
self.panel.update_layout(app)?;
|
||||
}
|
||||
|
||||
self.can_render_inner = true;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
|
||||
use crate::{gui::panel::GuiPanel, state::AppState, subsystem::hid::XkbKeymap};
|
||||
use crate::{app_misc, gui::panel::GuiPanel, state::AppState, subsystem::hid::XkbKeymap};
|
||||
use glam::{FloatExt, Mat4, Vec2, vec2, vec3};
|
||||
use wgui::{
|
||||
animation::{Animation, AnimationEasing},
|
||||
assets::AssetPath,
|
||||
drawing::{self, Color},
|
||||
event::{self, CallbackMetadata, EventListenerKind},
|
||||
layout::LayoutParams,
|
||||
layout::{LayoutParams, LayoutUpdateParams},
|
||||
parser::Fetchable,
|
||||
renderer_vk::util,
|
||||
taffy::{self, prelude::length},
|
||||
@@ -264,7 +264,13 @@ pub(super) fn create_keyboard_panel(
|
||||
}
|
||||
}
|
||||
|
||||
panel.layout.update(vec2(2048., 2048.), 0.0)?;
|
||||
app_misc::process_layout_result(
|
||||
app,
|
||||
panel.layout.update(&mut LayoutUpdateParams {
|
||||
size: vec2(2048., 2048.),
|
||||
timestep_alpha: 0.0,
|
||||
})?,
|
||||
);
|
||||
panel.parser_state = gui_state_key;
|
||||
|
||||
Ok(panel)
|
||||
|
||||
@@ -179,7 +179,10 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option<OverlayWindowConfig> {
|
||||
.inspect_err(|e| log::error!("Could not create toast: {e:?}"))
|
||||
.ok()?;
|
||||
|
||||
panel.update_layout().context("layout update failed").ok()?;
|
||||
panel
|
||||
.update_layout(app)
|
||||
.context("layout update failed")
|
||||
.ok()?;
|
||||
|
||||
Some(OverlayWindowConfig {
|
||||
name: TOAST_NAME.clone(),
|
||||
|
||||
@@ -551,7 +551,7 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result<OverlayWindowConfig> {
|
||||
align_to_hmd: false,
|
||||
};
|
||||
|
||||
panel.update_layout()?;
|
||||
panel.update_layout(app)?;
|
||||
|
||||
Ok(OverlayWindowConfig {
|
||||
name: WATCH_NAME.into(),
|
||||
|
||||
@@ -109,6 +109,9 @@ impl AppState {
|
||||
audio::AudioSample::from_mp3(include_bytes!("res/toast.mp3"))?,
|
||||
);
|
||||
|
||||
let mut assets = Box::new(gui::asset::GuiAsset {});
|
||||
audio_sample_player.register_wgui_samples(assets.as_mut())?;
|
||||
|
||||
let mut defaults = wgui::globals::Defaults::default();
|
||||
|
||||
{
|
||||
@@ -147,7 +150,7 @@ impl AppState {
|
||||
anchor: Affine3A::IDENTITY,
|
||||
anchor_grabbed: false,
|
||||
wgui_globals: WguiGlobals::new(
|
||||
Box::new(gui::asset::GuiAsset {}),
|
||||
assets,
|
||||
defaults,
|
||||
&WguiFontConfig::default(),
|
||||
get_config_file_path(&theme),
|
||||
|
||||
Reference in New Issue
Block a user