lowenware / dotrix

A 3D engine with ECS and Vulkan renderer for Rust developers
https://dotrix.rs
MIT License
292 stars 11 forks source link

Horizontal scroll #131

Closed QuantumEntangledAndy closed 2 years ago

QuantumEntangledAndy commented 2 years ago

This adds horizontal scroll to the input.

I rather like blenders trackpad controls using the horizontal scroll so I wanted this for my app.

p.s. I use rustfmt by default in my editor and that makes a lot of changes. Would you be ok with putting the whole project through rustfmt or should I look to disabling that?

voxelias commented 2 years ago

I am ok with rustfmt, even wanted to put it into CI. Would be nice to have it in one separate commit though.

QuantumEntangledAndy commented 2 years ago

I have a CI script for rustfmt and clippy a use in another project. Shall I put it in?

voxelias commented 2 years ago

It would be very kind of you :)

QuantumEntangledAndy commented 2 years ago

Do you use tap to click on your mac's touch pad? The egui dosen't seem to like tap to click for buttons only actual clicks.

I put a couple of debug prints in and found that when using tap to click the state of the button is Deactivated while egui expects it to be Hold with this line pressed: button_state == InputState::Hold,. I think perhaps tap to click just sends the button up event and no other

voxelias commented 2 years ago

Can it be that TAP triggers a separate event that we ignore?

QuantumEntangledAndy commented 2 years ago

From the looks of it tap just sends mouse up. Which I thinnk is normal, consider what happens when you click a hyper link on a webpage: You can click it drag the mouse away and letgo and the hyper link won't activate. Only the mouse up event triggers the link event

QuantumEntangledAndy commented 2 years ago

Have you also noticed how if you have an egui side bar (like in the lights demo) and you click and drag to move the camera it will also resize the side bar if your drag goes in that area.

I suspect that if would also drag scroll bars etc

QuantumEntangledAndy commented 2 years ago

Perhaps egui needs a global context of active ui element

QuantumEntangledAndy commented 2 years ago

Here's a video showing what I mean

https://user-images.githubusercontent.com/13386481/148160403-ed996f25-2950-4b90-9ea8-48890caded49.mp4

QuantumEntangledAndy commented 2 years ago

I am thinking it needs to handle mouse down and up fully rather than just have a yes/no for pressed.

I think this covers it:

Any thoughts?

QuantumEntangledAndy commented 2 years ago

Hmm I see you are delgating to https://github.com/emilk/egui for the lifting. I'll look into there and see what can be done

QuantumEntangledAndy commented 2 years ago

It seems we want to use this function:

https://github.com/emilk/egui/blob/b1fd6a44e82c8cde7fab0b952851d2d2fd785349/egui/src/context.rs#L743-L750

    /// True if egui is currently interested in the pointer (mouse or touch).
    /// Could be the pointer is hovering over a [`Window`] or the user is dragging a widget.
    /// If `false`, the pointer is outside of any egui area and so
    /// you may be interested in what it is doing (e.g. controlling your game).
    /// Returns `false` if a drag started outside of egui and then moved over an egui area.
    pub fn wants_pointer_input(&self) -> bool {
        self.is_using_pointer() || (self.is_pointer_over_area() && !self.input().pointer.any_down())
    }
QuantumEntangledAndy commented 2 years ago

Ok so I made some more changes and have it working.

https://user-images.githubusercontent.com/13386481/148176542-2235d1ab-5d50-47cb-86a6-72da6afabee1.mp4

QuantumEntangledAndy commented 2 years ago

The example looks good to me. There is still issue, that you can rotate the camera with mouse even if mouse is above he UI. But I would fix it separately and globally.

Do you mean when the click starts outside the ui? That was intentional, I expect that if my click starts with controlling the camera it keeps doing that until i let go

voxelias commented 2 years ago

Try to hover mouse over the sidebar, then hold right button and move.

QuantumEntangledAndy commented 2 years ago

Try to hover mouse over the sidebar, then hold right button and move.

That dosen't move the camera for me

QuantumEntangledAndy commented 2 years ago

https://user-images.githubusercontent.com/13386481/148196118-0d8c61e9-2a34-4a21-9472-02b18ac86296.mp4