410 views
in GUI Development by

Hello there,

We have some blocks of text and we need to have each block with same width. Width should be set accoding by the longest text. Our solution has two components (cell and table). We use text property AutoSize: true and OnUpdate slot for getting real sizes of texts in cell component. Then we send signal to table component and table component find the longest cell. If we try to give correct width into cells via properties, it is not working and cells has its own sizes according size of its texts. The longest width is in table component stored as variable.

How we should trigger render of another cells?

Thank you for your feedback,

Jakub Jirgl

1 Answer

0 votes
by
 
Best answer
Hello Jakub,

without knowing your project it is difficult to say what is not working as expected. Can you isolate the behaviour in a small example project and upload it here?

Best regards

Paul Banach
by

Hello Jakub,

the cells seem to work - so far I understand what you try to achieve. When changing the text in a cell, the Text view as well as the surrounding cell component adjust their width automaticaly and a signal is sent to OnForceWidth. The new width seems to be correct also. Do you observe the same?

The problems begin when we try to adjust the width of all other cells. In this case the size of the respective cell as well as the embedded Text view is adjusted to the new width. The implementation is found in the method ForcedWidth:

The problem here is, the Text view is configured with AutoSize = true. It reacts thereupon to this size alternation (see the highlighted text row above) and after short delay (after reparsing the text again internally) it adjusts its size back to its actual text content. It also sends a signal to the associated OnTextUpdate slot method. This method again restores the size of the cell to match the actual content of the Text view. 

I think, this approach will not work unless you enable/disable the AutoSize depending on whether the cell should adjust its size its 'own' content or to the of other cells. This makes the implementation even more complex. 

What can you do? I would implement a layout algorithm which works in two steps and does not rely on the AutoSize property:

- In the first step: iterate over all strings you want to display in the table and for each string calculate its pixel width. Use the methods of the Resources::Font class for this purpose. The method GetTextAdvance() could be the adequate one for this application case.

- While you iterate over the strings track the max. width.

- In the second step: Once all strings are processed iterate again over the cells and adjust their Bounds properties to the estimated max. width. By the way you can also arrange the cells side by side, etc. depending on your desired layout.

Does it help you further?

Best regards

Paul Banach

by
Hello Paul,

yes I see a problem right now. Thank you very much for clarification. Your idea with 2 steps algorithm is great and it works great as well.

Thank you very much for your help.

Regards,

Jakub Jirgl

Embedded Wizard Website | Privacy Policy | Imprint

...