diff --git a/ActionMenu.meta b/ActionMenu.meta new file mode 100644 index 0000000..d6ecfda --- /dev/null +++ b/ActionMenu.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8f2c47a1d5e34b0f9c6a2d8b1e4f7a30 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ActionMenu/ActionMenuDemo.cs b/ActionMenu/ActionMenuDemo.cs new file mode 100644 index 0000000..e2337a5 --- /dev/null +++ b/ActionMenu/ActionMenuDemo.cs @@ -0,0 +1,139 @@ +// Examples~/ActionMenu/ActionMenuDemo.cs +// Demonstrates: DropDownMenuControl, PillButton +// +// Scene setup: +// A scene for this example is provided. The demo grabs the UIDocument from the same +// GameObject via GetComponent(), so no manual assignment is needed. +// - Three content rows each expose a "···" overflow button; tapping it opens a +// DropDownMenuControl anchored to the button (AnchorRight) with View / Edit / +// Remove options. Remove really removes the row. +// - The "Card actions" PillButton opens the same menu centered on itself +// (CenteredOnAnchor) with card-level actions. +// - The status line reports the chosen action, or notes when a menu is +// dismissed by tapping the backdrop. + +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; + +namespace UnityUIToolkit.Extensions.Examples +{ + /// + /// Demonstrates opened from per-row overflow + /// buttons and from a centered card-level trigger. + /// + public class ActionMenuDemo : MonoBehaviour + { + private static readonly string[] ItemNames = + { + "Quarterly report.pdf", + "Team photo.png", + "Product roadmap.fig", + }; + + private const string IdleStatusText = "Open an item's ··· menu, or the card actions menu."; + + private UIDocument uiDocument; + // Constructed in Start — VisualElements must not be created from a MonoBehaviour + // constructor or field initializer. + private DropDownMenuControl actionMenu; + private VisualElement itemList; + private PillButton cardActionsButton; + private Label statusLabel; + + private void Start() + { + uiDocument = GetComponent(); + if (uiDocument == null) + { + Debug.LogError("ActionMenuDemo requires a UIDocument on the same GameObject.", this); + return; + } + + actionMenu = new DropDownMenuControl(); + + VisualElement root = uiDocument.rootVisualElement; + root.Clear(); + BuildUI(root); + } + + private void BuildUI(VisualElement root) + { + VisualElement screen = UIToolkitExtensions.CreateVisualElement(root, "actionMenuExample__screen"); + VisualElement card = UIToolkitExtensions.CreateVisualElement(screen, "actionMenuExample__card"); + + Label eyebrow = UIToolkitExtensions.CreateVisualElement