pistondevelopers / drag_controller Goto Github PK
View Code? Open in Web Editor NEWA drag controller
License: MIT License
A drag controller
License: MIT License
All I really want out of DragController
is to know when an area is being dragged, and by how much each frame. It'd be really cool if it could do that. I might implement this myself real quick.
The event
method takes f: |Drag| -> bool
which in code is not self documenting, since one usually puts true
or false
at the end of the closure.
By using an enum DragAction
with Continue
and Cancel
the code will be easier to read.
Tried to fix myself, but couldn't quite figure it out.
Compiling piston2d-drag_controller v0.0.2 (file:///Users/aaronmcleod/Documents/programming/rust/drag_controller)
src/lib.rs:69:17: 69:49 error: mismatched types:
expected `input::Button`,
found `input::Button`
(expected enum `input::Button`,
found a different enum `input::Button`) [E0308]
src/lib.rs:69 Button::Mouse(MouseButton::Left) => {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:83:17: 83:49 error: mismatched types:
expected `input::Button`,
found `input::Button`
(expected enum `input::Button`,
found a different enum `input::Button`) [E0308]
src/lib.rs:83 Button::Mouse(MouseButton::Left) => {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile `piston2d-drag_controller`.
I'm using piston with gfx and glutin, and when I resize the window, it starts a drag once I let go of the mouse button on the window resize, and a drag is happening without having the mouse button pressed.
If the mouse cursor leaves the window while a drag is in progress, the drag controller will continue the drag when it re-enters, even if the mouse button was released while the cursor was out of view. This is generally undesirable behavior, as far as I can tell.
Some window back-ends do not emit mouse events outside the window, which might cause undesirable behavior.
For example, when dragging and left mouse button is released outside the window, when entering this might mess up something and with no way to cancel the operation.
I think there should be a way to cancel drag operations. This can be a useful feature also when you can continue dragging outside the window.
A = dealing with interruption, such as window loosing focus
B = dealing with cancelling
M = mess up behavior
A, B, !M.
When dealing with interruption, you can also deal with cancelling operations.
!A, !B, ?!M.
When not dealing with interruption or cancelling, you usually don't mess up behavior. Cancelling can simply be ignored.
When building the current Piston, I get the following:
$ cargo build --verbose
[...]
Compiling input v0.0.0 (https://github.com/pistondevelopers/input#fb351501)
[...]
Compiling drag_controller v0.0.0 (https://github.com/pistondevelopers/drag_controller#a797ac06)
[...]
src/lib.rs:17:5: 17:10 error: unresolved import `input::Mouse`. There is no `Mouse` in `input`
src/lib.rs:17 Mouse,
^~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `drag_controller`.
where it bails as indicated. Checking input
, there is indeed no input::Mouse
present.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.