The label is updated when the button is clicked and I wanted to know if it would be possible to change the color of the text for this purpose. If this is not an option then being able to change the color of the button would benefit me too.

1 Answer
1

Yes, yes it is possible, but the library doesn't make it easy out of the box. Fortunately, this is Racket, so we can easily make our own (much easier) abstraction. I'll cut to the chaise and show you it. Its a colorerable-button% class, that works like button%, except it has a color argument and set-color field:

This complexity stems from the button%'s label api. It can either accept a string or a bitmap%. Unfortunately, the string is not very flexible, but the bitmap% one is a bit more flexible. So this new type of button grabs the string its given (if given one rather than a bitmap%), and converts it to a bitmap% manually. This enables the class to manually set the color of the text and even dynamically change it.

The whole text-size-dc is just to compensate for some unfortunate decisions with the dc<%> api. Namely, to get the extent of text we need to create a dc<%> object, but we don't know how bit of a bitmap% it should have until we have the size. So we just create a 1 pixel dc<%> object that exists only to get the size needed for text.

So if there's a colorable-button% class, does this mean there's also stuff like colorable-frame%, colorable-panel% etc that would allow me to set the background color?
– FatboyJamesJan 27 '18 at 22:19

That would be very nice. It looks like the current frame% class doesn't let you do that easily, and you'd end up needing to use a canvas%. In theory you could use the snip% api, but its clunky. I'm currently working on fixing this oversight, but it will take some time. :/
– Leif AndersenJan 29 '18 at 4:22

Any insight into how to make a background color for a frame while at the same time being able to keep GUI elements like buttons overlayed on top would be great
– FatboyJamesJan 29 '18 at 19:53