TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
docking/docking.cpp

Panels in a dock layout that the user can rearrange, tear off and dock again.

Panels in a dock layout that the user can rearrange, tear off and dock again.Walkthrough: Docking.

// Docking: a few panels in a dock layout. Drag a tab to move a panel, onto
// another leaf to dock it there, or outside the window to float it.
#include <cstdio>
#include <string>
class DockingApp : public tachyon::GUIApplication
{
public:
tachyon::Result<void> Initialize(const InitializeOptions& options = {}) override
{
if (tachyon::Result<void> result = GUIApplication::Initialize(options); !result)
return result;
windowID = idManager.CreateStaticID();
dockID = idManager.CreateStaticID();
// Panels are created once; each draws its content in its callback.
const tachyon::ID scene = CreatePanel(layout.panels, "Scene", noIcon, [this] { ScenePanel(); });
const tachyon::ID details = CreatePanel(layout.panels, "Details", noIcon, [this] { DetailsPanel(); });
const tachyon::ID log = CreatePanel(layout.panels, "Log", noIcon, [this] { Text("Nothing logged yet."); });
const tachyon::ID help = CreatePanel(layout.panels, "Help", noIcon, [this] { Text("Drag the tabs around."); });
// Left column of 220 px, the rest split over a 150 px bottom row.
layout.root = tachyon::MakeSplit(DockSplitMode::LeftPinned, 220,
tachyon::MakeLeaf({ scene }),
tachyon::MakeSplit(DockSplitMode::BottomPinned, 150,
tachyon::MakeLeaf({ details, help }),
tachyon::MakeLeaf({ log })));
return {};
}
void OnGUI() override
{
if (BeginWindow(windowID, "Docking", theme.mainWindowStyleRef, tachyon::LayoutOverride::FixedSize(900, 600).Centered()))
{
BeginDockingContainer(dockID, &layout, tachyon::LayoutOverride::Auto());
EndDockingContainer();
// Panels dragged out of the window get their own OS windows, owned by this one.
EmitFloatingDockWindows();
}
EndWindow();
}
private:
void ScenePanel()
{
for (int i = 0; i < 4; ++i)
Button("Object " + std::to_string(i), [this, i] { selected = i; }, tachyon::LayoutOverride{}.NoGrow());
}
void DetailsPanel()
{
Text("Selected object " + std::to_string(selected));
BeginLabelGroup();
DragLabel("Scale");
Field(scale);
EndLabelGroup();
}
int selected = 0;
float scale = 1.0f;
};
int main()
{
DockingApp app;
tachyon::Result<void> result = app.Initialize();
if (result)
result = app.Run();
app.Cleanup();
if (!result)
{
std::fprintf(stderr, "%s\n", result.GetError().message.c_str());
return 1;
}
return 0;
}
The application: owns the windows, the systems and the frame loop.
Definition gui_application.h:185
A value, or the Error saying why there is none.
Definition gui_result.h:36
const Error & GetError() const
The error; only valid when !HasValue().
Definition gui_result.h:61
std::unique_ptr< DockNode > MakeLeaf(std::initializer_list< ID > panelIds={})
A leaf with the given panel tabs.
std::unique_ptr< DockNode > MakeSplit(DockSplitMode mode, CssPx splitSize, std::unique_ptr< DockNode > first, std::unique_ptr< DockNode > second, CssPx minFirstSize=80, CssPx minSecondSize=80)
A split node owning first and second; sizes in CSS px.
DockSplitMode
Split direction and which child is pinned to splitSize; the other child flexes.
Definition gui_dock_node.h:25
IconID
Handle for an icon registered with ITextSystem::RegisterIconFromSVG / RegisterIconFromSVGFile.
Definition gui_style_text.h:15
@ Invalid
Definition gui_style_text.h:15
A docking area: the split/tab tree and the panels its leaves refer to by ID.
Definition gui_docking_types.h:125
std::string message
what went wrong, for logs and users
Definition gui_result.h:28
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
Per-element overrides of style layout properties.
Definition gui_constraints.h:150
LayoutOverride & Centered() &
Centered in the parent on both axes.
Definition gui_constraints.h:259
static LayoutOverride FixedSize(CssPx w, CssPx h)
Sizes in CSS px (scaled by the UI scale) or in Pixels (as they are); see gui_units....
Definition gui_constraints.h:184
LayoutOverride & NoGrow() &
Shorthands for FlexGrow(0) / FlexShrink(0).
Definition gui_constraints.h:322
static LayoutOverride Auto()
No overrides: everything comes from the style.
Definition gui_constraints.h:182