Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions CHANGELOG.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ if(TACHYON_INSTALL)

# gui_backend_default is an object library: its object file is installed, and a program
# that links it gets that file on its link line.
install(TARGETS gui_core gui_controls gui_dialogs ${TACHYON_BACKEND_TARGETS}
install(TARGETS gui_core gui_controls gui_dialogs gui_curves gui_color gui_views gui_nodes gui_docking ${TACHYON_BACKEND_TARGETS}
EXPORT TachyonUITargets
ARCHIVE DESTINATION "lib/$<CONFIG>"
OBJECTS DESTINATION "lib/$<CONFIG>/objects")
Expand All @@ -160,7 +160,7 @@ if(TACHYON_INSTALL)
if(NOT TACHYON_SDL)
list(APPEND _tachyon_header_excludes PATTERN "sdl" EXCLUDE)
endif()
install(DIRECTORY src/gui_core src/gui_controls src/gui_dialogs
install(DIRECTORY src/gui_core src/gui_controls src/gui_dialogs src/gui_curves src/gui_color src/gui_views src/gui_nodes src/gui_docking
DESTINATION include
FILES_MATCHING PATTERN "*.h"
${_tachyon_header_excludes})
Expand All @@ -169,7 +169,7 @@ if(TACHYON_INSTALL)

install(FILES LICENSE THIRD_PARTY_NOTICES.txt DESTINATION share/TachyonUI)

set(_tachyon_resource_excludes PATTERN showcase.css EXCLUDE)
set(_tachyon_resource_excludes PATTERN showcase.css EXCLUDE PATTERN app_controls.css EXCLUDE)
if(NOT TACHYON_FALLBACK_FONTS)
list(APPEND _tachyon_resource_excludes PATTERN Noto-otf EXCLUDE)
endif()
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ target_link_libraries(my_app PRIVATE TachyonUI::gui_controls TachyonUI::gui_back
```

`gui_backend_default` brings in the graphics and window backends; an app with backends of its
own leaves it out. The shaders, default themes and fonts are built into the libraries and SDL
own leaves it out. The controls beyond the basic ones are libraries of their own, linked when
used: `gui_views` (lists, trees, grids, tables), `gui_docking` (docked panels and documents),
`gui_nodes` (the node view), `gui_color`, `gui_curves` and `gui_dialogs`. The shaders, default themes and fonts are built into the libraries and SDL
is linked statically, so there are no extra files or DLLs to ship. Packaging, subprojects, your own
themes and system libraries are covered in [docs/integration.md](docs/integration.md).

Expand Down
5 changes: 5 additions & 0 deletions cmake/TachyonUIConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# Provides:
# TachyonUI::gui_core, TachyonUI::gui_controls static libraries: the UI, with no backend
# TachyonUI::gui_dialogs message dialogs, toasts, banners and progress
# TachyonUI::gui_curves curve fields, the curve editor and plots
# TachyonUI::gui_color color and gradient fields, their pickers, shadow fields
# TachyonUI::gui_views list, tree and grid views, tables, the settings panel
# TachyonUI::gui_nodes the node view and state machines
# TachyonUI::gui_docking docked and floating panels, documents, layout presets
# TachyonUI::gui_backend_default the backends the package has, registered
# before main (link it directly)
# TachyonUI::gui_backend_vulkan, _d3d12, _sdlgpu, each backend on its own, for an app that
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PROJECT_NUMBER = $(TACHYON_VERSION)
PROJECT_BRIEF = "High-performance UI for building tools."
PROJECT_LOGO = docs/doxygen/logo.svg
OUTPUT_DIRECTORY = $(DOXYGEN_OUTPUT)
INPUT = src/gui_core src/gui_controls src/gui_dialogs docs
INPUT = src/gui_core src/gui_controls src/gui_dialogs src/gui_curves src/gui_color src/gui_views src/gui_nodes src/gui_docking docs
RECURSIVE = YES
FILE_PATTERNS = *.h *.md *.dox
EXCLUDE = docs/design docs/doxygen docs/contributing
Expand Down
109 changes: 78 additions & 31 deletions docs/contributing/writing-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,15 @@ For a control that opens a popup, such as a list, a picker or a menu:
const auto trackRef = RegisterControl(std::move(track), std::move(constraints).FlexGrow(1));
```

- [ ] In a node row, a field fills the row like the others. `nodeRowFieldMinWidth` is set
while a node row is drawn.
- [ ] In a row that fills, a field fills the row like the others. The node view sets
`SetFieldRowFill` while it draws a node's property row.

For example, in `Field`:

```cpp
// Inside a node row, fill the body after the label so the node stays grid-aligned.
if (nodeRowFieldMinWidth > 0 && !constraints.HasFixedWidth())
constraints.FlexGrow(1).MinWidth(Pixels{ nodeRowFieldMinWidth });
// In a row that fills (SetFieldRowFill), fill the body after the label.
if (m_fieldRowFill > 0 && !constraints.HasFixedWidth())
constraints.FlexGrow(1).MinWidth(Pixels{ m_fieldRowFill });
```

**Frame and cache**
Expand Down Expand Up @@ -972,53 +972,100 @@ A pen on a tablet or pen display drives the pointer as a mouse does.

## Controls outside GUIApplication

A library of controls on top of `gui_controls` (such as `gui_dialogs`), or an app's own,
can't add members to `GUIApplication`. Its controls are free functions that take the app.
A library of controls on top of `gui_controls` (such as `gui_views` or `gui_dialogs`), or an
app's own, can't add members to `GUIApplication`. Its controls are free functions in a namespace of its
own, and they take the app.

- The app comes first; the rest is as a member control's would be:
- The app comes first, then the library's context; the rest is as a member control's
would be:

```cpp
void Rating(GUIApplication& app, ID id, int& stars, LayoutOverride&& constraints = {});
ratings::Rating(*this, ratingContext, ratingID, stars); // in your app class
```

- What it keeps from frame to frame, and its styles, live in an `AppExtension`
(`gui_controls/gui_app_extension.h`): one per app, made the first time
`app.Extension<T>()` asks for it, kept until `Cleanup`.
- What it keeps from frame to frame, and its styles, are a plain struct the app owns and
passes to each of its controls: a context. The library knows nothing of where it's kept.
- What has to happen once a frame, or at cleanup, are functions the app calls itself, at
the right point: the end of `OnGUI`, before its own `Cleanup`.

```cpp
class Ratings : public AppExtension
namespace ratings
{
public:
explicit Ratings(GUIApplication& app) : AppExtension(app) {}
void OnStylesLoaded() override { starStyle = app.theme.GetStyle("rating-star"); }
StyleRef starStyle{};
};
struct Context
{
StyleRef starStyle{};
uint32_t stylesGeneration = 0;
};

void Rating(GUIApplication& app, Context& context, ID id, int& stars, LayoutOverride&& constraints = {});
void EndGUI(GUIApplication& app, Context& context); // last in OnGUI
void Cleanup(GUIApplication& app, Context& context); // before GUIApplication::Cleanup
}
```

- Styles come from the theme by their CSS classes. A theme load clears every `StyleRef`, so
look them up again when `app.StylesGeneration()` changes:

void Rating(GUIApplication& app, ID id, int& stars, LayoutOverride&& constraints)
```cpp
if (context.stylesGeneration != app.StylesGeneration())
{
Ratings& ratings = app.Extension<Ratings>();
app.BeginHorizontal(id, std::move(constraints));
...
context.starStyle = app.theme.GetStyle("rating-star");
context.stylesGeneration = app.StylesGeneration();
}
```

- Its hooks run with the app, in the order the extensions were made:
- `OnStylesLoaded`: after each theme load, which clears every `StyleRef`; look the
extension's styles up here by their CSS classes
- `OnPostConstruct`: every element of the frame is declared, before layout
- `OnEndFrame`: drop the state of controls no longer built
- `OnCleanup`: give back static IDs and close windows, before the extension is destroyed
- A lambda that runs later (an event handler, a post-layout callback) captures `&app` and
gets the extension again inside, rather than holding on to it.
- A lambda that runs later (an event handler, a post-layout callback) holds a pointer to
the context, which lives as long as the app.
- `std::function` keeps what a lambda holds inline up to 48 bytes (MSVC); beyond that, it
allocates. For a handler made for every row or node each frame, keep its captures small:
a reference to the context, and values, rather than a reference to each part of it.
- Work at points of the frame `OnGUI` doesn't reach (before the frame is built, after its
input, before a theme reload clears the styles) is registered once, after `Initialize`,
with the hooks the app offers. `docking::Install` does it this way:

```cpp
app.OnFrameStage(FrameStage::PreConstruct, [&app, &context] { BeginFrame(app, context); });
app.OnInputDispatched([&app, &context](std::span<const ID> actedOn) { ReportChangedPanels(app, context, actedOn); });
app.OnBeforeStylesCleared([&app, &context] {
for (DockingLayout* layout : context.layoutsThisFrame)
if (layout) DisableAllPanels(app, context, *layout);
});
```

- A hook holds the context by reference, so the context can't move: delete its copy
constructor.
- Cleanup stays a function the app calls: `GUIApplication`'s destructor may run its
`Cleanup` after the app's own members are gone.
- What it keeps in the saved UI state goes through `PersistJson`: what its `save` function
gives is kept under a section and a key, and `RestoreUIState` hands it to its `restore`
function. `views::PersistTable` is built on it.
- What a control inside `GUIApplication` uses that isn't otherwise public is in the
Extensions group of `gui_application.h`:
"For controls outside GUIApplication" group of `gui_application.h`:
- `ScheduleFrameAt`: a frame at a later time, for a control that changes by itself
- `CloseOnPressOutside`: a popover that closes on a press elsewhere
- `RetireWindow`: close a popup window whose state went
- `AppColorStyle`: a color style of the control's own, for a color the app gives
- `ButtonGroupItemStyle` and `NoteButtonGroupItem`: a button of its own inside
`BeginButtonGroup`
- `LastStatusBar`: where a window's status bar is
- `StylesGeneration`: when to look the styles up again
- `ReportMisuse`: an End without its Begin, and the like
- `RegisterTabStop`: a control in the Tab order
- `TitleBarCaption`: a strip in the title bar that drags the window
- `ClaimCommandMode`: the command mode while the focus is in the control
- `RebuildCachedScopesAbove`: a cached scope around the control built again
- `ContextMenuScreenPos`: where the context menu opening was asked for
- `PendingLabelText`: the label just before the control, for a popup's title
- `BeginFieldBox` and `EndFieldBox`: a field with a caption or a unit
- `SetFieldRowFill`: fields that fill their row (a node's property row)
- `ClaimSwatchStyle`, `NoteSwatchClaim` and `ReplayedSwatches`: color swatches
- `CollectPropagatedAncestors`: the elements around one that show its state
- `ReorderDrag`, `CurrentTabBar`, `CurrentTab` and `CurrentWindowID`: the drag and the
tab bar, tab and window being built
- `OnFrameStage`, `OnInputDispatched` and `OnBeforeStylesCleared`: the hooks above
- `PersistJson`, `SaveWindowPlace`, `ReadWindowPlace` and `RestoreWindowPlace`: saved UI state
- In `GUITheme`: `VariableColor`, a theme color looked up again after each load, and
`RegisterDropdownParts`, a dropdown trigger's text and arrow parts.

## Decide for each control

Expand Down
61 changes: 39 additions & 22 deletions docs/controls.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Controls

Every control is a member function of `tachyon::GUIApplication`. Your application is a
subclass of it and builds its whole UI again each frame, in `OnGUI()`. The examples on
these pages are written as if inside that `OnGUI()`, with `using namespace tachyon;`.
Your application is a subclass of `tachyon::GUIApplication` and builds its whole UI again
each frame, in `OnGUI()`. The examples on these pages are written as if inside that
`OnGUI()`, with `using namespace tachyon;`.

- The basic controls (windows, buttons, fields, menus, tab bars, toolbars and more) are
member functions of `GUIApplication`, in `gui_controls`.
- The others are in libraries of their own, built on `gui_controls`:
- each library has a namespace: `views`, `nodes`, `docking`, `color`, `curves`, `dialogs`
- its controls are free functions that take the app first, then a context your app owns
(a member of your app class), for example `views::Cell(*this, viewsContext, name)`
- link its target and include its header: `TachyonUI::gui_views` and
`<gui_views/gui_views.h>`, say
- each page says what its controls need: some libraries want a call at the end of
`OnGUI` or before `Cleanup`

```cpp
class MyApp : public tachyon::GUIApplication
Expand All @@ -23,29 +34,35 @@ public:
Read [Common conventions](controls/conventions.md) first: it explains the parameters and
results all controls share.

| Page | Library | Covers |
| --- | --- | --- |
| [Common conventions](controls/conventions.md) | | Parameter order, return values, callbacks, `LayoutOverride`, state scopes |
| [Windows and layout](controls/windows-and-layout.md) | `gui_controls` | Windows, horizontal and vertical groups, areas, scroll bars, caching, label and button groups, `Segmented` |
| [Text and images](controls/text-and-images.md) | `gui_controls` | `Text`, `Label`, `DragLabel`, `SelectableText`, `Image` |
| [Buttons and toggles](controls/buttons-and-toggles.md) | `gui_controls` | `Button`, `CommandButton`, `Toggle`, `Switch`, `Checkbox` |
| [Fields](controls/fields.md) | `gui_controls`; the shadow field `gui_color` | Text, search, numeric, vector and typed fields, edge, corner and shadow fields, dropdowns, lists, dictionaries |
| [Sliders](controls/sliders.md) | `gui_controls` | `SliderField`, `Slider`, `RangeField` |
| [Color and gradient fields](controls/color-and-gradient.md) | `gui_color` | `ColorField`, `GradientField` and their pickers |
| [Curves](controls/curves.md) | `gui_curves` | `CurveField` and its curve editor, `EvaluateCurve` |
| [Plots](controls/plots.md) | `gui_curves` | `Plot`: histograms and other series, with handles (Levels) |
| [Menus](controls/menus.md) | `gui_controls` | Menus, menu items, menu bar, title bar, context menus |
| [Tooltips and message dialogs](controls/tooltips-and-dialogs.md) | `gui_controls`; message dialogs `gui_dialogs` | Tooltips, modal `MessageDialog` |
| [Lists and reorderable groups](controls/lists.md) | `gui_views`; reorderable groups `gui_controls` | List views, drag-to-reorder groups |
| [Tables](controls/tables.md) | `gui_views` | Tables, virtual tables, tree cells |
| [Tree and grid views](controls/trees-and-grids.md) | `gui_views` | `VirtualTreeView`, grid views, virtual grid views |
| [Tabs, docking and toolbars](controls/tabs-docking-toolbars.md) | `gui_controls`; docking `gui_docking` | Tab bars, docking containers, toolbars, toolbar dock |
| [Node view](controls/node-view.md) | `gui_nodes` | `RenderNodeView` node graph editor |
| [Other controls](controls/other-controls.md) | `gui_controls`; progress and toasts `gui_dialogs`, the settings panel `gui_views` | Breadcrumb, status bar, progress bars, spinners and skeletons, task progress and background tasks, command search, settings panel |
| [Custom drawing](controls/custom-drawing.md) | `gui_controls` | Drawing shapes and text inside an element |
| [Default CSS classes](controls/css-classes.md) | | Each control's class when you pass no style |

Two more controls are example code rather than the library. They're in `examples/app_controls`,
and show how an app writes controls of its own; copy them, or use them as a model:

| Page | Covers |
| --- | --- |
| [Common conventions](controls/conventions.md) | Parameter order, return values, callbacks, `LayoutOverride`, state scopes |
| [Windows and layout](controls/windows-and-layout.md) | Windows, horizontal and vertical groups, areas, scroll bars, caching, label and button groups, `Segmented` |
| [Text and images](controls/text-and-images.md) | `Text`, `Label`, `DragLabel`, `SelectableText`, `Image` |
| [Buttons and toggles](controls/buttons-and-toggles.md) | `Button`, `CommandButton`, `Toggle`, `Switch`, `Checkbox` |
| [Fields](controls/fields.md) | Text, search, numeric, vector and typed fields, edge, corner and shadow fields, dropdowns, lists, dictionaries |
| [Sliders](controls/sliders.md) | `SliderField`, `Slider`, `RangeField` |
| [Color and gradient fields](controls/color-and-gradient.md) | `ColorField`, `GradientField` and their pickers |
| [Curves](controls/curves.md) | `CurveField` and its curve editor, `EvaluateCurve` |
| [Plots](controls/plots.md) | `Plot`: histograms and other series, with handles (Levels) |
| [Viewport](controls/viewport.md) | `Viewport`: your 3D scene, its camera, and gizmos to move, rotate and scale |
| [Menus](controls/menus.md) | Menus, menu items, menu bar, title bar, context menus |
| [Tooltips and message dialogs](controls/tooltips-and-dialogs.md) | Tooltips, modal `MessageDialog` |
| [Lists and reorderable groups](controls/lists.md) | List views, drag-to-reorder groups |
| [Tables](controls/tables.md) | Tables, virtual tables, tree cells |
| [Tree and grid views](controls/trees-and-grids.md) | `VirtualTreeView`, grid views, virtual grid views |
| [Tabs, docking and toolbars](controls/tabs-docking-toolbars.md) | Tab bars, docking containers, toolbars, toolbar dock |
| [Node view](controls/node-view.md) | `RenderNodeView` node graph editor |
| [Timeline](controls/timeline.md) | `Timeline` playback row, `TimelineEditor` animation editor, `AdvanceTimeline` |
| [Other controls](controls/other-controls.md) | Breadcrumb, status bar, progress bars, spinners and skeletons, task progress and background tasks, command search, settings panel |
| [Custom drawing](controls/custom-drawing.md) | Drawing shapes and text inside an element |
| [Default CSS classes](controls/css-classes.md) | Each control's class when you pass no style |

<!--!
\htmlonly <div class="page-tree"> \endhtmlonly
Expand Down
9 changes: 5 additions & 4 deletions docs/controls/buttons-and-toggles.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ EndHorizontal();

A button that can show it's at work, for example while a save runs.

- It's in the dialogs library, with the other progress controls: link
`TachyonUI::gui_dialogs`, include `<gui_dialogs/gui_dialogs.h>`, and pass the app first.
- It's in the dialogs library, with the other progress controls: `dialogs::BusyButton`,
with the app and a `dialogs::Context` first. See
[Message dialogs](tooltips-and-dialogs.md#message-dialogs) for the setup.
- While `busy` is `false` it's an ordinary [Button](#button).
- While `busy` is `true`:
- a turning spinner takes the place of its icon
Expand All @@ -70,15 +71,15 @@ A button that can show it's at work, for example while a save runs.
- it returns `false`

```cpp
bool BusyButton(GUIApplication& app, ID id, const GUIContent& content, bool busy, std::string_view busyText,
bool dialogs::BusyButton(GUIApplication& app, Context& context, ID id, const GUIContent& content, bool busy, std::string_view busyText,
std::function<void()> onClick, StyleRef style, LayoutOverride&& constraints = {});
```

You decide when it's busy, so pass a flag your own work sets and clears:

```cpp
// member: bool saving
BusyButton(*this, saveID, { saveIcon, "Save" }, saving, "Saving...", [this] { saving = true; StartSave(); });
dialogs::BusyButton(*this, dialogContext, saveID, { saveIcon, "Save" }, saving, "Saving...", [this] { saving = true; StartSave(); });
```

```cpp
Expand Down
Loading
Loading