Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to change the Mouse cursor #577

Closed
ogoffart opened this issue Oct 14, 2021 Discussed in #576 · 10 comments · Fixed by #721
Closed

Ability to change the Mouse cursor #577

ogoffart opened this issue Oct 14, 2021 Discussed in #576 · 10 comments · Fixed by #721
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ogoffart
Copy link
Member

Discussed in #576

We should add the ability to change the mouse cursor in TouchArea (or possibly on all element?)

   TouchArea {
      mouse-cursor: pointer;
   }

I'm the mouse-cursor: name here, instead of cursor: like in CSS in case we extend the property to be used on all elements.

The value should probably be an enum consisting of the keywords from the CSS spec.
Support for custom cursor could be added later.

@ogoffart ogoffart added the good first issue Good for newcomers label Oct 14, 2021
@ogoffart
Copy link
Member Author

I'm writing implementation step for this in case someone wants to implement this:

  1. One must create a new builtin enum. Builtins enums are currently a bit fastidious to write. because a lot of parts of the code need to be touch. The best is to grep for the existing enum FillRule and see all usages.
  2. Add a property to TouchArea: the comment in the tome of items.rs explain how to do it.
  3. Implement it in TouchArea. Probably the best way to do it is in TouchArea::input_event and look at places where the hover property is changed. And when that property changes, one can tell the backend (via the WindowRc) to set the cursor accordingly.
  4. Add interfaces to sixtyfps_corelib::window::PlatformWindow to change the cursor so that TouchArea::input_event can tell the backend to change the cursor.
  5. Implement these interfaces in the Backends.
    • For the Qt backend, one simply need to call QWidget::setCursor on the window's widget
    • For the GL backend, one can use winit::window::Window::set_cursor_icon

A good example of a pull request that adds a property and an enum is
#465

I added the "good first issue" tag because despite having many steps, none are really difficult. And I would gladly review pull requests that only do part of these steps.

@ogoffart ogoffart added the enhancement New feature or request label Oct 14, 2021
@lemmih
Copy link

lemmih commented Oct 14, 2021

So if I wanted to change the cursor when hovering over an arbitrary SVG path, I could do something like:

   TouchArea {
      mouse-cursor: rust-callback();
   }

And have rust-callback compute the appropriate cursor value?

Also, it would be great if there was a way to specify whether the mouse event should be consumed. This doesn't have any effect in native apps but matters for WebAssembly. If mouse events are always consumed then you cannot scroll past an embedded app on mobile, for example.

@ogoffart
Copy link
Member Author

So if I wanted to change the cursor when hovering over an arbitrary SVG path

Right, you could do mouse-cursor: rust-callback(mouse-x, mouse-y);

Also, it would be great if there was a way to specify whether the mouse event should be consumed

This is a separate issue. The native code kind of do that. But we maybe don't tell winit that the event was not consumed. I don't even know if winit can do that.

@lemmih
Copy link

lemmih commented Oct 14, 2021

Also, it would be great if there was a way to specify whether the mouse event should be consumed

This is a separate issue. The native code kind of do that. But we maybe don't tell winit that the event was not consumed. I don't even know if winit can do that.

Would you be interested in having support for it? I can only see it being useful on the web but you write in your README that "web support is currently limited to demo purposes."

@ogoffart
Copy link
Member Author

Would you be interested in having support for it? I can only see it being useful on the web but you write in your README that "web support is currently limited to demo purposes."

Yes, we would accept pull request. We don't focus on the web right now because we have priorities, and in order to have good support of the web, we probably should write another backend that uses the DOM and not jsut draw everything in a canvas. But we still see web support as a good thing to have.

@lemmih
Copy link

lemmih commented Oct 14, 2021

Okay, I'll look into what it would take to write a PR for this. For context, I'd love to use sixtyfps for computational geometry (https://rgeometry.org) and 3b1b style animations (https://github.com/reanimate/reanimate/). Probably way outside of your intended use-cases but it would make my life a lot easier if I could make it work.

@lukas-jung
Copy link
Contributor

Hey. I'd like to work on this issue if that's ok.

@ogoffart
Copy link
Member Author

@lukas-jung that'd be great, just let me know if you have any questions

@lukas-jung
Copy link
Contributor

I've got a first version running with both backends. there are some problems however.
not all css cursors are available in qt:
context-menu
cell
vertical-text
no-drop
all-scroll
zoom-in
zoom-out
and all unidirectional resizes.

Currently i'm replacing no-drop with not-allowed and the unidirectional resizes with their bidirectional counterpart.
All the other cursors can perhaps be added in a later Issue/PR. One could probably "steal" the bitmaps from webbrowsers or something like that.

However there is a second problem with the move cursor: since 'move' is a rust keyword I cannot use it as an enum variant!
Is it possible to map the .60 move to a rust enum variant that has another name?

Or perhaps the rust side of the enums should always use idiomatic camel case variant names and then the snake case .60 enum variants must be properly mapped to those.

@ogoffart
Copy link
Member Author

ogoffart commented Dec 6, 2021

@lukas-jung nice to hear! please make a PR.

(Someone else also made a PR for this at #708 but it is not finished yet.)

not all css cursors are available in qt:

Then we just have to use some fallback or placeholder, I think your choices make sense.

since 'move' is a rust keyword I cannot use it as an enum variant!

Can you try r#move ?
I think it should work unless the macro that do the enum to string conversion has a bug.

If that is too much of a problem we can also leave it out until we find a solution for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants