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

Spinner Widget [draft/work in progress] #711

Closed

Conversation

DerThorsten
Copy link

@DerThorsten DerThorsten commented Feb 25, 2020

Description:

Spinner Widget implementation composed of button and entry widget + border layout

Fixes #(issue)
Missing Spinner Widget

  • In Spinner Widget  #704 @andydotxyz already hinted that I should rather use entry.OnChanged instead of relying on a press of Enter. But OnChanged does not work well with a spinner, because while entering a valid number one generates text which does not encode a number inbetween (for instance when typing 10.0 one has a 10. at some point, or for 1e-4 one has 1e. Therefore I think enter is more appropriate. When spinner.GetValue() is called the current text is also evaluated (even without a press of enter).
  • Also @andydotxyz hinted to arrange the buttons vertically instead of horizontally, but this makes the height of the widget the height of two buttons which looks shitty (how would I resize two buttons which are arranged horizontally to have exactly the height of the entry widget?)
  • atm the widget extends a container canvas object, so all the public methods of the container are also visible in the spinner widget, which does not feel right, but not sure how to address this without manually adding all the methods from container which are needed by hand.
  • @andydotxyz suggested to implement the spinner by extending entry widget, but the entry widget is already very complicated and I did not like to read 1200 LOC just to implement something like a spinner which is clearly a composition of a text entry and two buttons (also I wanted to see how easy/hard it is to implement a custom widget by composing existing widgets)

@DerThorsten DerThorsten mentioned this pull request Feb 25, 2020
@DerThorsten DerThorsten changed the title added inital implementation of spinner widget Spinner Widget [draft/work in progress] Feb 25, 2020
@Kvaz1r
Copy link
Contributor

Kvaz1r commented Feb 25, 2020

Therefore I think enter is more appropriate.

I would also handled focus lost event with Enter.

Also @andydotxyz hinted to arrange the buttons vertically instead of horizontally, but this makes the height of the widget the height of two buttons which looks shitty (how would I resize two buttons which are arranged horizontally to have exactly the height of the entry widget?)

That's because it's usual view for Spinner (although it doesn't mean that every GUI library should use only such way). As for size - each button just takes ((height of entry)/2 - minus some border value)

@DerThorsten
Copy link
Author

DerThorsten commented Feb 25, 2020

As for size - each button just takes ((height of entry)/2 - minus some border value)

Sure, this is what we want, but not sure how to enforce this.

@andydotxyz
Copy link
Member

Thanks for working on this. As you'll be seeing I guess that getting API right is a lot more work than composing existing APIs.
I haven't gone through the code in detail, but in response to your comments introducing this I hope the following helps:

  • OnChanged could work if you ignore the times when the text is invalid, then do the full update when it is valid. Also we should add OnChanged for this widget so people could subscribe to change notifications.
  • You can see that we don't typically use getter functions but fields instead, that may play into the onChanged vs enter press conversation
  • Yes if you use a basic button 2 of them are twice the height, the complete widget will probably have to be slightly more complex to get a better user experience?
  • You're right about extending Container - we can't do this as every API will be exposed - we are very careful about only exposing API that absolutely is required. Extending Entry would be closer to the desired API I guessed - but perhaps it will have to be a complete custom widget to manage the API.

Perhaps some of this would be made easier if we implement the proposed #709 Simple Widget (as you could pass a container in to that so it's fully encapsulated?)

@andydotxyz
Copy link
Member

Anything we can do to help with this pull request?

@Jacalz
Copy link
Member

Jacalz commented Jun 15, 2020

Hi @DerThorsten. Have you had the time to look at this again? You have done some good work on this spinner widget and it is definitely something that would be useful in the toolkit if you ask me :)

@andydotxyz
Copy link
Member

The Entry widget now has ActionItem that might allow this to be implemented more easily (like the password show/hide button).
Are you still interested in picking this up @DerThorsten ?

@Jacalz
Copy link
Member

Jacalz commented Dec 6, 2020

Hi @DerThorsten. I hope that you are doing well and continuing to enjoy using Fyne. We have recently opened a new community contributions repository (https://github.com/fyne-io/fyne-x) where new widgets can be added faster and then possibly move into here over time. We would recommend that this PR be updated and re-opened over there. Hopefully we can continue the discussion there 🙂

@Jacalz Jacalz closed this Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants