kengineer Posted July 20, 2016 Report Posted July 20, 2016 (edited) I've setup a custom draw function for a button that I use to include an image in the button. I'd like the size to be based on the size of the image, so in the custom drawing routine, I tried resizing the widget by setting the values of gw->g.width and gw->g.height However this does not seem to work. I'm guessing this is because there needs to be some call to update these parameters with the window system. Before I dig into this further, I wanted to verify if this is even possible. Edited July 20, 2016 by kengineer
Joel Bodenmann Posted July 20, 2016 Report Posted July 20, 2016 You are not supposed to do that. The window manager is responsible for the positioning and the dimensions of the widgets that it maintains. A widget is not supposed to change its size by itself. May I ask why you would want to do that anyway? The µGFX library has been written to be as small and as fast as possible. The sizes of the images you want to be using for your buttons should be well known at compile time. The µGFX-Studio takes care of that for you and automatically adjust the size of your button to the image size if you select the image rendering routine.
kengineer Posted July 20, 2016 Author Report Posted July 20, 2016 Convenience mainly, I'm using an icon as a button and wanted to add some other things like text attributes and would be nice if it could autosize based on all these. I guess the better way to do this would be to implement by own custom widget to do this based on the button widget.
Joel Bodenmann Posted July 20, 2016 Report Posted July 20, 2016 You can have a look at the default drawing routine implementation of the label widget. It allows resizing the widget to fit the text. However, we discourage doing that - really. It goes against the µGFX philosophy. A widget is not supposed to resize itself. The window manager is responsible for the positioning and dimensions of the widgets. To resize, the widget must call the window manager function gwinResize() which will cause a lot of things to happen: It will have to verify the validity of the new dimensions, move the widget if it hits the clipping region, redraw any widget that is now becoming visible and so on. Additionally, it will also issue a redraw of the widget that called gwinResize() and therefore render the widget twice. To overcome some of these problems (including crashes!) we restrict the label widget to only grow larger. If you are writing your own widget you can auto-size it in the gwinCreateXxx() function. The label widget does that too. Note how the auto-sizing happens before _gwidetCreate() is called and therefore before the widget is being submitted to the window manager. @inmarket might have some additional things to say to this but in my opinion you really don't want to mess with things like that. The µGFX library has been written to be as resource friendly as possible to target embedded systems which usually feature static GUIs. It's possible to save a lot of memory and CPU cycles but that imposes these kinds of limitations.
inmarket Posted July 21, 2016 Report Posted July 21, 2016 Resizing within the widget code is nasty because of the various locks and redrawing required. While the label widget supports auto-sizing there are situations where it can get into endless resizing loops when you try to update the auto-size after widget creation. If you want to auto-size let me suggest that you only do it during widget creation and not dynamically thereafter. If you follow the placement of the code that the label uses for sizing on widget creation you should be relatively safe. Resizing after the widget is created is highly likely to cause you all sorts of pain.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now