1
This commit is contained in:
@@ -11,11 +11,6 @@ namespace BITKit.UX
|
||||
{
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits
|
||||
{
|
||||
private readonly UxmlIntAttributeDescription m_currentTabAttribute = new ()
|
||||
{
|
||||
name = "CurrentTab",
|
||||
defaultValue = -1
|
||||
};
|
||||
private readonly UxmlStringAttributeDescription m_customTabPathAttribute = new ()
|
||||
{
|
||||
name = "CustomTabPath",
|
||||
@@ -24,7 +19,6 @@ namespace BITKit.UX
|
||||
{
|
||||
base.Init(ve, bag, cc);
|
||||
var tabContainer = (TabContainer)ve;
|
||||
tabContainer.CurrentTab = m_currentTabAttribute.GetValueFromBag(bag, cc);
|
||||
tabContainer.CustomTabPath = m_customTabPathAttribute.GetValueFromBag(bag, cc);
|
||||
tabContainer.pickingMode = PickingMode.Ignore;
|
||||
tabContainer._container.pickingMode = PickingMode.Ignore;
|
||||
@@ -33,7 +27,6 @@ namespace BITKit.UX
|
||||
public new class UxmlFactory : UxmlFactory<TabContainer, UxmlTraits> { }
|
||||
public TabContainer()
|
||||
{
|
||||
_internalTabBar = new TabBar();
|
||||
_container = new VisualElement
|
||||
{
|
||||
name = UXConstant.ContextContainer,
|
||||
@@ -42,14 +35,19 @@ namespace BITKit.UX
|
||||
flexGrow = 1
|
||||
}
|
||||
};
|
||||
hierarchy.Add(_internalTabBar);
|
||||
hierarchy.Add(_container);
|
||||
RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
|
||||
RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
|
||||
_internalTabBar.OnTabChanged += EntryTab;
|
||||
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
pickingMode = PickingMode.Ignore;
|
||||
_container.pickingMode = PickingMode.Ignore;
|
||||
}
|
||||
|
||||
private void OnGeometryChanged(GeometryChangedEvent evt)
|
||||
{
|
||||
UpdateTabBar();
|
||||
}
|
||||
|
||||
public override VisualElement contentContainer => _container;
|
||||
public event Action<int> OnTabChanged;
|
||||
private int currentTab=-1;
|
||||
@@ -83,11 +81,10 @@ namespace BITKit.UX
|
||||
_externalTabBar.OnTabChanged += EntryTab;
|
||||
}
|
||||
}
|
||||
_internalTabBar.SetActive(_externalTabBar is null);
|
||||
viewDataKey=_externalTabBar is null ? "找到了TabBar" :"未找到Tab";
|
||||
}
|
||||
}
|
||||
private readonly VisualElement _container;
|
||||
private readonly TabBar _internalTabBar;
|
||||
private TabBar _externalTabBar;
|
||||
|
||||
private void OnDetachFromPanel(DetachFromPanelEvent evt)
|
||||
@@ -103,12 +100,7 @@ namespace BITKit.UX
|
||||
CustomTabPath = CustomTabPath;
|
||||
CurrentTab = CurrentTab;
|
||||
_externalTabBar?.SetValueWithoutNotify(CurrentTab);
|
||||
_internalTabBar.SetValueWithoutNotify(CurrentTab);
|
||||
_internalTabBar.Tabs = string.Join(",", _container.Children().Select(x => x.name));
|
||||
}
|
||||
private void OnShowTab(bool value)
|
||||
{
|
||||
_internalTabBar.style.display = value ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
CurrentTab = CurrentTab;
|
||||
}
|
||||
public void EntryTab(int index)
|
||||
{
|
||||
@@ -116,7 +108,7 @@ namespace BITKit.UX
|
||||
{
|
||||
x.SetActive(false);
|
||||
}
|
||||
if(_container.Children().TryGet(index,out var element))
|
||||
if(_container.Children().TryGetElementAt(index,out var element))
|
||||
element.SetActive(true);
|
||||
OnTabChanged?.Invoke(index);
|
||||
}
|
||||
|
Reference in New Issue
Block a user