question

Ehsan-9426 avatar image
0 Votes"
Ehsan-9426 asked Ehsan-9426 commented

how to draw rounded rectangles in guix

Is it possible to draw rectangles with rounded corners? The canvas api in guix seems to only support normal rectangles, I might be wrong since this is such a basic shape.

azure-rtos
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

KenMaxwell-4349 avatar image
0 Votes"
KenMaxwell-4349 answered Ehsan-9426 commented

For rounded rectangles, it does take some forethought to keep the resources from getting out of hand. I usually define 8 tiny png images, one for each corner and one for each straight side segment. Then write a custom drawing routine that positions the 4 corner pngs at the calling widget's corners, and fills the space between with the vertical and horizontal segment images. This makes it possible to use any size widget and even resize the widgets at runtime without adding any additional resources. This is a bit of work I grant you that, but drawing smooth anti-aliased rounded rectangles in a reasonable amount of compute cycles isn't trivial either.

Regarding text alignment, I think the necessary functionality is there although it may not be obvious. The function gx_system_string_width_get_ext(font, string, return_width) is used to calculate the width of the string, and you can use this value to calculate the top-left starting position for left/right/center aligned text drawing using some simple calculation.

I can see an ease-of-use benefit to something like:

gx_canvas_aligned_text_draw(string, rectangle, alignment)

Is this what you had in mind? If you want the text aligned within some calling widget, you could simply use the widget->gx_widget_size for the rectangle parameter, or you could specify your own rectangle for alignment. I will add this request to our roadmap for the next release if this would meet your needs.

Best Regards

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the detailed explanation regarding custom round rectangles, I will add for the sake of others reading this, that the side images can be one pixel wide and tiled using gx_canvas_pixelmap_tile(). I'm wondering is this is faster than anti aliased drawing. It does have the added benefit that the borders can be styled.

yes, gx_canvas_aligned_text_draw() would be very helpful, I actually ended up implementing something similar to meet my needs for now, that only does centered text.

I do have another request for guix studio, that is, when generating files, allow it to only modify the files that have been changed. It currently updates the timestamp in every file which is pretty annoying if you have a lot of generated files and use source control.

0 Votes 0 ·
KenMaxwell-4349 avatar image
0 Votes"
KenMaxwell-4349 answered Ehsan-9426 commented

It's not a built-in shape. You would have to piece this together using lines and arcs, or alternatively using PNGs. We can add it to our roadmap requests, but I haven't seen any other requests for this and we try to keep the library as small as we can to allow it to be used on lots of small devices.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It would be very convenient to have such functions when developing custom widgets, I don't think it is feasible for most small devices to store many gui elements as pixelmap.
Another missing feature I noticed was lack of text alignment support in the canvas api (outside of the text widgets), again, small devices might not have enough resources for allocating a widget for every text element.

1 Vote 1 ·