Skip to content

Commit

Permalink
Fix for issue #174 (#176)
Browse files Browse the repository at this point in the history
* Fix for issue #174 (removed instant)

fixes issue #174 by removing the use of ``Instant`` inside the drag/drop state. since it's not allowed on wasm.

* ran cargo fmt

ran cargo fmt on last commit.

* finishing touches

fixed ``widnow_fade`` which also made use of ``Instant``
  • Loading branch information
Vickerinox authored Sep 4, 2023
1 parent 37e9b5e commit 1de3979
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
19 changes: 7 additions & 12 deletions src/widgets/dock_area/drag_and_drop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
ops::BitOrAssign,
time::{Duration, Instant},
};
use std::ops::BitOrAssign;

use crate::{
AllowedSplits, NodeIndex, Split, Style, SurfaceIndex, TabDestination, TabIndex, TabInsert,
Expand Down Expand Up @@ -150,8 +147,8 @@ pub(super) struct DragDropState {
pub hover: HoverData,
pub drag: DragData,
pub pointer: Pos2,
/// Is some when the pointer is over rect, instant holds when the lock was last active.
pub locked: Option<Instant>,
/// Is some when the pointer is over rect, f64 holds the time when the lock was last active.
pub locked: Option<f64>,
}

impl DragDropState {
Expand Down Expand Up @@ -364,7 +361,7 @@ impl DragDropState {
match self.locked.as_mut() {
Some(lock_time) => {
if target_state == LockState::HardLock {
*lock_time = Instant::now();
*lock_time = ctx.input(|i| i.time);
}
let window_hold = if !self.hover.dst.surface_address().is_main() {
ctx.request_repaint();
Expand All @@ -378,7 +375,7 @@ impl DragDropState {
}
None => {
if target_state != LockState::Unlocked {
self.locked = Some(Instant::now());
self.locked = Some(ctx.input(|i| i.time));
}
}
}
Expand All @@ -387,10 +384,8 @@ impl DragDropState {
pub(super) fn is_locked(&self, style: &Style, ctx: &Context) -> bool {
match self.locked.as_ref() {
Some(lock_time) => {
let elapsed = lock_time.elapsed().as_secs_f32();
ctx.request_repaint_after(Duration::from_secs_f32(
(style.overlay.feel.max_preference_time - elapsed).max(0.0),
));
let elapsed = (ctx.input(|i| i.time) - lock_time) as f32;
ctx.request_repaint();
elapsed < style.overlay.feel.max_preference_time
}
None => false,
Expand Down
9 changes: 4 additions & 5 deletions src/widgets/dock_area/show/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Instant;

use egui::{
CentralPanel, Color32, Context, CursorIcon, Frame, LayerId, Order, Pos2, Rect, Rounding, Sense,
Ui, Vec2,
Expand Down Expand Up @@ -146,8 +144,8 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
};
if let Some(destination) = tab_dst {
self.dock_state.move_tab(source, destination);
state.reset_drag();
}
state.reset_drag();
}
}
state.store(ui.ctx(), self.id);
Expand All @@ -163,13 +161,14 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
) -> Option<SurfaceIndex> {
if let Some(dnd_state) = &state.dnd {
if dnd_state.is_locked(self.style.as_ref().unwrap(), ctx) {
state.window_fade = Some((Instant::now(), dnd_state.hover.dst.surface_address()));
state.window_fade =
Some((ctx.input(|i| i.time), dnd_state.hover.dst.surface_address()));
}
}

state.window_fade.and_then(|(time, surface)| {
ctx.request_repaint();
(time.elapsed().as_secs_f32() < hold_time).then_some(surface)
(hold_time > (ctx.input(|i| i.time) - time) as f32).then_some(surface)
})
}

Expand Down
4 changes: 1 addition & 3 deletions src/widgets/dock_area/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Instant;

use egui::{Context, Id, Pos2};

use crate::{Style, SurfaceIndex};
Expand All @@ -10,7 +8,7 @@ use super::drag_and_drop::{DragData, DragDropState, HoverData};
pub(super) struct State {
pub drag_start: Option<Pos2>,
pub dnd: Option<DragDropState>,
pub window_fade: Option<(Instant, SurfaceIndex)>,
pub window_fade: Option<(f64, SurfaceIndex)>,
}

impl State {
Expand Down

0 comments on commit 1de3979

Please sign in to comment.