Skip to content

Compare

compare · Containers · interactive

Two things in the same rectangle, with a handle that says how much of each.

Import

cpp
#include "gbui/widgets/compare.hpp"

Example

Nothing is downloaded until you press it.

cpp
CompareResult compare(Ui& ui, const Interaction& input, std::string_view id, float position, const std::function<void(Ui&)>& before, const std::function<void(Ui&)>& after, const CompareOptions& options = {});

Draws before under after, with after revealed from the leading edge up to position. Both callbacks are built at the full size of the box and both are built every frame — that is what makes the two comparable, and it is also why they should be cheap: this is a picture against a picture, not two dashboards.

API

CompareOptions

OptionTypeDefaultWhat it does
orientationCompareOrientation
Horizontal · Vertical
CompareOrientation::HorizontalWhich way the seam travels. Horizontal for two pictures, vertical for two things read top to bottom — a chart against its own baseline.
slideOnHoverboolfalseThe handle follows the pointer without anything being pressed. Off, because a comparison is something a reader sets and then looks at, and a seam that moves whenever the pointer crosses the picture cannot be left anywhere. On for a gallery of thumbnails where the gesture is the whole interaction and there is nothing to leave it at.
handleWidthfloat3.0fHow wide the bar down the seam is. The grip on it is drawn from this.
namestd::string_viewWhat is being compared — "Before and after retouching".
beforeLabelstd::string_viewWhat each side is. Announced with the value, because "60 percent" says nothing on its own: sixty percent of what, revealing what. A reader who cannot see either picture has only these two words to tell them which way the handle is moving them.
afterLabelstd::string_viewAs above, for the side the handle reveals — and the one the value is announced in terms of, since that is the one moving.
heightfloat240.0f
widthfloatkAuto
growfloat0.0f

Released under the LGPL-3.0-or-later licence.