in GUI Development by

I think I have found a bug that occurs when using AutoSize on a text-view. The reported text area, i.e. Text.GetExtent(), is not updated with the new size. It does however update if certain functions, e.g. Text.GetWidestRow() are called.

1 Answer

0 votes

Hello Måns,

I don't think it is a bug. This is a peculiarity of how views are updated. The method GetExtent() provides a common technique to query the size/position of the corresponding view regardless of the type of the view. When a Text view is configured to AutoSize its own Bounds according to its changing content, this adjustment is not performed immediately. For optimization purpose the update is performed with a delay accumulating multiple property alternations of the view. Until such pending update is not performed, the view retains its old size and position. The method GetExtent() returns the current value.

Better for your application case would be to use the Text view's method GetContentArea(). See also the section Arrange other views on the content of the Text view. Unlike the common GetExtent() method, GetContentArea() enforces the update if it is not yet performed. It ensures that the returned value is correct.

Also, when you intention is to automatically layout multiple views on the area occupied by the Text view, I would recommend to implement this layout logic in a slot method associated to the Text view's property OnUpdate. See the above mentioned documentation section. It explains the usage of OnUpdate to arrange decorations around the Text view.

In turn, if all you want is to estimate the area needed to display some text, you can also use the method of the Resources::Font class. For example, with the method GetTextExtent() and GetTextAdvance() you can calculate the area or the width (the advance) of a text fragment when it is displayed using the font.

I hope it helps you further.

Best regards

Paul Banach



Embedded Wizard Website | Privacy Policy | Imprint