Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(fix) Context menus open at their full width instead of clipping both sides (#279)

Egor Khindikaynenca2d305eaf65
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b82e70cf..7e234629 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -120,6 +120,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
`scripts/perf-gate.sh develop` (Linux).
### Fixed
+- **Context menus are never cut off at the sides**: a menu whose longest item had no shortcut
+ (the track menu of a live-frozen track, with *Flatten (remove source)*) could open a little
+ too narrow, clipping every row on both sides. Every menu and submenu now opens at its full
+ width.
- **Chorus, Flanger, Lens and Phaser go into rack chains** (nota-daw/nota#203): they can be
dropped onto an Instrument Rack or Audio Effect Rack chain and are listed in its add-device
menu, like every other built-in audio effect.
diff --git a/src/managed/Nota.App/MenuItemsPanel.cs b/src/managed/Nota.App/MenuItemsPanel.cs
new file mode 100644
index 00000000..7f6517f1
--- /dev/null
+++ b/src/managed/Nota.App/MenuItemsPanel.cs
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// The items panel of every menu, flyout menu and submenu (NotaTheme.axaml). The Nota
+// MenuItem theme lines its columns up through shared-size groups (icon · label · value ·
+// shortcut · caret), and a Grid only learns its group's width after a layout pass ends
+// (SharedSizeState updates on LayoutUpdated). The first pass therefore saw each item alone,
+// and a menu whose widest label sits on an item without a shortcut or caret came out too
+// narrow; the native popup window takes its size from that first pass and does not grow
+// when the shared columns settle, so every row was centred in it and clipped on both
+// sides. This panel reports the settled width already on the first pass: the widest
+// "padding + label" of any item plus the widest of each shared column.
+
+using System;
+using System.Linq;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Presenters;
+using Avalonia.VisualTree;
+
+namespace Nota.App;
+
+public sealed class MenuItemsPanel : StackPanel
+{
+ private const int Columns = 5; // icon, label, trailing, shortcut, caret — NotaTheme.axaml
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ var size = base.MeasureOverride(availableSize);
+ Span<double> shared = stackalloc double[Columns], cols = stackalloc double[Columns];
+ double own = 0;
+ foreach (var child in Children)
+ {
+ if (child is not MenuItem { IsVisible: true } mi || ItemGrid(mi) is not { } grid) continue;
+ cols.Clear();
+ foreach (var part in grid.Children)
+ {
+ int c = Grid.GetColumn(part);
+ if (c >= 0 && c < Columns) cols[c] = Math.Max(cols[c], part.DesiredSize.Width);
+ }
+ for (int c = 0; c < Columns; c++) if (c != 1) shared[c] = Math.Max(shared[c], cols[c]);
+ // The item's own share: its padding and frame around the grid, plus the label.
+ own = Math.Max(own, mi.DesiredSize.Width - grid.DesiredSize.Width + cols[1]);
+ }
+ double width = own + shared[0] + shared[2] + shared[3] + shared[4];
+ if (width > size.Width) size = size.WithWidth(Math.Min(width, availableSize.Width));
+ return size;
+ }
+
+ // The column grid of an item in the Nota MenuItem template (an inline row has none).
+ private static Grid? ItemGrid(MenuItem mi)
+ => mi.GetVisualDescendants().OfType<ContentPresenter>().FirstOrDefault(p => p.Name == "PART_HeaderPresenter")?.Parent as Grid;
+}
diff --git a/src/managed/Nota.App/Theme/NotaTheme.axaml b/src/managed/Nota.App/Theme/NotaTheme.axaml
index 39839108..f960594b 100644
--- a/src/managed/Nota.App/Theme/NotaTheme.axaml
+++ b/src/managed/Nota.App/Theme/NotaTheme.axaml
@@ -81,6 +81,11 @@
<Setter Property="MinHeight" Value="24"/>
<Setter Property="Padding" Value="8,0"/>
<Setter Property="CornerRadius" Value="{StaticResource Radius.Clip}"/>
+ <!-- Every menu's items sit in MenuItemsPanel: it sizes the menu to its settled
+ columns on the first layout pass, so the popup never comes out too narrow. -->
+ <Setter Property="ItemsPanel">
+ <ItemsPanelTemplate><app:MenuItemsPanel/></ItemsPanelTemplate>
+ </Setter>
<Setter Property="Template">
<ControlTemplate>
<Panel>
@@ -1196,6 +1201,9 @@
<Setter Property="CornerRadius" Value="{StaticResource Radius.Control}"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="MinWidth" Value="200"/>
+ <Setter Property="ItemsPanel">
+ <ItemsPanelTemplate><app:MenuItemsPanel/></ItemsPanelTemplate>
+ </Setter>
</Style>
<!-- A menu carrying inline rows (colour grid, height keys): wide enough that they never
wrap, whatever the track's name (spec 034). -->
@@ -1224,6 +1232,9 @@
<Setter Property="CornerRadius" Value="{StaticResource Radius.Control}"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="MinWidth" Value="200"/>
+ <Setter Property="ItemsPanel">
+ <ItemsPanelTemplate><app:MenuItemsPanel/></ItemsPanelTemplate>
+ </Setter>
</Style>
<!-- Menu items take the Nota MenuItem theme (ControlTheme above); the danger and inline
diff --git a/tests/Nota.SmokeTest/DesignTokenCheck.Menus.cs b/tests/Nota.SmokeTest/DesignTokenCheck.Menus.cs
index 5b357220..e9498795 100644
--- a/tests/Nota.SmokeTest/DesignTokenCheck.Menus.cs
+++ b/tests/Nota.SmokeTest/DesignTokenCheck.Menus.cs
@@ -67,5 +67,20 @@ internal static partial class DesignTokenCheck
.Select(kv => $"{kv.Key} {kv.Value} → {counts.GetValueOrDefault(kv.Key)}").ToArray();
yield return (slack.Length == 0,
slack.Length == 0 ? "menu allow-list counts are tight" : $"menu allow-list above today's count (lower it): {string.Join(", ", slack.Take(8))}");
+
+ // Menus, flyout menus and submenus lay their items out in MenuItemsPanel, which sizes
+ // the native popup to the settled shared columns on the first pass (else the popup
+ // comes out too narrow and clips every row on both sides).
+ var theme = File.ReadAllText(Path.Combine(app, "Theme/NotaTheme.axaml"));
+ bool themed = new[] { "<Style Selector=\"MenuFlyoutPresenter\">", "<Style Selector=\"ContextMenu\">", "<ControlTheme x:Key=\"{x:Type MenuItem}\"" }
+ .All(open =>
+ {
+ int at = theme.IndexOf(open, StringComparison.Ordinal);
+ int end = at < 0 ? -1 : theme.IndexOf(open.StartsWith("<Style") ? "</Style>" : "<Setter Property=\"Template\">", at, StringComparison.Ordinal);
+ return end > at && theme.IndexOf("<app:MenuItemsPanel/>", at, end - at, StringComparison.Ordinal) >= 0;
+ });
+ yield return (themed,
+ themed ? "menus lay out in MenuItemsPanel (popup sized on the first pass)"
+ : "NotaTheme.axaml: MenuFlyoutPresenter, ContextMenu and the MenuItem theme set ItemsPanel to app:MenuItemsPanel");
}
}