Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Nov 28, 2024
1 parent 298741b commit 474d8cb
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wgpu = { version = "22.0.0" }
parking_lot = { version = "0.12.1" }
swash = { version = "0.1.17" }
muda = { version = "0.15.3" }
winit = { git = "https://github.com/rust-windowing/winit", rev = "3a60cbaba5fd96d9244a1f316ae562d7032b2b98" }
winit = { git = "https://github.com/rust-windowing/winit", rev = "fc6cf89ac0674c64320024f800a41ffb365dab97" }

[dependencies]
slotmap = "1.0.7"
Expand Down
7 changes: 6 additions & 1 deletion reactive/src/derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use crate::{read::SignalTrack, RwSignal, SignalGet, SignalUpdate, SignalWith};
/// This is useful when you want a single state variable and don't want to use effects to synchronize multiple signals.
///
/// This is also useful when you want a derived signal that implements the [SignalGet], [SignalWith], etc. traits.
pub struct DerivedRwSignal<T, O, GF: Fn(&T) -> O + Clone + 'static, UF: Fn(&O) -> T + 'static> {
pub struct DerivedRwSignal<
T: 'static,
O,
GF: Fn(&T) -> O + Clone + 'static,
UF: Fn(&O) -> T + 'static,
> {
signal: RwSignal<T>,
getter: RwSignal<Box<GF>>,
setter: RwSignal<Box<UF>>,
Expand Down
13 changes: 3 additions & 10 deletions reactive/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
use std::{marker::PhantomData, sync::atomic::AtomicU64};
use std::sync::atomic::AtomicU64;

use crate::{effect::observer_clean_up, runtime::RUNTIME, signal::Signal};

/// Marker type explaining why something can't be sent across threads
#[allow(dead_code)]
struct NotThreadSafe(*const ());

/// An internal id which can reference a Signal/Effect/Scope.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Hash)]
pub struct Id(u64, PhantomData<NotThreadSafe>);
pub struct Id(u64);

impl Id {
/// Create a new Id that's next in order
pub(crate) fn next() -> Id {
static COUNTER: AtomicU64 = AtomicU64::new(0);
Id(
COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
PhantomData,
)
Id(COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
}

/// Try to get the Signal that links with this Id
Expand Down
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
action::{Timer, TimerToken},
app_handle::ApplicationHandle,
clipboard::Clipboard,
ext_event::ExtSendTrigger,
inspector::Capture,
profiler::Profile,
view::{IntoView, View},
Expand Down Expand Up @@ -54,7 +55,7 @@ pub enum AppEvent {

pub(crate) enum UserEvent {
AppUpdate(AppUpdateEvent),
Idle(Trigger),
Idle(ExtSendTrigger),
QuitApp,
GpuResourcesUpdate { window_id: WindowId },
}
Expand Down
4 changes: 2 additions & 2 deletions src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use winit::{
use crate::{
action::{Timer, TimerToken},
app::{AppUpdateEvent, UserEvent, APP_UPDATE_EVENTS},
ext_event::EXT_EVENT_HANDLER,
ext_event::{ExtSendTrigger, EXT_EVENT_HANDLER},
inspector::Capture,
profiler::{Profile, ProfileEvent},
view::View,
Expand Down Expand Up @@ -436,7 +436,7 @@ impl ApplicationHandle {
.map(|handle| handle.capture())
}

pub(crate) fn idle(&mut self, trigger: Trigger) {
pub(crate) fn idle(&mut self, trigger: ExtSendTrigger) {
trigger.notify();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ext_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{cell::Cell, collections::VecDeque, sync::Arc};

use floem_reactive::{
create_effect, create_rw_signal, untrack, with_scope, ReadSignal, RwSignal, Scope, SignalGet,
SignalUpdate, SignalWith, WriteSignal,
SignalUpdate, SignalWith, Trigger, WriteSignal,
};
use parking_lot::Mutex;

Expand Down
128 changes: 50 additions & 78 deletions src/screen_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,35 @@ use crate::window_tracking::{
/// to that view.
pub fn try_create_screen_layout(view: &ViewId) -> Option<ScreenLayout> {
with_window_id_and_window(view, |window_id, window| {
window
.current_monitor()
.map(|monitor| {
window
.inner_position()
.map(|inner_position| {
window
.outer_position()
.map(|outer_position| {
let monitor_bounds = monitor_bounds_for_monitor(window, &monitor);
let inner_size = window.surface_size();
let outer_size = window.outer_size();
window.current_monitor().and_then(|monitor| {
let inner_position = window.surface_position();
window
.outer_position()
.map(|outer_position| {
let monitor_bounds = monitor_bounds_for_monitor(window, &monitor);
let inner_size = window.surface_size();
let outer_size = window.outer_size();

let window_bounds = rect_from_physical_bounds_for_window(
window,
outer_position,
outer_size,
);
let window_bounds =
rect_from_physical_bounds_for_window(window, outer_position, outer_size);

let window_content_bounds = rect_from_physical_bounds_for_window(
window,
inner_position,
inner_size,
);
let window_content_bounds =
rect_from_physical_bounds_for_window(window, inner_position, inner_size);

let view_origin_in_window = find_window_origin(view);
let monitor_scale = window.scale_factor();
let view_origin_in_window = find_window_origin(view);
let monitor_scale = window.scale_factor();

ScreenLayout {
monitor_scale,
monitor_bounds,
window_content_bounds,
window_bounds,
view_origin_in_window: Some(view_origin_in_window),
window_id: *window_id,
}
})
.ok()
})
.ok()
})
.unwrap_or(None)
.unwrap_or(None)
ScreenLayout {
monitor_scale,
monitor_bounds,
window_content_bounds,
window_bounds,
view_origin_in_window: Some(view_origin_in_window),
window_id: *window_id,
}
})
.ok()
})
})
.unwrap_or(None)
}
Expand All @@ -69,49 +55,35 @@ pub fn screen_layout_for_window(
window_id: WindowId,
window: &Arc<dyn Window>,
) -> Option<ScreenLayout> {
window
.current_monitor()
.map(|monitor| {
window
.inner_position()
.map(|inner_position| {
window
.outer_position()
.map(|outer_position| {
let monitor_bounds = monitor_bounds_for_monitor(window, &monitor);
let inner_size = window.surface_size();
let outer_size = window.outer_size();
window.current_monitor().and_then(|monitor| {
let inner_position = window.surface_position();
window
.outer_position()
.map(|outer_position| {
let monitor_bounds = monitor_bounds_for_monitor(window, &monitor);
let inner_size = window.surface_size();
let outer_size = window.outer_size();

let window_bounds = rect_from_physical_bounds_for_window(
window,
outer_position,
outer_size,
);
let window_bounds =
rect_from_physical_bounds_for_window(window, outer_position, outer_size);

let window_content_bounds = rect_from_physical_bounds_for_window(
window,
inner_position,
inner_size,
);
let window_content_bounds =
rect_from_physical_bounds_for_window(window, inner_position, inner_size);

let view_origin_in_window = None;
let monitor_scale = window.scale_factor();
let view_origin_in_window = None;
let monitor_scale = window.scale_factor();

ScreenLayout {
monitor_scale,
monitor_bounds,
window_content_bounds,
window_bounds,
view_origin_in_window,
window_id,
}
})
.ok()
})
.ok()
})
.unwrap_or(None)
.unwrap_or(None)
ScreenLayout {
monitor_scale,
monitor_bounds,
window_content_bounds,
window_bounds,
view_origin_in_window,
window_id,
}
})
.ok()
})
}

/// A ScreenLayout is a snapshot of the layout of a view within a window
Expand Down
10 changes: 5 additions & 5 deletions src/views/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ mod test {
use crate::{
context::{EventCx, UpdateCx},
event::Event,
pointer::{PointerButton, PointerInputEvent, PointerMoveEvent},
pointer::{MouseButton, PointerButton, PointerInputEvent, PointerMoveEvent},
AppState,
};

Expand Down Expand Up @@ -580,7 +580,7 @@ mod test {
let pointer_down = Event::PointerDown(PointerInputEvent {
count: 1,
pos: Point::new(75.0, 10.0),
button: PointerButton::Primary,
button: PointerButton::Mouse(MouseButton::Primary),
modifiers: Default::default(),
});

Expand All @@ -605,7 +605,7 @@ mod test {
// Start drag
let pointer_down = Event::PointerDown(PointerInputEvent {
pos: Point::new(50.0, 10.0),
button: PointerButton::Primary,
button: PointerButton::Mouse(MouseButton::Primary),
count: 1,
modifiers: Default::default(),
});
Expand All @@ -626,7 +626,7 @@ mod test {
// End drag
let pointer_up = Event::PointerUp(PointerInputEvent {
pos: Point::new(75.0, 10.0),
button: PointerButton::Primary,
button: PointerButton::Mouse(MouseButton::Primary),
count: 1,
modifiers: Default::default(),
});
Expand Down Expand Up @@ -656,7 +656,7 @@ mod test {

let pointer_event = Event::PointerDown(PointerInputEvent {
pos: Point::new(60.0, 10.0),
button: PointerButton::Primary,
button: PointerButton::Mouse(MouseButton::Primary),
count: 1,
modifiers: Default::default(),
});
Expand Down
14 changes: 6 additions & 8 deletions src/window_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn bounds_to_logical_outer_position_and_inner_size(
// size as an *inner* size
let size_delta = delta_size(window.surface_size(), window.outer_size(), scale);
let inner_to_outer_delta: (f64, f64) = if let Some(delta) =
delta_position(window.inner_position(), window.outer_position(), scale)
delta_position(window.surface_position(), window.outer_position(), scale)
{
// This is the more accurate way, but may be unavailable on some platforms
delta
Expand Down Expand Up @@ -459,17 +459,15 @@ fn delta_size(inner: PhysicalSize<u32>, outer: PhysicalSize<u32>, window_scale:
type PositionResult = Result<winit::dpi::PhysicalPosition<i32>, winit::error::RequestError>;

fn delta_position(
inner: PositionResult,
inner: PhysicalPosition<i32>,
outer: PositionResult,
window_scale: f64,
) -> Option<(f64, f64)> {
if let Ok(inner) = inner {
if let Ok(outer) = outer {
let outer = winit_phys_position_to_point(outer, window_scale);
let inner = winit_phys_position_to_point(inner, window_scale);
if let Ok(outer) = outer {
let outer = winit_phys_position_to_point(outer, window_scale);
let inner = winit_phys_position_to_point(inner, window_scale);

return Some((inner.x - outer.x, inner.y - outer.y));
}
return Some((inner.x - outer.x, inner.y - outer.y));
}
None
}
Expand Down
20 changes: 4 additions & 16 deletions src/window_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,31 +192,19 @@ fn scale_point(window: &Arc<dyn Window>, mut rect: Point) -> Point {
pub fn window_inner_screen_position(id: &WindowId) -> Option<Point> {
with_window_map(|m| {
m.with_window(id, |window| {
window
.inner_position()
.map(|pos| Some(scale_point(window, Point::new(pos.x as f64, pos.y as f64))))
.unwrap_or(None)
let pos = window.surface_position();
scale_point(window, Point::new(pos.x as f64, pos.y as f64))
})
.unwrap_or(None)
})
.unwrap_or(None)
}

pub fn window_inner_screen_bounds(id: &WindowId) -> Option<Rect> {
with_window_map(|m| {
m.with_window(id, |window| {
window
.inner_position()
.map(|pos| {
Some(rect_from_physical_bounds_for_window(
window,
pos,
window.surface_size(),
))
})
.unwrap_or(None)
let pos = window.surface_position();
rect_from_physical_bounds_for_window(window, pos, window.surface_size())
})
.unwrap_or(None)
})
.unwrap_or(None)
}
Expand Down

0 comments on commit 474d8cb

Please sign in to comment.