handle button toggling

This commit is contained in:
Matt Parker
2025-08-27 21:05:35 +10:00
parent c1dbaf4627
commit e26e9dbd9f
5 changed files with 18 additions and 11 deletions

View File

@@ -9,7 +9,6 @@ public partial class BottomPanelManager : Panel
private Control _problemsPanel = null!; private Control _problemsPanel = null!;
private Dictionary<BottomPanelType, Control> _panelTypeMap = []; private Dictionary<BottomPanelType, Control> _panelTypeMap = [];
private BottomPanelType? _currentPanelType = BottomPanelType.Run;
public override void _Ready() public override void _Ready()
{ {
@@ -23,16 +22,15 @@ public partial class BottomPanelManager : Panel
{ BottomPanelType.Problems, _problemsPanel } { BottomPanelType.Problems, _problemsPanel }
}; };
GodotGlobalEvents.LeftSideBarButtonClicked += OnLeftSideBarButtonClicked; GodotGlobalEvents.BottomPanelTabSelected += OnBottomPanelTabSelected;
} }
private async Task OnLeftSideBarButtonClicked(BottomPanelType type) private async Task OnBottomPanelTabSelected(BottomPanelType? type)
{ {
await this.InvokeAsync(() => await this.InvokeAsync(() =>
{ {
if (type == _currentPanelType) if (type == null)
{ {
_currentPanelType = null;
// TODO: Ask parent to to collapse slider. // TODO: Ask parent to to collapse slider.
} }
foreach (var kvp in _panelTypeMap) foreach (var kvp in _panelTypeMap)

View File

@@ -0,0 +1,4 @@
[gd_resource type="ButtonGroup" format=3 uid="uid://c2nmo2x3va0gi"]
[resource]
allow_unpress = true

View File

@@ -5,6 +5,7 @@ namespace SharpIDE.Godot.Features.LeftSideBar;
public partial class LeftSideBar : Panel public partial class LeftSideBar : Panel
{ {
private Button _slnExplorerButton = null!; private Button _slnExplorerButton = null!;
// These are in a ButtonGroup, which handles mutual exclusivity of being toggled on
private Button _problemsButton = null!; private Button _problemsButton = null!;
private Button _runButton = null!; private Button _runButton = null!;
private Button _buildButton = null!; private Button _buildButton = null!;
@@ -16,8 +17,8 @@ public partial class LeftSideBar : Panel
_runButton = GetNode<Button>("%RunButton"); _runButton = GetNode<Button>("%RunButton");
_buildButton = GetNode<Button>("%BuildButton"); _buildButton = GetNode<Button>("%BuildButton");
_problemsButton.Pressed += () => GodotGlobalEvents.InvokeLeftSideBarButtonClicked(BottomPanelType.Problems); _problemsButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Problems : null);
_runButton.Pressed += () => GodotGlobalEvents.InvokeLeftSideBarButtonClicked(BottomPanelType.Run); _runButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Run : null);
_buildButton.Pressed += () => GodotGlobalEvents.InvokeLeftSideBarButtonClicked(BottomPanelType.Build); _buildButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Build : null);
} }
} }

View File

@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://biyhfwx36ium8"] [gd_scene load_steps=4 format=3 uid="uid://biyhfwx36ium8"]
[ext_resource type="Texture2D" uid="uid://bkty6563cthj8" path="res://Features/Run/Resources/Run.svg" id="1_6wc7d"] [ext_resource type="Texture2D" uid="uid://bkty6563cthj8" path="res://Features/Run/Resources/Run.svg" id="1_6wc7d"]
[ext_resource type="Script" uid="uid://bddno1bbvvp5q" path="res://Features/LeftSideBar/LeftSideBar.cs" id="1_rgaf0"] [ext_resource type="Script" uid="uid://bddno1bbvvp5q" path="res://Features/LeftSideBar/LeftSideBar.cs" id="1_rgaf0"]
[ext_resource type="ButtonGroup" uid="uid://c2nmo2x3va0gi" path="res://Features/LeftSideBar/LeftBottomSidebarButtonGroup.tres" id="2_1aad6"]
[node name="LeftSideBar" type="Panel"] [node name="LeftSideBar" type="Panel"]
custom_minimum_size = Vector2(80, 0) custom_minimum_size = Vector2(80, 0)
@@ -49,6 +50,7 @@ layout_mode = 2
focus_mode = 0 focus_mode = 0
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
toggle_mode = true toggle_mode = true
button_group = ExtResource("2_1aad6")
text = "Problems" text = "Problems"
icon = ExtResource("1_6wc7d") icon = ExtResource("1_6wc7d")
icon_alignment = 1 icon_alignment = 1
@@ -61,6 +63,7 @@ layout_mode = 2
focus_mode = 0 focus_mode = 0
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
toggle_mode = true toggle_mode = true
button_group = ExtResource("2_1aad6")
text = "Run" text = "Run"
icon = ExtResource("1_6wc7d") icon = ExtResource("1_6wc7d")
icon_alignment = 1 icon_alignment = 1
@@ -73,6 +76,7 @@ layout_mode = 2
focus_mode = 0 focus_mode = 0
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
toggle_mode = true toggle_mode = true
button_group = ExtResource("2_1aad6")
text = "Build" text = "Build"
icon = ExtResource("1_6wc7d") icon = ExtResource("1_6wc7d")
icon_alignment = 1 icon_alignment = 1

View File

@@ -2,8 +2,8 @@
public static class GodotGlobalEvents public static class GodotGlobalEvents
{ {
public static event Func<BottomPanelType, Task> LeftSideBarButtonClicked = _ => Task.CompletedTask; public static event Func<BottomPanelType?, Task> BottomPanelTabSelected = _ => Task.CompletedTask;
public static void InvokeLeftSideBarButtonClicked(BottomPanelType type) => LeftSideBarButtonClicked?.Invoke(type); public static void InvokeBottomPanelTabSelected(BottomPanelType? type) => BottomPanelTabSelected.Invoke(type);
} }
public enum BottomPanelType public enum BottomPanelType