1
This commit is contained in:
18
Assets/BITKit/Unity/Scripts/UX/Library/CustomButton.cs
Normal file
18
Assets/BITKit/Unity/Scripts/UX/Library/CustomButton.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class CustomButton : Button
|
||||
{
|
||||
public new class UxmlTraits : Button.UxmlTraits
|
||||
{
|
||||
}
|
||||
public CustomButton() : base()
|
||||
{
|
||||
}
|
||||
public new class UxmlFactory : UxmlFactory<CustomButton, UxmlTraits> { }
|
||||
}
|
||||
}
|
@@ -23,12 +23,18 @@ namespace BITKit.UX
|
||||
{
|
||||
name = "tabs"
|
||||
};
|
||||
private readonly UxmlBoolAttributeDescription m_allowFocus = new ()
|
||||
{
|
||||
name = "allowFocus",
|
||||
defaultValue = true
|
||||
};
|
||||
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
|
||||
{
|
||||
base.Init(ve, bag, cc);
|
||||
var tabBar = (TabBar)ve;
|
||||
tabBar.CurrentTab = m_TabBarAttribute.GetValueFromBag(bag, cc);
|
||||
tabBar.Tabs = m_TabsAttribute.GetValueFromBag(bag, cc);
|
||||
tabBar.allowFocus = m_allowFocus.GetValueFromBag(bag, cc);
|
||||
}
|
||||
}
|
||||
public new class UxmlFactory : UxmlFactory<TabBar, UxmlTraits> { }
|
||||
@@ -58,6 +64,22 @@ namespace BITKit.UX
|
||||
SetTabs(value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool allowFocus;
|
||||
public bool AllowFocus
|
||||
{
|
||||
get => allowFocus;
|
||||
set
|
||||
{
|
||||
allowFocus = value;
|
||||
foreach (var x in _buttons)
|
||||
{
|
||||
x.focusable = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetTabs(string value)
|
||||
{
|
||||
var split = value.Split(",");
|
||||
@@ -72,6 +94,7 @@ namespace BITKit.UX
|
||||
var index = i;
|
||||
var button = _buttons[i] = this.Create<Button>();
|
||||
button.text = tabName;
|
||||
button.focusable = allowFocus;
|
||||
button.clicked += () => CurrentTab = index;
|
||||
}
|
||||
}
|
||||
|
@@ -76,6 +76,8 @@ namespace BITKit.UX
|
||||
|
||||
[SerializeReference, SubclassSelector] private IUXPanel initialPanel;
|
||||
|
||||
[SerializeField] private TextAsset validTexts;
|
||||
|
||||
private bool initialized;
|
||||
private void Awake()
|
||||
{
|
||||
|
Reference in New Issue
Block a user