/// <summary> /// Sets up a "homemade" toggle button in the toolbar. /// <para> /// sets the "inactive" class on all the toolbar's buttons, and sets the given tool as the active one if it isn't active, otherwise sets the active tool to none /// </para> /// </summary> void SetupToolButton(ToolbarButton button, Tools tool) { button.clickable.clicked += () => { Toolbar toolbar = rootVisualElement.Q <Toolbar>("toolbar"); foreach (VisualElement e in toolbar.Children()) { e.RemoveFromClassList("tool-active"); e.AddToClassList("tool-inactive"); } if (activeTool != tool) { button.AddToClassList("tool-active"); button.RemoveFromClassList("tool-inactive"); activeTool = tool; } else { activeTool = Tools.none; } }; }