How can I write a custom Container in gtk-rs for GTK-3? I use gtk-rs 0.15.0 (to be compatible with the last GTK-3 compatible version of webkit2gtk). I couldn't find any reasonable documentation.
Reason behind this: I use a horizontally aligned Box layout, where I want a left component take roughly 2/3 window-width and the remainder component 1/3. "Roughly" meaning: In detail it's more complicated, but setting the sizes manually, also with hexpand set to false, leads to "wobbling" sizes, conflicting with the constantly changing contents sizes, all in all shaky behavior. Writing a custom container seems to be the cleanest way.
Is there any example code / project (e.g. GitHub ?) where a custom Container was written in gtk-rs for GTK-3?
There's no need to write a custom container; to do what you described, you can simply use
Grid.Using
GridAs you probably know, the
Gridcontainer is made up of rows and columns. A single widget can take up multiple rows and columns. Thus, if you want one widget to span 2/3 of the window and the other to span 1/3 of it, you can use three columns of aGrid, and make the first widget cover two columns while the second widget covers just one.In order to do this, you use the
widthandheightarguments ofGrid.attach(). For example, this widget will span two columns:Now in order for the column proportions to be correct, you also need to set the columns homogeneous:
The same principles can be applied to rows too.
Example
All that being said, here is a simple working example with a
Buttonand anEntry. TheButton(on the left) takes up 2/3 of the width of the window, while theEntry(on the right) takes up only 1/3.