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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,4 @@ First public preview. The API is not stable yet.
- The library gives back the static IDs it makes. A panel `CreatePanel` made an ID for releases it when it closes: its tab, its window, its document, or a layout applied without it. `ClosePanel` closes a panel wherever it is, `ReleaseDockingLayout` closes a whole layout, and `CloseAllDocuments` closes a document set. `Cleanup` releases the application's own window IDs (menus, tooltips, pickers, toasts, popovers) and closes its torn-off panel windows. The showcase closes its documents at exit and holds no static ID when it's done.
- Fixed: closing a docked panel with Ctrl+W, Ctrl+F4 or its tab menu's Close no longer frees what it holds while that frame still draws it. A viewport's scene drawn that frame read freed memory. A closed panel leaves its layout at once, and its callbacks are destroyed when the next frame starts.
- Fixed: `FloatToHalf` lost the carry when rounding up past the largest mantissa, so 0.99995 became 0.5 and 65530 became 32768; it now carries into the exponent, and to infinity past the largest half. A gradient at an angle near an axis, whose rotation is packed this way, pointed the wrong way. `HalfToFloat` read subnormal halves as half their value.
- Fixed: two node views or tables with one shortcut mode (two panels of a kind) undid each other's mode, so the focused one's shortcuts could stop working while both were built. `ClaimCommandMode(owner, mode)` records a control's mode as it's built, and the mode is set once a frame, before input is handled, from where the focus is; Default once the focus is in none, unless the app set a mode of its own.
3 changes: 3 additions & 0 deletions docs/controls/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ tableState.contextMenu = [this](int row) {
Keyboard shortcuts that only work in the table: give it a `commandMode`.

- The mode is on while the focus is in the table, and Default again once the focus leaves.
- Two tables with one mode (two panels of a kind) don't undo each other: the mode is the
one the focus is in.
- Your own controls can do the same with `ClaimCommandMode(id, mode)`, called as they're built.
- Register the mode's commands once, with the `CommandManager`.
- For example, Delete deletes the selected rows.
- A key the table uses itself, such as the arrow keys, doesn't reach the commands.
Expand Down
42 changes: 42 additions & 0 deletions src/gui_controls/controls_docking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,50 @@ namespace tachyon
// m_dockingLayoutsThisFrame stays: onDragOut, run during input dispatch, reads it.
// BeginDockingFrame clears it.
}
void GUIApplication::ClaimCommandMode(ID owner, CommandMode mode)
{
if (owner == ID::Invalid() || mode == CommandMode::Default)
return;
m_commandModeClaims[owner] = { mode, m_commandModeFrame };
}

void GUIApplication::ApplyClaimedCommandMode()
{
// The claim the focus is in: the focused element's own, else one around it.
const InteractionState& interaction = guiStateManager.Interaction();
const ID focused = interaction.GetFocusedID();
std::optional<CommandMode> mode;
for (auto it = m_commandModeClaims.begin(); it != m_commandModeClaims.end(); )
{
const bool within = interaction.IsFocusWithin(it->first);
if (within && (!mode || it->first == focused))
mode = it->second.mode;
// Not built this frame, and not where the focus is: gone (a closed panel's).
if (!within && it->second.frame != m_commandModeFrame)
it = m_commandModeClaims.erase(it);
else
++it;
}
++m_commandModeFrame;

if (mode)
{
if (commandManager.GetMode() != *mode)
commandManager.SetMode(*mode);
m_claimedCommandMode = *mode;
}
else if (m_claimedCommandMode != CommandMode::Default)
{
// The focus left: Default again, unless the app set a mode of its own since.
if (commandManager.GetMode() == m_claimedCommandMode)
commandManager.SetMode(CommandMode::Default);
m_claimedCommandMode = CommandMode::Default;
}
}

void GUIApplication::DispatchInput(ID overID)
{
ApplyClaimedCommandMode();
// What the user acts on, taken before the handlers move the focus or the capture.
std::vector<ID> actedOn = ActedOnIDs(overID);
if (inputManager)
Expand Down
11 changes: 2 additions & 9 deletions src/gui_controls/controls_node_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,8 @@ namespace tachyon
view.state.transitionMenuTransition.reset();
}

// Edit-mode wiring: while this canvas has focus, set the command
// manager to the view's mode; restore Default when focus leaves.
if (guiStateManager.Interaction().GetFocusedID() == canvasID)
{
if (commandManager.GetMode() != view.state.commandMode)
commandManager.SetMode(view.state.commandMode);
} else
if (commandManager.GetMode() == view.state.commandMode)
commandManager.SetMode(CommandMode::Default);
// Its shortcuts while the focus is on the canvas.
ClaimCommandMode(canvasID, view.state.commandMode);

// ---- Canvas: pan/zoom + focus capture. Everything below renders as
// children of this element under the view's content transform.
Expand Down
13 changes: 2 additions & 11 deletions src/gui_controls/controls_table_virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,17 +1554,8 @@ namespace tachyon
m_tableEmit = std::move(m_outerTableEmits.back());
m_outerTableEmits.pop_back();

// Its shortcuts while the focus is in it; Default again once it leaves.
if (state.commandMode != CommandMode::Default)
{
if (guiStateManager.Interaction().IsFocusWithin(id))
{
if (commandManager.GetMode() != state.commandMode)
commandManager.SetMode(state.commandMode);
}
else if (commandManager.GetMode() == state.commandMode)
commandManager.SetMode(CommandMode::Default);
}
// Its shortcuts while the focus is in it.
ClaimCommandMode(id, state.commandMode);

// The context menu: a shown row's, for that row; the sections' bodies', below the rows.
if (state.contextMenu)
Expand Down
17 changes: 17 additions & 0 deletions src/gui_controls/gui_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ namespace tachyon

/// Closes the panel at `tabIndex` of a docked leaf, as the tab's Close action does.
void CloseDockedPanel(DockingLayout& layout, DockNode& leaf, int tabIndex);
/// For a control with shortcuts of its own (CommandManager::RegisterMode): while the
/// focus is within `owner`, the command mode is `mode`; once it's within none, Default
/// again. Call it as the control is built, every frame it is. The mode is set once a
/// frame, before input is handled, from where the focus is, so two controls of one mode
/// (two panels of a kind) don't undo each other. Default claims nothing.
void ClaimCommandMode(ID owner, CommandMode mode);

/// Closes a panel of `layout` for good, wherever it is: out of its tree (its leaf
/// closing up when it empties), hidden first (onDisable) if it's shown, its ID back when
/// CreatePanel made it. Its callbacks, and what they hold, are destroyed when the next
Expand Down Expand Up @@ -3073,6 +3080,13 @@ namespace tachyon
std::vector<DockingLayout*> m_dockingLayoutsThisFrame{};
/// Panels closed this frame, kept until the next one starts (ClosePanel).
std::vector<Panel> m_closedPanels;
/// The controls with a command mode of their own (ClaimCommandMode), by their ID, and
/// the frame each was last built in.
struct CommandModeClaim { CommandMode mode; uint64_t frame; };
std::unordered_map<ID, CommandModeClaim> m_commandModeClaims;
uint64_t m_commandModeFrame = 0;
/// The mode a claim set, while it holds; Default when none does.
CommandMode m_claimedCommandMode = CommandMode::Default;

/// Toolbar docks emitted this frame, walked by SyncToolbarDockRects (type in controls_toolbar_dock.h).
std::vector<struct ToolbarDockState*> m_toolbarDocksThisFrame{};
Expand Down Expand Up @@ -3386,6 +3400,9 @@ namespace tachyon
void ReleaseOwnIDs();
/// Destroys every panel of `layout`, as ClosePanel does each, leaving its tree.
void ErasePanels(DockingLayout& layout);
/// Sets the command mode from the claims (ClaimCommandMode) the focus is within, before
/// the frame's input is handled; drops claims no longer built that the focus isn't in.
void ApplyClaimedCommandMode();
/// Hands the frame's input to the element handlers, then calls onChanged of the docked
/// panels the user acted in.
void DispatchInput(ID overID);
Expand Down
15 changes: 15 additions & 0 deletions tests/node_view_two_views_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ namespace tachyon
EXPECT_NE(NodeRect(right, nodeA).position, rightBefore.position) << "the other view shows where it went";
}

// Two views with one shortcut mode: the mode is the focused view's, whichever of the two
// is built first, and it holds while the focus moves between them.
TEST_F(NodeViewTwoViewsTest, TheFocusedViewsShortcutModeHolds)
{
const CommandMode mode = app.commandManager.RegisterMode("Graph");
left.commandMode = right.commandMode = mode;
Settle();
app.ClickAt({ 600, 700 }); // the left view's empty canvas
Settle();
EXPECT_EQ(app.commandManager.GetMode(), mode) << "the left one focused, built before the right";
app.ClickAt({ 1400, 700 }); // the right one's
Settle();
EXPECT_EQ(app.commandManager.GetMode(), mode) << "the right one focused, built after the left";
}

// A node removed through one view goes from the other's selection on its next build,
// which reports the change.
TEST_F(NodeViewTwoViewsTest, ANodeRemovedInOneViewLeavesTheOthersSelection)
Expand Down
Loading