how to draw rounded rectangles in guix

Ehsan 26 Reputation points
2021-11-01T17:53:05.647+00:00

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
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
341 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ken Maxwell 706 Reputation points Microsoft Employee
    2021-11-02T19:49:08.31+00:00

    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 additional answer

Sort by: Most helpful
  1. Ken Maxwell 706 Reputation points Microsoft Employee
    2021-11-01T20:58:34.883+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.