Canvas widget resize/layout

I'm starting to write more custom widgets using the "canvas" widget. I have been finding that I need to do a lot of layout computation to figure out which subregions to draw, respond to touch, etc. Most of these computations are based on the width/height of the canvas and various properties of the widget.

Since there is no "onResize" scripting function, I am forced in both "onTouch" and "onDraw" to check if the widget size has changed and recompute the layout. My technique is to define a "computeLayout" function in "onCreate" which is stored as a local on the widget and then call that from onTouch or onCreate.

Is there a suggestion for a better way to handle this? My technique is kind of clumsy.

cheers,
Rob

I guess adding an onResize property would be a good thing then !

1 Like

I guess, ideally this would be called if any of the CSS vars or properties change since they could influence the layout as well? Maybe call it "onLayoutChange" or something like that?