Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/splitter.h

Panes the user can resize, and the bar between them.

#include <sonore/gfx/splitter.h>
On this page

Design notes

What it is for

A sample browser down the left and the sample's detail on the right. A preset list above and its parameters below. The moment an editor has two regions whose right proportion depends on what the user is doing, a fixed split is wrong for somebody -- and the somebody is usually the one with a long preset name or a deep folder tree.

FlexBox already lays a row out. What it cannot do is let the USER move the boundary and have that survive the next resize, which is the whole of what this adds.

Sizes, and what a negative one means

The usual convention, because it is genuinely the clearest: a POSITIVE size is pixels, a NEGATIVE one is a fraction of the total. So (-0.25, -0.75, -0.5) is "between a quarter and three quarters, preferring half", and it stays that when the window is resized -- where a pixel preference would drift to nothing on a small editor and to a stripe on a large one.

The algorithm

The same freeze loop FlexBox uses, for the same reason: start everything at its preferred size, share the difference among the items that can still move, freeze whatever hits a limit, and go round again. The naive alternative -- distribute once, then clamp -- leaves the clamped items' share unspent, so a row of panes comes up short by exactly the amount its constrained members refused.

Types 2

Sizes a row or column of items between limits, and remembers where the user dragged the boundaries -- the reference's StretchableLayoutManager. The file comment gives the size convention (positive is pixels, negative a fraction of the total) and the algorithm.

Describe every item with setItemLayout -- the resizer bars too, as items of fixed size -- then call layOutComponents from the owner's resized(). A StretchableLayoutResizerBar moves a boundary through setBoundaryPosition and asks the owner to lay out again. A plain object, not a component: it owns no components and touches only the ones handed to layOutComponents.

class StretchableLayoutResizerBar : public Widget

The bar you drag.

It owns nothing and lays nothing out: it tells the manager where the boundary now is and asks its owner to lay out again. Which keeps the one piece of state -- where the split is -- in the manager, where the next resize will look for it.

↑↓ to move↵ to openEvery public name in the headers, and every guide