mirror of https://github.com/wayvr-org/wayvr.git
wgui: use DeviceBitmask instead of usize
This commit is contained in:
parent
9734955ebb
commit
97e6263bd1
|
|
@ -1,12 +1,7 @@
|
|||
#![allow(dead_code)]
|
||||
use std::path::PathBuf;
|
||||
|
||||
// TODO: Remove later
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wlx_common::{async_executor::AsyncExecutor, config_io};
|
||||
|
||||
use crate::util::networking::{self, WAYVR_SKYMAPS_ROOT, http_client};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use wlx_common::{async_executor::AsyncExecutor, config_io};
|
||||
pub type SkymapUuid = uuid::Uuid;
|
||||
|
||||
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ pub fn create_button(par: CreateButtonParams) -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn create_label(layout: &mut Layout, id_parent: WidgetID, content: Translation) -> anyhow::Result<()> {
|
||||
let label = WidgetLabel::create(
|
||||
&mut layout.state,
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
&wgui::event::Event::MouseWheel(MouseWheelEvent {
|
||||
delta: Vec2::new(x, y),
|
||||
pos: mouse / scale,
|
||||
device: 0,
|
||||
device: wgui::event::DeviceBitmask(0),
|
||||
}),
|
||||
&mut (),
|
||||
&mut (),
|
||||
|
|
@ -157,7 +157,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
&wgui::event::Event::MouseWheel(MouseWheelEvent {
|
||||
delta: Vec2::new(pos.x as f32 / 5.0, pos.y as f32 / 5.0),
|
||||
pos: mouse / scale,
|
||||
device: 0,
|
||||
device: wgui::event::DeviceBitmask(0),
|
||||
}),
|
||||
&mut (),
|
||||
&mut (),
|
||||
|
|
@ -177,7 +177,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
&wgui::event::Event::MouseDown(MouseButtonEvent {
|
||||
pos: mouse / scale,
|
||||
index: MouseButtonIndex::Left,
|
||||
device: 0,
|
||||
device: wgui::event::DeviceBitmask(0),
|
||||
}),
|
||||
&mut (),
|
||||
&mut (),
|
||||
|
|
@ -190,7 +190,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
&wgui::event::Event::MouseUp(MouseButtonEvent {
|
||||
pos: mouse / scale,
|
||||
index: MouseButtonIndex::Left,
|
||||
device: 0,
|
||||
device: wgui::event::DeviceBitmask(0),
|
||||
}),
|
||||
&mut (),
|
||||
&mut (),
|
||||
|
|
@ -209,7 +209,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.push_event(
|
||||
&wgui::event::Event::MouseMotion(MouseMotionEvent {
|
||||
pos: mouse / scale,
|
||||
device: 0,
|
||||
device: wgui::event::DeviceBitmask(0),
|
||||
}),
|
||||
&mut (),
|
||||
&mut (),
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use wgui::{
|
|||
slider::ComponentSlider,
|
||||
},
|
||||
event::{
|
||||
Event as WguiEvent, EventCallback, EventListenerID, EventListenerKind,
|
||||
DeviceBitmask, Event as WguiEvent, EventCallback, EventListenerID, EventListenerKind,
|
||||
InternalStateChangeEvent, MouseButtonEvent, MouseButtonIndex, MouseLeaveEvent,
|
||||
MouseMotionEvent, MouseWheelEvent,
|
||||
},
|
||||
|
|
@ -368,7 +368,7 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
|||
let e = WguiEvent::MouseWheel(MouseWheelEvent {
|
||||
delta: vec2(delta.x, delta.y) / 8.0,
|
||||
pos: hit.uv * self.layout.content_size,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
self.push_event(app, &e);
|
||||
}
|
||||
|
|
@ -376,7 +376,7 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
|||
fn on_hover(&mut self, app: &mut AppState, hit: &PointerHit) -> HoverResult {
|
||||
let e = &WguiEvent::MouseMotion(MouseMotionEvent {
|
||||
pos: hit.uv * self.layout.content_size,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
|
||||
self.has_focus[hit.pointer] = true;
|
||||
|
|
@ -397,7 +397,9 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
|||
}
|
||||
|
||||
fn on_left(&mut self, app: &mut AppState, pointer: usize) {
|
||||
let e = WguiEvent::MouseLeave(MouseLeaveEvent { device: pointer });
|
||||
let e = WguiEvent::MouseLeave(MouseLeaveEvent {
|
||||
device: DeviceBitmask::from_usize(pointer),
|
||||
});
|
||||
self.has_focus[pointer] = false;
|
||||
self.push_event(app, &e);
|
||||
}
|
||||
|
|
@ -414,13 +416,13 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
|||
WguiEvent::MouseDown(MouseButtonEvent {
|
||||
pos: hit.uv * self.layout.content_size,
|
||||
index,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
})
|
||||
} else {
|
||||
WguiEvent::MouseUp(MouseButtonEvent {
|
||||
pos: hit.uv * self.layout.content_size,
|
||||
index,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
})
|
||||
};
|
||||
self.push_event(app, &e);
|
||||
|
|
@ -429,11 +431,11 @@ impl<S: 'static> OverlayBackend for GuiPanel<S> {
|
|||
if !pressed && !self.has_focus[hit.pointer] {
|
||||
let e = WguiEvent::MouseMotion(MouseMotionEvent {
|
||||
pos: vec2(-1., -1.),
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
self.push_event(app, &e);
|
||||
let e = WguiEvent::MouseLeave(MouseLeaveEvent {
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
self.push_event(app, &e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ use wayvr_ipc::{
|
|||
};
|
||||
use wgui::{
|
||||
event::{
|
||||
Event as WguiEvent, MouseButtonEvent, MouseButtonIndex, MouseLeaveEvent, MouseMotionEvent,
|
||||
MouseWheelEvent,
|
||||
DeviceBitmask, Event as WguiEvent, MouseButtonEvent, MouseButtonIndex, MouseLeaveEvent,
|
||||
MouseMotionEvent, MouseWheelEvent,
|
||||
},
|
||||
gfx::cmd::WGfxClearMode,
|
||||
renderer_vk::context::Context as WguiContext,
|
||||
|
|
@ -205,7 +205,7 @@ impl OverlayBackend for DashFrontend {
|
|||
let e = WguiEvent::MouseWheel(MouseWheelEvent {
|
||||
delta: vec2(delta.x, delta.y) / 8.0,
|
||||
pos: hit.uv * self.inner.layout.content_size,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
self.push_event(&e);
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ impl OverlayBackend for DashFrontend {
|
|||
fn on_hover(&mut self, _app: &mut AppState, hit: &PointerHit) -> HoverResult {
|
||||
let e = &WguiEvent::MouseMotion(MouseMotionEvent {
|
||||
pos: hit.uv * self.inner.layout.content_size,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
|
||||
self.has_focus[hit.pointer] = true;
|
||||
|
|
@ -235,7 +235,9 @@ impl OverlayBackend for DashFrontend {
|
|||
}
|
||||
|
||||
fn on_left(&mut self, _app: &mut AppState, pointer: usize) {
|
||||
let e = WguiEvent::MouseLeave(MouseLeaveEvent { device: pointer });
|
||||
let e = WguiEvent::MouseLeave(MouseLeaveEvent {
|
||||
device: DeviceBitmask::from_usize(pointer),
|
||||
});
|
||||
self.has_focus[pointer] = false;
|
||||
self.push_event(&e);
|
||||
}
|
||||
|
|
@ -252,13 +254,13 @@ impl OverlayBackend for DashFrontend {
|
|||
WguiEvent::MouseDown(MouseButtonEvent {
|
||||
pos: hit.uv * self.inner.layout.content_size,
|
||||
index,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
})
|
||||
} else {
|
||||
WguiEvent::MouseUp(MouseButtonEvent {
|
||||
pos: hit.uv * self.inner.layout.content_size,
|
||||
index,
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
})
|
||||
};
|
||||
self.push_event(&e);
|
||||
|
|
@ -267,11 +269,11 @@ impl OverlayBackend for DashFrontend {
|
|||
if !pressed && !self.has_focus[hit.pointer] {
|
||||
let e = WguiEvent::MouseMotion(MouseMotionEvent {
|
||||
pos: vec2(-1., -1.),
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
self.push_event(&e);
|
||||
let e = WguiEvent::MouseLeave(MouseLeaveEvent {
|
||||
device: hit.pointer,
|
||||
device: DeviceBitmask::from_usize(hit.pointer),
|
||||
});
|
||||
self.push_event(&e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ use crate::{
|
|||
},
|
||||
drawing::{self},
|
||||
event::{
|
||||
self, CallbackDataCommon, CallbackMetadata, EventAlterables, EventListenerCollection, EventListenerKind,
|
||||
StyleSetRequest,
|
||||
self, CallbackDataCommon, CallbackMetadata, DeviceBitmask, EventAlterables, EventListenerCollection,
|
||||
EventListenerKind, StyleSetRequest,
|
||||
},
|
||||
i18n::Translation,
|
||||
layout::{WidgetID, WidgetPair},
|
||||
|
|
@ -77,7 +77,7 @@ pub struct Params {
|
|||
}
|
||||
|
||||
struct State {
|
||||
dragged_by: Option<usize>,
|
||||
dragged_by: Option<DeviceBitmask>,
|
||||
hovered: bool,
|
||||
values: ValuesMinMax,
|
||||
on_value_changed: Option<SliderValueChangedCallback>,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
layout::WidgetPair,
|
||||
widget::{ConstructEssentials, div::WidgetDiv},
|
||||
};
|
||||
use std::{cell::RefCell, fmt::Pointer, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use taffy::{
|
||||
AlignItems,
|
||||
prelude::{length, percent},
|
||||
|
|
|
|||
|
|
@ -19,6 +19,17 @@ use crate::{
|
|||
widget::{EventResult, WidgetData, WidgetObj},
|
||||
};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||
pub struct DeviceBitmask(pub u8);
|
||||
|
||||
impl DeviceBitmask {
|
||||
pub fn from_usize(mask: usize) -> Self {
|
||||
// more than 8 input devices?
|
||||
debug_assert!(mask & !0xff == 0);
|
||||
Self(mask as u8)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum MouseButtonIndex {
|
||||
Left,
|
||||
|
|
@ -30,28 +41,28 @@ pub enum MouseButtonIndex {
|
|||
pub struct MouseButtonEvent {
|
||||
pub index: MouseButtonIndex,
|
||||
pub pos: Vec2,
|
||||
pub device: usize,
|
||||
pub device: DeviceBitmask,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct MousePosition {
|
||||
pub pos: Vec2,
|
||||
pub device: usize,
|
||||
pub device: DeviceBitmask,
|
||||
}
|
||||
|
||||
pub struct MouseLeaveEvent {
|
||||
pub device: usize,
|
||||
pub device: DeviceBitmask,
|
||||
}
|
||||
|
||||
pub struct MouseMotionEvent {
|
||||
pub pos: Vec2,
|
||||
pub device: usize,
|
||||
pub device: DeviceBitmask,
|
||||
}
|
||||
|
||||
pub struct MouseWheelEvent {
|
||||
pub pos: Vec2, /* mouse position */
|
||||
pub delta: Vec2, /* wheel delta */
|
||||
pub device: usize,
|
||||
pub device: DeviceBitmask,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ use crate::{
|
|||
any::AnyTrait,
|
||||
drawing::{self, PrimitiveExtent},
|
||||
event::{
|
||||
self, CallbackData, CallbackDataCommon, CallbackMetadata, Event, EventAlterables, EventListenerCollection,
|
||||
self, CallbackData, CallbackDataCommon, CallbackMetadata, DeviceBitmask, Event, EventAlterables,
|
||||
EventListenerCollection,
|
||||
EventListenerKind::{self, InternalStateChange, MouseLeave},
|
||||
MouseWheelEvent,
|
||||
},
|
||||
|
|
@ -26,8 +27,8 @@ pub mod sprite;
|
|||
pub mod util;
|
||||
|
||||
pub struct WidgetData {
|
||||
hovered: usize,
|
||||
pressed: usize,
|
||||
hovered: DeviceBitmask,
|
||||
pressed: DeviceBitmask,
|
||||
pub scrolling_target: Vec2, // normalized, 0.0-1.0. Not used in case if overflow != scroll
|
||||
pub scrolling_cur: Vec2, // normalized, used for smooth scrolling animation
|
||||
pub scrolling_cur_prev: Vec2, // for motion interpolation while rendering between ticks
|
||||
|
|
@ -36,46 +37,46 @@ pub struct WidgetData {
|
|||
}
|
||||
|
||||
impl WidgetData {
|
||||
pub const fn set_device_pressed(&mut self, device: usize, pressed: bool) -> bool {
|
||||
let bit = 1 << device;
|
||||
pub const fn set_device_pressed(&mut self, device: DeviceBitmask, pressed: bool) -> bool {
|
||||
let bit = 1 << device.0;
|
||||
let state_changed;
|
||||
if pressed {
|
||||
state_changed = self.pressed == 0;
|
||||
self.pressed |= bit;
|
||||
state_changed = self.pressed.0 == 0;
|
||||
self.pressed.0 |= bit;
|
||||
} else {
|
||||
state_changed = self.pressed == bit;
|
||||
self.pressed &= !bit;
|
||||
state_changed = self.pressed.0 == bit;
|
||||
self.pressed.0 &= !bit;
|
||||
}
|
||||
state_changed
|
||||
}
|
||||
|
||||
pub const fn set_device_hovered(&mut self, device: usize, hovered: bool) -> bool {
|
||||
let bit = 1 << device;
|
||||
pub const fn set_device_hovered(&mut self, device: DeviceBitmask, hovered: bool) -> bool {
|
||||
let bit = 1 << device.0;
|
||||
let state_changed;
|
||||
if hovered {
|
||||
state_changed = self.hovered == 0;
|
||||
self.hovered |= bit;
|
||||
state_changed = self.hovered.0 == 0;
|
||||
self.hovered.0 |= bit;
|
||||
} else {
|
||||
state_changed = self.hovered == bit;
|
||||
self.hovered &= !bit;
|
||||
state_changed = self.hovered.0 == bit;
|
||||
self.hovered.0 &= !bit;
|
||||
}
|
||||
state_changed
|
||||
}
|
||||
|
||||
pub const fn get_pressed(&self, device: usize) -> bool {
|
||||
self.pressed & (1 << device) != 0
|
||||
pub const fn get_pressed(&self, device: DeviceBitmask) -> bool {
|
||||
self.pressed.0 & (1 << device.0) != 0
|
||||
}
|
||||
|
||||
pub const fn get_hovered(&self, device: usize) -> bool {
|
||||
self.hovered & (1 << device) != 0
|
||||
pub const fn get_hovered(&self, device: DeviceBitmask) -> bool {
|
||||
self.hovered.0 & (1 << device.0) != 0
|
||||
}
|
||||
|
||||
pub const fn is_pressed(&self) -> bool {
|
||||
self.pressed != 0
|
||||
self.pressed.0 != 0
|
||||
}
|
||||
|
||||
pub const fn is_hovered(&self) -> bool {
|
||||
self.hovered != 0
|
||||
self.hovered.0 != 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,8 +117,8 @@ impl WidgetState {
|
|||
fn new(flags: WidgetStateFlags, obj: Box<dyn WidgetObj>) -> Self {
|
||||
Self {
|
||||
data: WidgetData {
|
||||
hovered: 0,
|
||||
pressed: 0,
|
||||
hovered: DeviceBitmask(0),
|
||||
pressed: DeviceBitmask(0),
|
||||
scrolling_target: Vec2::default(),
|
||||
scrolling_cur: Vec2::default(),
|
||||
scrolling_cur_prev: Vec2::default(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue