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

Togglebuttons with only Icons #2209

Open
orpheus92 opened this issue Sep 13, 2018 · 10 comments
Open

Togglebuttons with only Icons #2209

orpheus92 opened this issue Sep 13, 2018 · 10 comments
Milestone

Comments

@orpheus92
Copy link
Contributor

I have a togglebuttons related question.
When I am created togglebuttons, would it be possible to create several buttons without name? In that case, only the icons are used to show the button.
Also, for the togglebuttons, does it support removing one of it or add another toggle button to it?
Thanks

@jasongrout jasongrout added this to the Reference milestone Sep 13, 2018
@jasongrout
Copy link
Member

When I am created togglebuttons, would it be possible to create several buttons without name? In that case, only the icons are used to show the button.

You should be able to create buttons with only icons.

Also, for the togglebuttons, does it support removing one of it or add another toggle button to it?

That should work.

@maartenbreddels maartenbreddels changed the title Togglebuttons Togglebuttons with only Icons Oct 1, 2018
@maartenbreddels
Copy link
Member

You should be able to create buttons with only icons.

I'm afraid that doesn't work, or should not work, as the documentation says:

options can be specified as a list of values, list of (label, value)
tuples, or a dict of {label: value}. The labels are the strings that will be
displayed in the UI, representing the actual Python choices, and should be
unique. If labels are not specified, they are generated from the values.

I think we should not require unique labels though, is there any reason for it?

@maartenbreddels
Copy link
Member

I changed #2182 to allow non-unique labels.

@martinRenou
Copy link
Member

I was trying to achieve the same thing right now, TogglesButtons with only icons.

I think we should not require unique labels though, is there any reason for it?

I totally agree with you. It feels wrong to me. Actually, I feel like values should be unique, not labels. Right now nothing stops you from creating a ToggleButtons with duplicated values:

ToggleButtons(options=[('first', ''), ('second', '')])

And this totally breaks the selection, both in the GUI and from Python.

I suppose a proper ToggleButtons implementation would be:

  • labels should not be required to be unique, labels should only be visual information. That would allow creating ToggleButtons with only icons:
ToggleButtons(options=[('', 0), ('', 1)], icons=['home', 'arrow-left'])
  • values should be required to be unique, that would prevent doing:
ToggleButtons(options=[('first', ''), ('second', '')]) # Broken
  • options should be a dictionary-like mapping a value to a label, not a dictionary-like mapping a label to a value.

@giswqs
Copy link
Contributor

giswqs commented May 10, 2020

Any update on ToggleButtons with only icons? Although the following code can create ToggleButtons with only icons, the buttons are not responding to mouse-clicking properly, as the labels are non-unique.

ToggleButtons(options=[('', 0), ('', 1)], icons=['home', 'arrow-left'])

@maread99
Copy link

maread99 commented Jul 3, 2020

It ain't pretty, but seems to work:

ToggleButtons(options = [('', 0), (' ', 1), ('  ', 2)], value=1,
              icons=['refresh', 'close', 'arrow-up'],
              style=ToggleButtonsStyle(button_width='35px'))

image
It appears the label + icon concatenation strips preceeding whitespace, so you can get away with the above without creating ugly misaligned icons.

@giswqs
Copy link
Contributor

giswqs commented Jul 3, 2020

@maread99 Thanks for providing this workaround. It works.

@maartenbreddels
Copy link
Member

@giswqs
Copy link
Contributor

giswqs commented Jul 3, 2020

@maartenbreddels Wow, ipyvuetify looks fantastic. I need to try it out. Thanks.

@nvaytet
Copy link

nvaytet commented Oct 12, 2022

While @maread99 's suggestions is a good workaround, it seems the description is still kind of there when I make the buttons very narrow:

ipw.ToggleButtons(options = [('', 0), (' ', 1), ('  ', 2)], value=1,
              icons=['refresh', 'close', 'arrow-up'],
              style=ipw.ToggleButtonsStyle(button_width='15px'))

Screenshot at 2022-10-12 22-01-24

It shows up as little dots (for some reason, the close icon seems narrower than the others).

Is it possible to hide the description alltogether?

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

No branches or pull requests

7 participants