WxWidgets Sizers

Hello, Habr!



Today I want to talk a little about my experience with using sizers in wxWidgets.



I spent my entire conscious 'life' in C ++ in the C ++ Builder environment with rare attacks in Misrosoft VC. In search of something new, I decided to try a bunch of CodeBlocks and wxWidgets. And he immediately caught nostalgia for the greenhouse environment of C ++ Builder with its 'live' visual forms in the constructor. First of all, I did not get a mutual understanding with wxSizers. Their subset and behavior undermined the whole optimism of developing a new environment for me. And here the idea came up to write something of my own for wxWidgets, so that it would be like in C ++ Builder.



The result was wxFreeStyleSizer, named for lack of imagination and time.

I tried to make the behavior style of this sizer as close as possible to the behavior of forms and components in C ++ Builder (Delphi).



The Align mechanism is implemented - panels and controls (form elements) can stretch along one of the sides of the form, or stretch to the entire form. A lot of controls can stack up in the right position. Priority of placement of controls: top + bottom / left + right / for the whole form.



Here is an example of such a panel layout:



image



Anchors mechanism has been implemented - the position of the control side is fixed at a certain distance from the edge of the form. Depending on which of the sides are fixed, it is possible to obtain different models of control behavior when changing the size of the form. For example, fixing the left and right sides of the control we get stretching / compression of the control when changing the size of the form.



Original size of controls:



image



Dimensions after stretching:



image



The Splitter mechanism is implemented - the sizes and position of the sides of the control can be changed by the user using the computer mouse. An example of applying this option to two panels:



image



An example of resizing (dragging and dropping a splitter) between two panels:



image



It should also be noted that all of the above is implemented on one element of the sizer, one panel - one sizer on it.



As a disclaimer, I must say that the code is written in CodeBlocks in the Windows environment (GNU GCC, C ++ 11, wxWidgets 3.1.2) for personal purposes. If anyone has a desire to familiarize themselves with the source, Welcome .



Thanks for attention.



All Articles