-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9635ec3
commit a2dff69
Showing
8 changed files
with
410 additions
and
146 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
use winit::event::ElementState; | ||
|
||
use crate::{ | ||
input::{focusable, on_mouse_input}, | ||
ScopeRef, | ||
}; | ||
|
||
use super::Widget; | ||
|
||
pub mod button; | ||
pub mod input; | ||
pub mod slider; | ||
|
||
pub trait InteractiveExt { | ||
fn on_press<F: 'static + Send + Sync + FnMut(&ScopeRef<'_>)>( | ||
self, | ||
on_press: F, | ||
) -> OnPress<Self, F> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
impl<W: Widget> InteractiveExt for W { | ||
fn on_press<F: 'static + Send + Sync + FnMut(&ScopeRef<'_>)>( | ||
self, | ||
on_press: F, | ||
) -> OnPress<Self, F> | ||
where | ||
Self: Sized, | ||
{ | ||
OnPress { | ||
widget: self, | ||
func: on_press, | ||
} | ||
} | ||
} | ||
|
||
pub struct OnPress<W, F> { | ||
widget: W, | ||
func: F, | ||
} | ||
|
||
impl<W, F> Widget for OnPress<W, F> | ||
where | ||
W: Widget, | ||
F: 'static + Send + Sync + FnMut(&ScopeRef<'_>), | ||
{ | ||
fn mount(mut self, scope: &mut crate::Scope<'_>) { | ||
self.widget.mount(scope); | ||
|
||
scope | ||
.set_default(focusable()) | ||
.on_event(on_mouse_input(), move |scope, input| { | ||
if input.state == ElementState::Released { | ||
(self.func)(scope) | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters