fix?
This commit is contained in:
252
Editor/RebootWindow/TabView.cs
Normal file → Executable file
252
Editor/RebootWindow/TabView.cs
Normal file → Executable file
@@ -1,127 +1,127 @@
|
||||
using System.Collections.Generic;
|
||||
using RebootKit.Engine.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RebootKitEditor.RebootWindow {
|
||||
public class TabView : IView {
|
||||
struct Tab {
|
||||
public string name;
|
||||
public IView view;
|
||||
public VisualElement container;
|
||||
}
|
||||
|
||||
readonly List<Tab> m_Tabs = new();
|
||||
readonly List<VisualElement> m_TabContents = new();
|
||||
readonly List<Button> m_TabButtons = new();
|
||||
int m_CurrentTabIndex = -1;
|
||||
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public VisualElement Build() {
|
||||
VisualElement rootContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Row,
|
||||
flexGrow = 1,
|
||||
width = new StyleLength(new Length(100, LengthUnit.Percent)),
|
||||
height = new StyleLength(new Length(100, LengthUnit.Percent)),
|
||||
backgroundColor = RTheme.s_BackgroundPrimaryColor
|
||||
}
|
||||
};
|
||||
|
||||
VisualElement tabContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Row,
|
||||
width = new StyleLength(new Length(100, LengthUnit.Percent)),
|
||||
}
|
||||
};
|
||||
rootContainer.Add(tabContainer);
|
||||
|
||||
VisualElement tabButtonsContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Column,
|
||||
borderRightWidth = 1,
|
||||
borderRightColor = new Color(0.1f, 0.1f, 0.1f),
|
||||
width = 100,
|
||||
fontSize = 24,
|
||||
backgroundColor = RTheme.s_BackgroundSecondaryColor
|
||||
}
|
||||
};
|
||||
tabContainer.Add(tabButtonsContainer);
|
||||
|
||||
VisualElement contentContainer = new() {
|
||||
style = {
|
||||
flexGrow = 1,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
paddingTop = 4,
|
||||
paddingBottom = 4,
|
||||
}
|
||||
};
|
||||
tabContainer.Add(contentContainer);
|
||||
|
||||
for (int i = 0; i < m_Tabs.Count; i++) {
|
||||
Tab tab = m_Tabs[i];
|
||||
int index = i;
|
||||
|
||||
Button button = new(() => SetActiveTab(index)) {
|
||||
text = tab.name,
|
||||
style = {
|
||||
paddingLeft = 8,
|
||||
paddingRight = 8,
|
||||
paddingTop = 4,
|
||||
paddingBottom = 4,
|
||||
borderTopLeftRadius = 0,
|
||||
borderTopRightRadius = 0,
|
||||
borderBottomLeftRadius = 0,
|
||||
borderBottomRightRadius = 0,
|
||||
backgroundColor = new Color(0.2f, 0.2f, 0.2f)
|
||||
}
|
||||
};
|
||||
tabButtonsContainer.Add(button);
|
||||
m_TabButtons.Add(button);
|
||||
|
||||
VisualElement tabContent = tab.container;
|
||||
tabContent.style.display = DisplayStyle.None;
|
||||
contentContainer.Add(tabContent);
|
||||
m_TabContents.Add(tabContent);
|
||||
}
|
||||
|
||||
SetActiveTab(0);
|
||||
return rootContainer;
|
||||
}
|
||||
|
||||
public void AddTab(string name, IView view) {
|
||||
VisualElement tabContainer = new() {
|
||||
name = "rr_tab__container",
|
||||
style = {
|
||||
flexGrow = 1
|
||||
}
|
||||
};
|
||||
|
||||
VisualElement viewVisualElement = view.Build();
|
||||
Assert.IsNotNull(viewVisualElement);
|
||||
|
||||
tabContainer.Add(viewVisualElement);
|
||||
|
||||
m_Tabs.Add(new Tab {
|
||||
name = name,
|
||||
view = view,
|
||||
container = tabContainer
|
||||
});
|
||||
}
|
||||
|
||||
void SetActiveTab(int index) {
|
||||
if (m_CurrentTabIndex >= 0) {
|
||||
m_TabContents[m_CurrentTabIndex].style.display = DisplayStyle.None;
|
||||
m_TabButtons[m_CurrentTabIndex].style.backgroundColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
}
|
||||
|
||||
m_CurrentTabIndex = index;
|
||||
m_TabContents[index].style.display = DisplayStyle.Flex;
|
||||
m_TabButtons[index].style.backgroundColor = new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using RebootKit.Engine.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RebootKitEditor.RebootWindow {
|
||||
public class TabView : IView {
|
||||
struct Tab {
|
||||
public string name;
|
||||
public IView view;
|
||||
public VisualElement container;
|
||||
}
|
||||
|
||||
readonly List<Tab> m_Tabs = new();
|
||||
readonly List<VisualElement> m_TabContents = new();
|
||||
readonly List<Button> m_TabButtons = new();
|
||||
int m_CurrentTabIndex = -1;
|
||||
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public VisualElement Build() {
|
||||
VisualElement rootContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Row,
|
||||
flexGrow = 1,
|
||||
width = new StyleLength(new Length(100, LengthUnit.Percent)),
|
||||
height = new StyleLength(new Length(100, LengthUnit.Percent)),
|
||||
backgroundColor = RTheme.s_BackgroundPrimaryColor
|
||||
}
|
||||
};
|
||||
|
||||
VisualElement tabContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Row,
|
||||
width = new StyleLength(new Length(100, LengthUnit.Percent)),
|
||||
}
|
||||
};
|
||||
rootContainer.Add(tabContainer);
|
||||
|
||||
VisualElement tabButtonsContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Column,
|
||||
borderRightWidth = 1,
|
||||
borderRightColor = new Color(0.1f, 0.1f, 0.1f),
|
||||
width = 100,
|
||||
fontSize = 24,
|
||||
backgroundColor = RTheme.s_BackgroundSecondaryColor
|
||||
}
|
||||
};
|
||||
tabContainer.Add(tabButtonsContainer);
|
||||
|
||||
VisualElement contentContainer = new() {
|
||||
style = {
|
||||
flexGrow = 1,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
paddingTop = 4,
|
||||
paddingBottom = 4,
|
||||
}
|
||||
};
|
||||
tabContainer.Add(contentContainer);
|
||||
|
||||
for (int i = 0; i < m_Tabs.Count; i++) {
|
||||
Tab tab = m_Tabs[i];
|
||||
int index = i;
|
||||
|
||||
Button button = new(() => SetActiveTab(index)) {
|
||||
text = tab.name,
|
||||
style = {
|
||||
paddingLeft = 8,
|
||||
paddingRight = 8,
|
||||
paddingTop = 4,
|
||||
paddingBottom = 4,
|
||||
borderTopLeftRadius = 0,
|
||||
borderTopRightRadius = 0,
|
||||
borderBottomLeftRadius = 0,
|
||||
borderBottomRightRadius = 0,
|
||||
backgroundColor = new Color(0.2f, 0.2f, 0.2f)
|
||||
}
|
||||
};
|
||||
tabButtonsContainer.Add(button);
|
||||
m_TabButtons.Add(button);
|
||||
|
||||
VisualElement tabContent = tab.container;
|
||||
tabContent.style.display = DisplayStyle.None;
|
||||
contentContainer.Add(tabContent);
|
||||
m_TabContents.Add(tabContent);
|
||||
}
|
||||
|
||||
SetActiveTab(0);
|
||||
return rootContainer;
|
||||
}
|
||||
|
||||
public void AddTab(string name, IView view) {
|
||||
VisualElement tabContainer = new() {
|
||||
name = "rr_tab__container",
|
||||
style = {
|
||||
flexGrow = 1
|
||||
}
|
||||
};
|
||||
|
||||
VisualElement viewVisualElement = view.Build();
|
||||
Assert.IsNotNull(viewVisualElement);
|
||||
|
||||
tabContainer.Add(viewVisualElement);
|
||||
|
||||
m_Tabs.Add(new Tab {
|
||||
name = name,
|
||||
view = view,
|
||||
container = tabContainer
|
||||
});
|
||||
}
|
||||
|
||||
void SetActiveTab(int index) {
|
||||
if (m_CurrentTabIndex >= 0) {
|
||||
m_TabContents[m_CurrentTabIndex].style.display = DisplayStyle.None;
|
||||
m_TabButtons[m_CurrentTabIndex].style.backgroundColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
}
|
||||
|
||||
m_CurrentTabIndex = index;
|
||||
m_TabContents[index].style.display = DisplayStyle.Flex;
|
||||
m_TabButtons[index].style.backgroundColor = new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user