mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Use AttachedProperty for TabContainer, TabVisibleProperty.
This commit is contained in:
@@ -541,7 +541,7 @@ namespace Robust.Client.Console.Commands
|
||||
}
|
||||
|
||||
var group = new ButtonGroup();
|
||||
var vBoxRadioButtons = new VBoxContainer { Name = "Radio Buttons" };
|
||||
var vBoxRadioButtons = new VBoxContainer();
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
vBoxRadioButtons.AddChild(new Button
|
||||
@@ -555,6 +555,8 @@ namespace Robust.Client.Console.Commands
|
||||
|
||||
tabContainer.AddChild(vBoxRadioButtons);
|
||||
|
||||
TabContainer.SetTabTitle(vBoxRadioButtons, "Radio buttons!!");
|
||||
|
||||
tabContainer.AddChild(new VBoxContainer
|
||||
{
|
||||
Name = "Slider",
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.UserInterface.Controls
|
||||
{
|
||||
public class TabContainer : Container
|
||||
{
|
||||
public static readonly AttachedProperty<bool> TabVisibleProperty = AttachedProperty<bool>.Create("TabVisible", typeof(TabContainer), true);
|
||||
public static readonly AttachedProperty<string> TabTitleProperty = AttachedProperty<string>.Create("TabTitle", typeof(TabContainer));
|
||||
|
||||
public const string StylePropertyTabStyleBox = "tab-stylebox";
|
||||
public const string StylePropertyTabStyleBoxInactive = "tab-stylebox-inactive";
|
||||
public const string stylePropertyTabFontColor = "tab-font-color";
|
||||
@@ -20,7 +21,6 @@ namespace Robust.Client.UserInterface.Controls
|
||||
|
||||
private int _currentTab;
|
||||
private bool _tabsVisible = true;
|
||||
private readonly List<TabData> _tabData = new List<TabData>();
|
||||
|
||||
public int CurrentTab
|
||||
{
|
||||
@@ -72,22 +72,56 @@ namespace Robust.Client.UserInterface.Controls
|
||||
MouseFilter = MouseFilterMode.Pass;
|
||||
}
|
||||
|
||||
public string GetTabTitle(int tab)
|
||||
public string GetActualTabTitle(int tab)
|
||||
{
|
||||
return _tabData[tab].Name ?? GetChild(tab).Name ?? Loc.GetString("No title");
|
||||
var control = GetChild(tab);
|
||||
var title = control.GetValue(TabTitleProperty);
|
||||
|
||||
return title ?? control.Name ?? Loc.GetString("No title");
|
||||
}
|
||||
|
||||
public static string GetTabTitle(Control control)
|
||||
{
|
||||
return control.GetValue(TabTitleProperty);
|
||||
}
|
||||
|
||||
public bool GetTabVisible(int tab)
|
||||
{
|
||||
var control = GetChild(tab);
|
||||
return GetTabVisible(control);
|
||||
}
|
||||
|
||||
public static bool GetTabVisible(Control control)
|
||||
{
|
||||
return control.GetValue(TabVisibleProperty);
|
||||
}
|
||||
|
||||
public void SetTabTitle(int tab, string title)
|
||||
{
|
||||
_tabData[tab].Name = title;
|
||||
var control = GetChild(tab);
|
||||
SetTabTitle(control, title);
|
||||
}
|
||||
|
||||
public static void SetTabTitle(Control control, string title)
|
||||
{
|
||||
control.SetValue(TabTitleProperty, title);
|
||||
}
|
||||
|
||||
public void SetTabVisible(int tab, bool visible)
|
||||
{
|
||||
var control = GetChild(tab);
|
||||
SetTabVisible(control, visible);
|
||||
}
|
||||
|
||||
public static void SetTabVisible(Control control, bool visible)
|
||||
{
|
||||
control.SetValue(TabVisibleProperty, visible);
|
||||
}
|
||||
|
||||
protected override void ChildAdded(Control newChild)
|
||||
{
|
||||
base.ChildAdded(newChild);
|
||||
|
||||
_tabData.Add(new TabData(newChild));
|
||||
|
||||
if (ChildCount == 1)
|
||||
{
|
||||
// This is our first child so it must always be visible.
|
||||
@@ -101,30 +135,6 @@ namespace Robust.Client.UserInterface.Controls
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ChildRemoved(Control child)
|
||||
{
|
||||
base.ChildRemoved(child);
|
||||
|
||||
for (var i = 0; i < _tabData.Count; i++)
|
||||
{
|
||||
if (_tabData[i].Control == child)
|
||||
{
|
||||
_tabData.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ChildMoved(Control child, int oldIndex, int newIndex)
|
||||
{
|
||||
base.ChildMoved(child, oldIndex, newIndex);
|
||||
|
||||
var data = _tabData[oldIndex];
|
||||
DebugTools.Assert(data.Control == child);
|
||||
_tabData.RemoveAt(oldIndex);
|
||||
_tabData.Insert(newIndex, data);
|
||||
}
|
||||
|
||||
protected internal override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
base.Draw(handle);
|
||||
@@ -145,9 +155,14 @@ namespace Robust.Client.UserInterface.Controls
|
||||
var headerOffset = 0f;
|
||||
|
||||
// Then, draw the tabs.
|
||||
for (var i = 0; i < _tabData.Count; i++)
|
||||
for (var i = 0; i < ChildCount; i++)
|
||||
{
|
||||
var title = GetTabTitle(i);
|
||||
if (!GetTabVisible(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var title = GetActualTabTitle(i);
|
||||
|
||||
var titleLength = 0;
|
||||
// Get string length.
|
||||
@@ -264,9 +279,14 @@ namespace Robust.Client.UserInterface.Controls
|
||||
|
||||
var headerOffset = 0f;
|
||||
|
||||
for (var i = 0; i < _tabData.Count; i++)
|
||||
for (var i = 0; i < ChildCount; i++)
|
||||
{
|
||||
var title = GetTabTitle(i);
|
||||
if (!GetTabVisible(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var title = GetActualTabTitle(i);
|
||||
|
||||
var titleLength = 0;
|
||||
// Get string length.
|
||||
@@ -384,16 +404,5 @@ namespace Robust.Client.UserInterface.Controls
|
||||
|
||||
return UserInterfaceManager.ThemeDefaults.DefaultFont;
|
||||
}
|
||||
|
||||
private class TabData
|
||||
{
|
||||
public string Name;
|
||||
public readonly Control Control;
|
||||
|
||||
public TabData(Control control)
|
||||
{
|
||||
Control = control;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user