UTKToolBar 완료
This commit is contained in:
@@ -15,10 +15,10 @@ namespace UVC.UIToolkit
|
||||
#region Fields
|
||||
|
||||
/// <summary>아이콘 요소 (Material Icon Label 또는 Image)</summary>
|
||||
protected Label? _iconLabel;
|
||||
protected UTKLabel? _iconLabel;
|
||||
|
||||
/// <summary>텍스트 라벨</summary>
|
||||
protected Label? _textLabel;
|
||||
protected UTKLabel? _textLabel;
|
||||
|
||||
/// <summary>루트 버튼 요소</summary>
|
||||
protected VisualElement? _rootButton;
|
||||
@@ -103,12 +103,13 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
var root = asset.Instantiate();
|
||||
_rootButton = root.Q<VisualElement>("button-root");
|
||||
_iconLabel = root.Q<Label>("icon");
|
||||
_textLabel = root.Q<Label>("label");
|
||||
_iconLabel = root.Q<UTKLabel>("icon");
|
||||
_textLabel = root.Q<UTKLabel>("label");
|
||||
_textLabel.Size = UTKLabel.LabelSize.Caption; // UXML에서 기본 크기를 설정하므로 코드에서 다시 지정
|
||||
|
||||
// TemplateContainer가 아이콘 정렬을 방해하지 않도록 설정
|
||||
root.style.flexGrow = 1;
|
||||
root.style.alignItems = Align.Center;
|
||||
root.style.alignItems = Align.Stretch;
|
||||
root.style.justifyContent = Justify.Center;
|
||||
|
||||
Add(root);
|
||||
@@ -129,12 +130,13 @@ namespace UVC.UIToolkit
|
||||
_rootButton = new VisualElement();
|
||||
_rootButton.AddToClassList("utk-toolbar-btn");
|
||||
|
||||
_iconLabel = new Label();
|
||||
_iconLabel = new UTKLabel();
|
||||
_iconLabel.AddToClassList("utk-toolbar-btn__icon");
|
||||
_rootButton.Add(_iconLabel);
|
||||
|
||||
_textLabel = new Label();
|
||||
_textLabel = new UTKLabel();
|
||||
_textLabel.AddToClassList("utk-toolbar-btn__label");
|
||||
_textLabel.Size = UTKLabel.LabelSize.Caption;
|
||||
_rootButton.Add(_textLabel);
|
||||
|
||||
Add(_rootButton);
|
||||
@@ -164,6 +166,7 @@ namespace UVC.UIToolkit
|
||||
UpdateIcon(_data.IconPath, _data.UseMaterialIcon);
|
||||
UpdateText(_data.Text);
|
||||
UpdateEnabled(_data.IsEnabled);
|
||||
UpdateTooltip(_data.Tooltip);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -216,29 +219,15 @@ namespace UVC.UIToolkit
|
||||
|
||||
if (useMaterialIcon)
|
||||
{
|
||||
// Material Icon (폰트 기반)
|
||||
// Material Icon (폰트 기반) - UTKLabel의 SetMaterialIcon 사용
|
||||
_iconLabel.RemoveFromClassList("utk-toolbar-btn__icon--image");
|
||||
_iconLabel.text = iconPath;
|
||||
_iconLabel.style.backgroundImage = StyleKeyword.None;
|
||||
_iconLabel.SetMaterialIcon(iconPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 이미지 아이콘
|
||||
// 이미지 아이콘 - UTKLabel의 SetImageIcon 사용
|
||||
_iconLabel.AddToClassList("utk-toolbar-btn__icon--image");
|
||||
_iconLabel.text = "";
|
||||
var sprite = Resources.Load<Sprite>(iconPath);
|
||||
if (sprite != null)
|
||||
{
|
||||
_iconLabel.style.backgroundImage = new StyleBackground(sprite);
|
||||
}
|
||||
else
|
||||
{
|
||||
var texture = Resources.Load<Texture2D>(iconPath);
|
||||
if (texture != null)
|
||||
{
|
||||
_iconLabel.style.backgroundImage = new StyleBackground(texture);
|
||||
}
|
||||
}
|
||||
_iconLabel.SetImageIcon(iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +239,26 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
if (_textLabel != null)
|
||||
{
|
||||
_textLabel.text = text;
|
||||
_textLabel.Text = text;
|
||||
_textLabel.style.display = string.IsNullOrEmpty(text) ? DisplayStyle.None : DisplayStyle.Flex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 툴팁을 업데이트합니다.
|
||||
/// </summary>
|
||||
/// <param name="tooltipText">툴팁 텍스트</param>
|
||||
protected void UpdateTooltip(string? tooltipText)
|
||||
{
|
||||
if (_rootButton == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(tooltipText))
|
||||
{
|
||||
UTKTooltipManager.Instance.DetachTooltip(_rootButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
UTKTooltipManager.Instance.UpdateTooltip(_rootButton, tooltipText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,6 +290,7 @@ namespace UVC.UIToolkit
|
||||
UpdateIcon(_data.IconPath, _data.UseMaterialIcon);
|
||||
UpdateText(_data.Text);
|
||||
UpdateEnabled(_data.IsEnabled);
|
||||
UpdateTooltip(_data.Tooltip);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -354,6 +363,12 @@ namespace UVC.UIToolkit
|
||||
// 데이터 바인딩 해제
|
||||
UnbindData();
|
||||
|
||||
// 툴팁 해제
|
||||
if (_rootButton != null)
|
||||
{
|
||||
UTKTooltipManager.Instance.DetachTooltip(_rootButton);
|
||||
}
|
||||
|
||||
// 테마 구독 해제
|
||||
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
|
||||
UnregisterCallback<AttachToPanelEvent>(OnAttachToPanelForTheme);
|
||||
|
||||
Reference in New Issue
Block a user