Skip to content

Commit

Permalink
Merge branch 'main' into thread-local-context
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Dec 11, 2023
2 parents 4009aee + dd6062f commit 18985bc
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 283 deletions.
2 changes: 1 addition & 1 deletion docs/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To create a binding for a member of a struct, use `make_lens!` and `bind` Suppos
struct MyState {
value: f32,
}
make_lens!(MyLens, MyState, f32, x);
make_lens!(MyLens, MyState, f32, value);
```

then we can use `bind` to create a control for `value`:
Expand Down
51 changes: 40 additions & 11 deletions src/modifiers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

use crate::*;
use accesskit::Role;
use std::marker::PhantomData;

/// Modifiers common to all views.
pub trait Modifiers: View + Sized {
Expand Down Expand Up @@ -32,8 +34,16 @@ pub trait Modifiers: View + Sized {
fn drag<F: Fn(&mut Context, LocalOffset, GestureState, Option<MouseButton>) + 'static>(
self,
f: F,
) -> Drag<Self, F> {
Drag::new(self, f)
) -> Drag<Self, DragFunc<F>> {
Drag::new(self, DragFunc { f })
}

/// Calls a function in response to a drag. Version which passes the position.
fn drag_p<F: Fn(&mut Context, LocalPoint, GestureState, Option<MouseButton>) + 'static>(
self,
f: F,
) -> Drag<Self, DragFuncP<F>> {
Drag::new(self, DragFuncP { f })
}

/// Calls a function in response to a drag. Version which passes in a binding.
Expand All @@ -43,15 +53,26 @@ pub trait Modifiers: View + Sized {
F: Fn(&mut T, LocalOffset, GestureState, Option<MouseButton>) + 'static,
>(
self,
s: B,
b: B,
f: F,
) -> DragS<Self, F, B, T> {
DragS::new(self, s, f)
) -> Drag<Self, DragFuncS<F, B, T>> {
Drag::new(self, DragFuncS { f, b, phantom: PhantomData::default() })
}

/// Calls a function in response to a mouse hovering.
fn hover<F: Fn(&mut Context, bool) + 'static>(self, f: F) -> Hover<Self, F> {
Hover::new(self, f)
fn hover<A: 'static, F: Fn(&mut Context, bool) -> A + 'static>(
self,
f: F,
) -> Hover<Self, HoverFunc<F>> {
Hover::new(self, HoverFunc { f })
}

/// Calls a function in response to a mouse hovering. Version which passes the position
fn hover_p<A: 'static, F: Fn(&mut Context, LocalPoint) -> A + 'static>(
self,
f: F,
) -> Hover<Self, HoverFuncP<F>> {
Hover::new(self, HoverFuncP { f })
}

/// Add an environment value.
Expand Down Expand Up @@ -101,14 +122,22 @@ pub trait Modifiers: View + Sized {
}

/// Calls a function in response to a tap.
fn tap<A: 'static, F: Fn(&mut Context) -> A + 'static>(self, f: F) -> Tap<Self, F> {
Tap::new(self, f)
fn tap<A: 'static, F: Fn(&mut Context) -> A + 'static>(self, f: F) -> Tap<Self, TapAdapter<F>> {
Tap::new(self, TapAdapter { f })
}

/// Version of `tap` which takes an action type instead
/// of a function.
fn tap_a<A: 'static>(self, action: A) -> TapA<Self, A> {
TapA::new(self, action)
fn tap_a<A: Clone + 'static>(self, action: A) -> Tap<Self, TapActionAdapter<A>> {
Tap::new(self, TapActionAdapter { action })
}

/// Version of `tap` which passes the tap position and mouse button.
fn tap_p<A: 'static, F: Fn(&mut Context, LocalPoint, Option<MouseButton>) -> A + 'static>(
self,
f: F,
) -> Tap<Self, TapFunc<F>> {
Tap::new(self, TapFunc { f })
}

/// Specify the title of the window.
Expand Down
Loading

0 comments on commit 18985bc

Please sign in to comment.