-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the TAB control (#1680)
- Loading branch information
Showing
4 changed files
with
54 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,55 @@ | ||
using System.Linq; | ||
using OpenDreamClient.Interface.Descriptors; | ||
using Robust.Client.UserInterface; | ||
using Robust.Client.UserInterface.Controls; | ||
|
||
namespace OpenDreamClient.Interface.Controls; | ||
|
||
internal sealed class ControlTab : InterfaceControl { | ||
internal sealed class ControlTab(ControlDescriptor controlDescriptor, ControlWindow window) | ||
: InterfaceControl(controlDescriptor, window) { | ||
private ControlDescriptorTab TabDescriptor => (ControlDescriptorTab)ElementDescriptor; | ||
|
||
private TabContainer _tab; | ||
private readonly List<ControlWindow> _tabs = new(); | ||
|
||
protected override Control CreateUIElement() { | ||
_tab = new TabContainer(); | ||
|
||
public ControlTab(ControlDescriptor controlDescriptor, ControlWindow window) : | ||
base(controlDescriptor, window) { | ||
return _tab; | ||
} | ||
|
||
protected override Control CreateUIElement() { | ||
_tab = new TabContainer() { | ||
protected override void UpdateElementDescriptor() { | ||
base.UpdateElementDescriptor(); | ||
|
||
}; | ||
_tabs.Clear(); | ||
_tab.RemoveAllChildren(); | ||
if (TabDescriptor.Tabs != null) { | ||
var tabIds = TabDescriptor.Tabs.Split(',', | ||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); | ||
|
||
return _tab; | ||
foreach (var tabId in tabIds) { | ||
if (!_interfaceManager.Windows.TryGetValue(tabId, out var pane)) | ||
continue; | ||
|
||
TabContainer.SetTabTitle(pane.UIElement, pane.Title); | ||
_tab.AddChild(pane.UIElement); | ||
_tabs.Add(pane); | ||
if (TabDescriptor.CurrentTab == pane.Title) | ||
_tab.CurrentTab = pane.UIElement.GetPositionInParent(); | ||
} | ||
} | ||
} | ||
|
||
public override bool TryGetProperty(string property, out string value) { | ||
switch (property) { | ||
case "current-tab": | ||
var currentTab = _tab.GetChild(_tab.CurrentTab); | ||
|
||
// The use of First() is kinda bad but hopefully this isn't large or performance critical | ||
value = _tabs.First(tab => tab.UIElement == currentTab).Id; | ||
return true; | ||
default: | ||
return base.TryGetProperty(property, out value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters