christolliday / limn

Experimental cross platform GUI library
Other
404 stars 19 forks source link

Add button label @ update example #15

Closed wendivoid closed 6 years ago

wendivoid commented 6 years ago

I'm simple reopening this, I need to put some thought into whether ButtonLabels should be Image widgets or simple Image draw states.

christolliday commented 6 years ago

Hmm, my first thoughts are: 1: Does there need to be a concept of a ButtonLabel? What about just having set_text and set_image instead of set_label, in theory you could use both at the same time. 2: I think it's probably better to just take a image path (&str) as an argument instead of an ImageState, since the button should probably be in charge of scaling/position the image.

wendivoid commented 6 years ago

1: I Initially tried the way you suggested but i came into problems when trying to implement the same for the ToggleButton, the set_image function would be tricky. If i wanted to set an image for each state On, Off, On Hover, Off Hover, (Inactive?) the functions signature gets pretty ugly. Using the ButtonLabel enum would allow both button types(possibly more) to share the same API cleanly. But i'm willing to follow your direction/guidence though.

2: Your right that would be much simpler, i will change!

christolliday commented 6 years ago

Ok I see, yeah the set_text method for ToggleButton let's you set on and off states more easily because that's a common use for a ToggleButton, beyond that, for setting arbitrary states, I think the best interface is to provide a Vec<*Style>. So for text you could have set_text and set_text_style which takes a Vec<TextStyle>, and for images you would have set_image and set_image_style which takes a Vec<ImageStyle> where ImageStyle doesn't exist yet but would be similar to a TextStyle, but probably only take the image string.

That way you could do something like this, but for any state you want

button.set_image_style(style!(ImageStyle::Image: selector!("off.png", ACTIVATED: "on.png")))
wendivoid commented 6 years ago

Ok It would probably be easier to close this and start from scratch. It'll be a few days before i have some more time to work on it but i'll have a new PR in a few days.