mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.24k stars 243 forks source link

Mouse support, Issue #452 #457

Closed hanek23 closed 4 years ago

hanek23 commented 4 years ago

Mouse support for: Button, TextBox, CheckBox, ActionListBox, RadioListBox, Menu and Table and a bit of refactoring.

I mostly edited handleKeyStroke methods of these components but when I came across MenuBar, Menu and MenuItem I ran into a problem with how components were drawn if there was or was not Menu at the top. What I found out was that if there is a Menu bar, all components would be down by 1 row but their coordinates would stay the same, as if there was no Menu bar and that was messing up mouse clicks, obviously. So what I have done is: edited AbstactComposite#setComponent to take into account that +1 if there is MenuBar present and since EmptyMenuBar is an inner class I had to do a bit of an ugliness. With that I also removed what I believe was another hack in AbstractBasePane where there was something similar with EmptyMenuBar handling.

I also added getGlobalPosition in Component interface for convenient access to global coordinates of top the left corner of the component.

One component that I was not able to make reactive to mouse is ComboBox because of that inner window which for some reason was not responsive to mouse clicks.

I tested everything on Linux Mint 19.1 inside standard terminal and telnet. I was not able to get it working in putty though. And obviously I don't know all uses of all components so it is possible it is not even working in some cases.

I have a few more aesthetic modifications in mind, for example extract that same old "if (enter || mouse || character(' ') && isFocused)" in every handleKeyStroke; some "is" methods on KeyStroke like "isEnter" "isMouseClick" and so on, which would in my opinion make it more readable, but that is for future PR, first I want to get this one through.

mabe02 commented 4 years ago

You seem to be committing mixed tabs and spaces... :(

mabe02 commented 4 years ago

I can't easily fix the tabs without rebasing, so I'm probably going to merge it as-is. The code looks fine.

mabe02 commented 4 years ago

Okay, I've merged and then amended the commit to swap tabs->spaces

hanek23 commented 4 years ago

Yeah I am sorry about that. I have a habit of clicking auto formatting bind all the time and since we do not have the formatter settings it got all messed up, tried to fix most of it in that branch but I guess I did not get everything.