-
Notifications
You must be signed in to change notification settings - Fork 698
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
Mouse API makes it way too hard to track button pressed #3312
Comments
How about only using the |
That's what the code above does. I think having to do that is cumbersome. |
I recommend to create 3 events as |
Agreed it's cumbersome and even a little odd for that function. One thing though: For any new or modified code: Please use actual named private methods (not lambdas) when subscribing to public events in library code. Additionally, making those methods static will both perform better (both CPU and heap memory impact) and force or encourage better and more testable code for the event and whatever code caused it to be raised. And remember that any single instance of any delegate can target 0 to n methods, so don't assume that your subscriber is the only one, the first one, nor that it will even get called at all or exactly once, if part of a public event. For code that doesn't do those things when I get to events, it will be done at that time, so don't worry about it for existing code if you don't feel like it (though it will make those diffs easier to grok when they come). But please do for new work. 🙏 |
@tig you want when press button 1 in the view changes color to Toplevel and when drag outside with the button pressed, changes the color to Dialog and when drag again into the view with the button still pressed, change the color to Toplevel. Right? |
I don't think asking the question that way makes sense. As a View, i want to know when the user has pressed a button down. Then I want to know the user has kept the button pressed (regardless of whether the mouse was moved or not). The current api only gives me the later. |
Imagine the button was pressed on a view and the
The task ProcessContinuousButtonPressedAsync or the
With |
I don't think you're getting what I'm puttin' down. This has nothing to do with MouseGrabView or WantContinuous. Today if a user presses the mouse button, moves it a bit, and then releases it,
What I want is:
|
I'm my opinion it isn't the mouse API that have to track those behavior but the View itself. The MouseButton1Pressed or the MouseButton1Down is the same. |
I'd like to undertstand WHY you think this. I disagree because: The ideal way to design a UI library API is to have the API match how end-users think. End users, using mice, think in terms of
The current Terminal.Gui API does not follow this at all. It provides no event for the first action. Other mouse APIs do. For example Windows provides WM_LBUTTONDOWN which is only sent when the mouse button first goes down. WindowsForms: I propose the // Passes all Application mouse events on; lets views have total flexiblity
protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent);
// When the user first presses the button down over a view
protected internal virtual bool OnMouseDown (MouseEvent mouseEvent);
// When the user moves the mouse over a view, or if mouse was grabbed by the view. Flags will indicate if a button is down.
protected internal virtual bool OnMouseMove (MouseEvent mouseEvent);
// When the user lets go of the mouse button. Only received i the mouse is over the view or it was grabbed by the view.
protected internal virtual bool OnMouseUp (MouseEvent mouseEvent);
// When the user presses down and then releases the mouse over a view (they could move off in between).
// If they press and release multiple times in quick succession this event will be called for each up action
protected internal virtual bool OnMouseClick (MouseEvent mouseEvent);
// When the user presses and releases the mouse button twice in quick succession without moving the mouse outside the view
protected internal virtual bool OnMouseDoubleClick (MouseEvent mouseEvent);
// When the user presses and releases the mouse button thrice in quick succession without moving the mouse outside the view
protected internal virtual bool OnMouseTripleClick (MouseEvent mouseEvent); The logic for determining which of these methods to call could either be in |
I think in this case isn't totally a bug because none of the outer views want handle the mouse and the If you move the mouse without press any button and while the mouse is moving you press the Button1, you will get a |
I'll will provide my workaround for this soon, in 1 or 2 hours. |
Why waste time on a work around? We should fix the core issue in a well thought through way. |
Can't you wait too see it, at least. If you don't like you'll say it for sure. |
If it's a holistic solution that addresses the fundamental problem with the current API then absolutely! If it's hack/workaround, then I'm not interested. |
While the mouse is moving and a button is pressed you never will have a unit flag. For this you have to stop the mouse and then press a button.
Ok. If you in the previous step you only get one flag now you'll have two
If the button is released while the mouse is moving sometimes the released event doesn't occurs. In
Ok after the fixes in the #3393 those events can be created on the
They use low level code for that. Here you have to deal with what the drivers provides.
Here if you are moving the mouse when the button is pressed you'll have
With the fixes I provided I think it's more easy to do them in the But that I'll leave with you because it's better you continue those implementations. |
It is also possible to create a new property in the In the What do you think? |
I think that with the changes I've made it's much more easy for you to implement the methods and events as you whish. |
I also will add the above methods and events in this PR as well. |
I think is all done. |
I am sorry you feel I'm acting selfish. I do not believe I am. I am doing my best to ensure this project is successful and I strive to focus on the technical issues, not personality. I am surprised you think I don't value your efforts. I feel like I regularly take the time to thank you for your hard work and great ideas. I can't help how you feel though, but I am motivated to keep trying to do the right thing. |
I know you are trying to do the right thing, as everyone who contributes also tries, but you already make value judgments without letting anyone present their solutions, discouraging them from even presenting them. That's what I disagree with you about. |
To illustrate what I think is wrong with the current Terminal.Gui (and v1) API in this regard, consider this class.
I want this view to show the "TopLevel" colorscheme while button1 is pressed; when button1 is released, or the mouse leaves the view, the color should go back to "Dialog".
Here's how it behaves now. Note that if I press button1 outside of the view and drag into the view, the color changes to "Toplevel". This is not what I want. The current API provides me no way of knowing that the
Button1Pressed
flag was set while the mouse was outsdie of my view.Now, I can work around this like this, but this is awful.
FWIW, the impact of this behavior can be seen (in v1 and v2) in the
Windows & FrameViews
scenario.Press button1 while in the Bounds of
1 - Windows Loop...
and drag up.I think there should be a
View.MouseButton1Pressed
andView.MouseButton1Released
event.Originally posted by @tig in #3290 (comment)
The text was updated successfully, but these errors were encountered: