mirror of
https://github.com/danbulant/cushy
synced 2026-07-08 04:30:34 +00:00
animate_mouse_button + more example recordings
This commit is contained in:
parent
d234e6e607
commit
774a846210
7 changed files with 149 additions and 9 deletions
4
.github/workflows/docs.yml
vendored
4
.github/workflows/docs.yml
vendored
|
|
@ -58,11 +58,11 @@ jobs:
|
||||||
|
|
||||||
- name: Regenerate Example Images
|
- name: Regenerate Example Images
|
||||||
run: |
|
run: |
|
||||||
CAPTURE=1 cargo test -p cushy --examples --all-features
|
CAPTURE=1 cargo test -p cushy --examples --all-features -r
|
||||||
|
|
||||||
- name: Regenerate Guide Example Images
|
- name: Regenerate Guide Example Images
|
||||||
run: |
|
run: |
|
||||||
CAPTURE=1 cargo test -p guide-examples --examples
|
CAPTURE=1 cargo test -p guide-examples --examples -r
|
||||||
|
|
||||||
- name: Build Guide
|
- name: Build Guide
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
- `AnimationRecorder::animate_keypress` is a new helper that animates a single
|
- `AnimationRecorder::animate_keypress` is a new helper that animates a single
|
||||||
key press.
|
key press.
|
||||||
|
- `AnimationRecorder::animate_mouse_button` is a new helper that animates a
|
||||||
|
single mouse button press and release.
|
||||||
|
|
||||||
## v0.3.0 (2024-05-12)
|
## v0.3.0 (2024-05-12)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use cushy::widget::MakeWidget;
|
||||||
use cushy::widgets::Disclose;
|
use cushy::widgets::Disclose;
|
||||||
use cushy::Run;
|
use cushy::Run;
|
||||||
|
|
||||||
fn main() -> cushy::Result {
|
fn disclose() -> impl MakeWidget {
|
||||||
Disclose::new(
|
Disclose::new(
|
||||||
"This is some inner content"
|
"This is some inner content"
|
||||||
.align_left()
|
.align_left()
|
||||||
|
|
@ -10,5 +10,44 @@ fn main() -> cushy::Result {
|
||||||
.into_rows(),
|
.into_rows(),
|
||||||
)
|
)
|
||||||
.labelled_by("This demonstrates the Disclose widget")
|
.labelled_by("This demonstrates the Disclose widget")
|
||||||
.run()
|
}
|
||||||
|
|
||||||
|
fn main() -> cushy::Result {
|
||||||
|
disclose().run()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn runs() {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use cushy::animation::easings::EaseInOutSine;
|
||||||
|
use figures::units::Px;
|
||||||
|
use figures::Point;
|
||||||
|
use kludgine::app::winit::event::MouseButton;
|
||||||
|
|
||||||
|
cushy::example!(disclose, 600, 300)
|
||||||
|
.prepare_with(|r| {
|
||||||
|
r.set_cursor_position(Point::new(Px::new(16), Px::new(64)));
|
||||||
|
r.set_cursor_visible(true);
|
||||||
|
})
|
||||||
|
.animated(|r| {
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(30), Px::new(30)),
|
||||||
|
Duration::from_millis(500),
|
||||||
|
EaseInOutSine,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.animate_mouse_button(MouseButton::Left, Duration::from_millis(100))
|
||||||
|
.unwrap();
|
||||||
|
r.wait_for(Duration::from_secs(1)).unwrap();
|
||||||
|
r.animate_mouse_button(MouseButton::Left, Duration::from_millis(100))
|
||||||
|
.unwrap();
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(16), Px::new(64)),
|
||||||
|
Duration::from_millis(500),
|
||||||
|
EaseInOutSine,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.wait_for(Duration::from_secs(1)).unwrap();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use cushy::widget::{MakeWidget, WidgetList};
|
||||||
use cushy::widgets::list::ListStyle;
|
use cushy::widgets::list::ListStyle;
|
||||||
use cushy::Run;
|
use cushy::Run;
|
||||||
|
|
||||||
fn main() -> cushy::Result {
|
fn list() -> impl MakeWidget {
|
||||||
let current_style: Dynamic<ListStyle> = Dynamic::default();
|
let current_style: Dynamic<ListStyle> = Dynamic::default();
|
||||||
let options = ListStyle::provided()
|
let options = ListStyle::provided()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -24,5 +24,13 @@ fn main() -> cushy::Result {
|
||||||
.into_columns()
|
.into_columns()
|
||||||
.expand()
|
.expand()
|
||||||
.pad()
|
.pad()
|
||||||
.run()
|
}
|
||||||
|
|
||||||
|
fn main() -> cushy::Result {
|
||||||
|
list().run()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn runs() {
|
||||||
|
cushy::example!(list).untested_still_frame();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ enum MenuOptions {
|
||||||
Third,
|
Third,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> cushy::Result {
|
fn menu_example() -> impl MakeWidget {
|
||||||
let overlay = OverlayLayer::default();
|
let overlay = OverlayLayer::default();
|
||||||
|
|
||||||
"Click Me"
|
"Click Me"
|
||||||
|
|
@ -30,7 +30,10 @@ fn main() -> cushy::Result {
|
||||||
.expand()
|
.expand()
|
||||||
.and(overlay)
|
.and(overlay)
|
||||||
.into_layers()
|
.into_layers()
|
||||||
.run()
|
}
|
||||||
|
|
||||||
|
fn main() -> cushy::Result {
|
||||||
|
menu_example().run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn menu(top: bool) -> Menu<MenuOptions> {
|
fn menu(top: bool) -> Menu<MenuOptions> {
|
||||||
|
|
@ -53,3 +56,66 @@ fn menu(top: bool) -> Menu<MenuOptions> {
|
||||||
.with_separator()
|
.with_separator()
|
||||||
.with(third)
|
.with(third)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn runs() {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use cushy::animation::easings::{EaseInCircular, EaseInOutSine, EaseOutCircular};
|
||||||
|
use figures::units::Px;
|
||||||
|
use figures::Point;
|
||||||
|
use kludgine::app::winit::event::MouseButton;
|
||||||
|
|
||||||
|
cushy::example!(menu_example, 800, 600)
|
||||||
|
.prepare_with(|r| {
|
||||||
|
r.set_cursor_position(Point::new(Px::new(420), Px::new(270)));
|
||||||
|
r.set_cursor_visible(true);
|
||||||
|
r.refresh().unwrap();
|
||||||
|
})
|
||||||
|
.animated(|r| {
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(410), Px::new(300)),
|
||||||
|
Duration::from_millis(500),
|
||||||
|
EaseInOutSine,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.animate_mouse_button(MouseButton::Left, Duration::from_millis(250))
|
||||||
|
.unwrap();
|
||||||
|
r.wait_for(Duration::from_millis(500)).unwrap();
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(430), Px::new(325)),
|
||||||
|
Duration::from_millis(200),
|
||||||
|
EaseInCircular,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(480), Px::new(480)),
|
||||||
|
Duration::from_millis(400),
|
||||||
|
EaseOutCircular,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.wait_for(Duration::from_millis(300)).unwrap();
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(620), Px::new(460)),
|
||||||
|
Duration::from_millis(600),
|
||||||
|
EaseInOutSine,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(460), Px::new(340)),
|
||||||
|
Duration::from_millis(800),
|
||||||
|
EaseInOutSine,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.animate_mouse_button(MouseButton::Left, Duration::from_millis(250))
|
||||||
|
.unwrap();
|
||||||
|
r.wait_for(Duration::from_millis(500)).unwrap();
|
||||||
|
r.animate_cursor_to(
|
||||||
|
Point::new(Px::new(420), Px::new(270)),
|
||||||
|
Duration::from_millis(500),
|
||||||
|
EaseInOutSine,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
r.wait_for(Duration::from_millis(500)).unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ impl Widget for DiscloseIndicator {
|
||||||
|
|
||||||
fn mouse_up(
|
fn mouse_up(
|
||||||
&mut self,
|
&mut self,
|
||||||
_location: Option<Point<Px>>,
|
location: Option<Point<Px>>,
|
||||||
_device_id: DeviceId,
|
_device_id: DeviceId,
|
||||||
_button: kludgine::app::winit::event::MouseButton,
|
_button: kludgine::app::winit::event::MouseButton,
|
||||||
context: &mut EventContext<'_>,
|
context: &mut EventContext<'_>,
|
||||||
|
|
@ -343,6 +343,11 @@ impl Widget for DiscloseIndicator {
|
||||||
self.deactivate(context);
|
self.deactivate(context);
|
||||||
self.collapsed.toggle();
|
self.collapsed.toggle();
|
||||||
}
|
}
|
||||||
|
let hovering = location.map_or(false, |location| self.hit_test(location, context));
|
||||||
|
if hovering != self.hovering_indicator {
|
||||||
|
self.hovering_indicator = hovering;
|
||||||
|
context.set_needs_redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(&mut self, _context: &mut EventContext<'_>) {
|
fn activate(&mut self, _context: &mut EventContext<'_>) {
|
||||||
|
|
|
||||||
|
|
@ -3500,6 +3500,26 @@ where
|
||||||
self.wait_for(over)
|
self.wait_for(over)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Animates pressing and releasing a mouse button at the current cursor
|
||||||
|
/// location.
|
||||||
|
pub fn animate_mouse_button(
|
||||||
|
&mut self,
|
||||||
|
button: MouseButton,
|
||||||
|
duration: Duration,
|
||||||
|
) -> Result<(), VirtualRecorderError> {
|
||||||
|
let _ =
|
||||||
|
self.recorder
|
||||||
|
.window
|
||||||
|
.mouse_input(DeviceId::Virtual(0), ElementState::Pressed, button);
|
||||||
|
|
||||||
|
self.wait_for(duration)?;
|
||||||
|
let _ =
|
||||||
|
self.recorder
|
||||||
|
.window
|
||||||
|
.mouse_input(DeviceId::Virtual(0), ElementState::Released, button);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Simulates a key down and key up event with the given information.
|
/// Simulates a key down and key up event with the given information.
|
||||||
pub fn animate_keypress(
|
pub fn animate_keypress(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue