Skip to content

Commit

Permalink
Adding on_tap
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoods committed Nov 17, 2024
1 parent 8f05f82 commit 10cdb1f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
2 changes: 2 additions & 0 deletions composable-views/src/gesture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub use recognizer::*;

mod tap;

pub use tap::TapGesture;

#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Id(pub(crate) std::num::NonZeroU128);

Expand Down
14 changes: 7 additions & 7 deletions composable-views/src/gesture/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use crate::gesture::{self, Id};
use crate::{Bounds, Event, Output, Point, Size, View};
use composable::Effects;

pub struct TapGesture<V, E, A> {
id: Id,
view: V,
action: A,
send: E,
pub struct TapGesture<V, A, E> {
pub(crate) id: Id,
pub(crate) view: V,
pub(crate) action: A,
pub(crate) send: E,
}

impl<V, E, A> View for TapGesture<V, E, A>
impl<V, A, E> View for TapGesture<V, A, E>
where
V: View,
E: Effects<A>,
A: Clone,
E: Effects<A>,
{
#[inline(always)]
fn size(&self) -> Size {
Expand Down
22 changes: 21 additions & 1 deletion composable-views/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::ops::Deref;

pub use lyon::math::{Box2D as Bounds, Point, Size, Transform};

pub use gesture::{Id, TapGesture};
pub use layout::{Layout, Spacer};
pub use modifiers::fixed::{Fixed, FixedHeight, FixedWidth};
pub use modifiers::padding::Padding;
Expand All @@ -11,7 +12,7 @@ pub use shapes::{Path, Shape};
#[doc(inline)]
pub use text::Text;

use composable::{From, TryInto};
use composable::{Effects, From, TryInto};

/// Alias for `euclid::default::SideOffsets2D<f32>`
pub type Offsets = lyon::geom::euclid::default::SideOffsets2D<f32>;
Expand Down Expand Up @@ -137,6 +138,25 @@ pub trait View: Sized {
fn across(self) -> impl View {
self
}


fn on_tap<A, E>(
self,
id: Id,
action: A,
send: E,
) -> TapGesture<Self, A, E>
where
A: Clone,
E: Effects<A>,
{
TapGesture {
id,
view: self,
action,
send,
}
}
}

impl<T: View> View for Box<T> {
Expand Down
1 change: 0 additions & 1 deletion composable-views/src/modifiers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod fixed;
pub mod offset;
pub mod padding;
25 changes: 0 additions & 25 deletions composable-views/src/modifiers/offset.rs

This file was deleted.

0 comments on commit 10cdb1f

Please sign in to comment.