TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
  1. The app

The app class

The app class owns the panels, the window and the dock layout. The dock layout describes how the panels are arranged in the window. At the end of my_app.h:

class MyApp : public tachyon::GUIApplication
{
public:
tachyon::Result<void> Initialize(const InitializeOptions& options = {}) override;
void OnGUI() override;
CounterPanel counter;
GreetingPanel greeting;
private:
};
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
A docking area: the split/tab tree and the panels its leaves refer to by ID.
Definition gui_docking_types.h:125
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

Close the namespace with }.

Setting up once

Initialize runs once, after the library has started. In my_app.cpp:

tachyon::Result<void> MyApp::Initialize(const InitializeOptions& options)
{
if (tachyon::Result<void> result = GUIApplication::Initialize(options); !result)
return result;
// The window and the dock layout keep their state between frames, so they get
// IDs that stay the same: static IDs, made once.
m_windowID = idManager.CreateStaticID();
m_dockID = idManager.CreateStaticID();
const tachyon::ID left = CreatePanel(m_layout.panels, "Counter", noIcon, [this] { counter.Draw(*this); });
const tachyon::ID right = CreatePanel(m_layout.panels, "Greeting", noIcon, [this] { greeting.Draw(*this); });
tachyon::MakeLeaf({ left }),
tachyon::MakeLeaf({ right }));
return {};
}
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.
@ LeftPinned
horizontal split: first child (left) pinned, right flexes
Definition gui_dock_node.h:26
IconID
Handle for an icon registered with ITextSystem::RegisterIconFromSVG / RegisterIconFromSVGFile.
Definition gui_style_text.h:15
@ Invalid
Definition gui_style_text.h:15
  • The window and the dock layout remember their position, size and arrangement by ID.
    • So they need static IDs: IDs made once, which stay the same.
    • Call-site IDs, made from the file and line of a call, won't do here.
  • CreatePanel registers a dockable panel with a title and a draw callback.
  • The dock tree gives the counter a 240 px left column and the greeting the rest.
  • Users can drag tabs to rearrange the panels, or drag a tab out of the window to float its panel.

Every frame

void MyApp::OnGUI()
{
if (BeginWindow(m_windowID, "My app", theme.mainWindowStyleRef,
{
BeginDockingContainer(m_dockID, &m_layout, tachyon::LayoutOverride::Auto());
EndDockingContainer();
EmitFloatingDockWindows();
}
EndWindow();
}
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
static LayoutOverride Auto()
No overrides: everything comes from the style.
Definition gui_constraints.h:182
  • The docking container draws the visible panels through their callbacks.
  • EmitFloatingDockWindows draws the floated ones.

Close the namespace with }.

main

In main.cpp, after #include "my_app.h" and #include <cstdio>:

int main()
{
my_app::MyApp app;
tachyon::Result<void> result = app.Initialize();
if (result)
result = app.Run(); // until the last window closes
app.Cleanup();
if (!result)
{
std::fprintf(stderr, "%s\n", result.GetError().message.c_str());
return 1;
}
return 0;
}
const Error & GetError() const
The error; only valid when !HasValue().
Definition gui_result.h:61
std::string message
what went wrong, for logs and users
Definition gui_result.h:28

On failure, the Result<void> says why. For example, the GPU may be missing required features.

Run it

Build as in step 1, then run it from any folder:

  • build\Debug\my_app.exe on Windows
  • build/Debug/my_app on Linux and macOS

Where next

  • Controls: every control, its options and CSS class.
  • CSS and theming: your own style file, dark and light.
  • Overview: IDs, Begin and End, the frame.
  • Integration: your own Vulkan device, window backend or main loop.

Previous: 3. Fields | Tutorial