샘플 코드 개선. UTKHelpBox 개선
This commit is contained in:
@@ -14,9 +14,9 @@ namespace UVC.UIToolkit
|
||||
/// <code>
|
||||
/// // 라디오 버튼 그룹
|
||||
/// var group = new RadioButtonGroup();
|
||||
/// var radio1 = new UTKRadioButton { Label = "옵션 1" };
|
||||
/// var radio2 = new UTKRadioButton { Label = "옵션 2" };
|
||||
/// var radio3 = new UTKRadioButton { Label = "옵션 3" };
|
||||
/// var radio1 = new UTKRadioButton { text = "옵션 1" }; // Unity RadioButton의 text 프로퍼티
|
||||
/// var radio2 = new UTKRadioButton { text = "옵션 2" };
|
||||
/// var radio3 = new UTKRadioButton { text = "옵션 3" };
|
||||
/// group.Add(radio1);
|
||||
/// group.Add(radio2);
|
||||
/// group.Add(radio3);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace UVC.UIToolkit
|
||||
/// <code>
|
||||
/// // 기본 토글
|
||||
/// var toggle = new UTKToggle();
|
||||
/// toggle.Label = "알림 받기";
|
||||
/// toggle.label = "알림 받기";
|
||||
/// toggle.IsOn = true;
|
||||
/// toggle.OnValueChanged += (isOn) => Debug.Log($"토글: {isOn}");
|
||||
/// </code>
|
||||
|
||||
@@ -18,10 +18,11 @@ namespace UVC.UIToolkit
|
||||
/// Unity Inspector에서 볼 수 있는 노란색/빨간색 경고 박스와 같은 역할입니다.
|
||||
/// </para>
|
||||
///
|
||||
/// <para><b>메시지 유형 (HelpBoxMessageType):</b></para>
|
||||
/// <para><b>메시지 유형 (MessageType):</b></para>
|
||||
/// <list type="bullet">
|
||||
/// <item><description><c>None</c> - 아이콘 없이 텍스트만 표시</description></item>
|
||||
/// <item><description><c>Info</c> - 정보 아이콘 (파란색) - 일반 안내 메시지</description></item>
|
||||
/// <item><description><c>Success</c> - 성공 아이콘 (녹색) - 작업 완료, 성공</description></item>
|
||||
/// <item><description><c>Warning</c> - 경고 아이콘 (노란색) - 주의 필요한 사항</description></item>
|
||||
/// <item><description><c>Error</c> - 오류 아이콘 (빨간색) - 에러, 문제 상황</description></item>
|
||||
/// </list>
|
||||
@@ -46,22 +47,29 @@ namespace UVC.UIToolkit
|
||||
/// // 정보 메시지
|
||||
/// var infoBox = new UTKHelpBox()
|
||||
/// {
|
||||
/// Message = "이 기능은 베타 버전입니다.",
|
||||
/// messageType = HelpBoxMessageType.Info
|
||||
/// Text = "이 기능은 베타 버전입니다.",
|
||||
/// messageType = UTKHelpBox.MessageType.Info
|
||||
/// };
|
||||
///
|
||||
/// // 성공 메시지
|
||||
/// var successBox = new UTKHelpBox()
|
||||
/// {
|
||||
/// Text = "저장되었습니다.",
|
||||
/// messageType = UTKHelpBox.MessageType.Success
|
||||
/// };
|
||||
///
|
||||
/// // 경고 메시지
|
||||
/// var warningBox = new UTKHelpBox()
|
||||
/// {
|
||||
/// Message = "주의: 되돌릴 수 없습니다.",
|
||||
/// messageType = HelpBoxMessageType.Warning
|
||||
/// Text = "주의: 되돌릴 수 없습니다.",
|
||||
/// messageType = UTKHelpBox.MessageType.Warning
|
||||
/// };
|
||||
///
|
||||
/// // 오류 메시지
|
||||
/// var errorBox = new UTKHelpBox()
|
||||
/// {
|
||||
/// Message = "오류: 파일을 찾을 수 없습니다.",
|
||||
/// messageType = HelpBoxMessageType.Error
|
||||
/// Text = "오류: 파일을 찾을 수 없습니다.",
|
||||
/// messageType = UTKHelpBox.MessageType.Error
|
||||
/// };
|
||||
/// </code>
|
||||
/// <para><b>UXML에서 사용:</b></para>
|
||||
@@ -70,6 +78,9 @@ namespace UVC.UIToolkit
|
||||
/// <!-- 정보 -->
|
||||
/// <utk:UTKHelpBox text="정보 메시지입니다." message-type="Info" />
|
||||
///
|
||||
/// <!-- 성공 -->
|
||||
/// <utk:UTKHelpBox text="성공 메시지입니다." message-type="Success" />
|
||||
///
|
||||
/// <!-- 경고 -->
|
||||
/// <utk:UTKHelpBox text="경고 메시지입니다." message-type="Warning" />
|
||||
///
|
||||
@@ -78,8 +89,20 @@ namespace UVC.UIToolkit
|
||||
/// </ui:UXML>
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <summary>
|
||||
/// 메시지 유형
|
||||
/// </summary>
|
||||
public enum MessageType
|
||||
{
|
||||
None,
|
||||
Info,
|
||||
Success,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
[UxmlElement]
|
||||
public partial class UTKHelpBox : HelpBox, IDisposable
|
||||
public partial class UTKHelpBox : VisualElement, IDisposable
|
||||
{
|
||||
#region Constants
|
||||
private const string USS_PATH = "UIToolkit/Common/UTKHelpBox";
|
||||
@@ -87,26 +110,35 @@ namespace UVC.UIToolkit
|
||||
|
||||
#region Fields
|
||||
private bool _disposed;
|
||||
private Label? _iconLabel;
|
||||
private Label? _messageLabel;
|
||||
private string _text = "";
|
||||
private MessageType _messageType = MessageType.Info;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>메시지 텍스트</summary>
|
||||
[UxmlAttribute("text")]
|
||||
public string Message
|
||||
public string Text
|
||||
{
|
||||
get => text;
|
||||
set => text = value;
|
||||
get => _text;
|
||||
set
|
||||
{
|
||||
_text = value;
|
||||
if (_messageLabel != null)
|
||||
_messageLabel.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>메시지 타입</summary>
|
||||
[UxmlAttribute("message-type")]
|
||||
public new HelpBoxMessageType MessageType
|
||||
public MessageType messageType
|
||||
{
|
||||
get => base.messageType;
|
||||
get => _messageType;
|
||||
set
|
||||
{
|
||||
base.messageType = value;
|
||||
UpdateMessageTypeClass();
|
||||
_messageType = value;
|
||||
UpdateMessageType();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -122,39 +154,73 @@ namespace UVC.UIToolkit
|
||||
styleSheets.Add(uss);
|
||||
}
|
||||
|
||||
SetupUI();
|
||||
SetupStyles();
|
||||
SubscribeToThemeChanges();
|
||||
}
|
||||
|
||||
public UTKHelpBox(string message, HelpBoxMessageType type = HelpBoxMessageType.Info) : this()
|
||||
public UTKHelpBox(string message, MessageType type = MessageType.Info) : this()
|
||||
{
|
||||
Message = message;
|
||||
MessageType = type;
|
||||
Text = message;
|
||||
messageType = type;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Setup
|
||||
private void SetupUI()
|
||||
{
|
||||
// 아이콘 레이블 (Material Icon)
|
||||
_iconLabel = new Label();
|
||||
_iconLabel.AddToClassList("utk-helpbox__icon");
|
||||
|
||||
// Material Icons 폰트 적용
|
||||
UTKMaterialIcons.ApplyIconStyle(_iconLabel);
|
||||
|
||||
// 수직 정렬
|
||||
_iconLabel.style.unityTextAlign = TextAnchor.MiddleCenter;
|
||||
_iconLabel.style.alignSelf = Align.Center;
|
||||
|
||||
Add(_iconLabel);
|
||||
|
||||
// 메시지 레이블
|
||||
_messageLabel = new Label(_text);
|
||||
_messageLabel.AddToClassList("utk-helpbox__message");
|
||||
|
||||
// 수직 정렬
|
||||
_messageLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
_messageLabel.style.alignSelf = Align.Center;
|
||||
|
||||
Add(_messageLabel);
|
||||
}
|
||||
|
||||
private void SetupStyles()
|
||||
{
|
||||
AddToClassList("utk-helpbox");
|
||||
UpdateMessageTypeClass();
|
||||
UpdateMessageType();
|
||||
}
|
||||
|
||||
private void UpdateMessageTypeClass()
|
||||
private void UpdateMessageType()
|
||||
{
|
||||
if (_iconLabel == null || _messageLabel == null) return;
|
||||
|
||||
RemoveFromClassList("utk-helpbox--info");
|
||||
RemoveFromClassList("utk-helpbox--success");
|
||||
RemoveFromClassList("utk-helpbox--warning");
|
||||
RemoveFromClassList("utk-helpbox--error");
|
||||
RemoveFromClassList("utk-helpbox--none");
|
||||
|
||||
var typeClass = messageType switch
|
||||
var (typeClass, iconText) = _messageType switch
|
||||
{
|
||||
HelpBoxMessageType.Warning => "utk-helpbox--warning",
|
||||
HelpBoxMessageType.Error => "utk-helpbox--error",
|
||||
HelpBoxMessageType.None => "utk-helpbox--none",
|
||||
_ => "utk-helpbox--info"
|
||||
MessageType.Success => ("utk-helpbox--success", UTKMaterialIcons.CheckCircle),
|
||||
MessageType.Warning => ("utk-helpbox--warning", UTKMaterialIcons.Warning),
|
||||
MessageType.Error => ("utk-helpbox--error", UTKMaterialIcons.Error),
|
||||
MessageType.None => ("utk-helpbox--none", ""),
|
||||
_ => ("utk-helpbox--info", UTKMaterialIcons.Info)
|
||||
};
|
||||
|
||||
AddToClassList(typeClass);
|
||||
_iconLabel.text = iconText;
|
||||
_iconLabel.style.display = _messageType == MessageType.None ? DisplayStyle.None : DisplayStyle.Flex;
|
||||
}
|
||||
|
||||
private void SubscribeToThemeChanges()
|
||||
|
||||
@@ -14,18 +14,19 @@ namespace UVC.UIToolkit
|
||||
/// <code>
|
||||
/// // 기본 입력 필드
|
||||
/// var input = new UTKInputField();
|
||||
/// input.Label = "이름";
|
||||
/// input.label = "이름";
|
||||
/// input.Placeholder = "이름을 입력하세요";
|
||||
/// input.OnValueChanged += (value) => Debug.Log($"입력값: {value}");
|
||||
///
|
||||
/// // 비밀번호 입력 필드
|
||||
/// var password = new UTKInputField();
|
||||
/// password.Label = "비밀번호";
|
||||
/// password.label = "비밀번호";
|
||||
/// password.isPasswordField = true;
|
||||
///
|
||||
/// // 검증 오류 표시
|
||||
/// input.SetError("이름은 필수입니다.");
|
||||
/// input.ClearError();
|
||||
/// input.ErrorMessage = "이름은 필수입니다.";
|
||||
/// // 오류 제거
|
||||
/// input.ErrorMessage = "";
|
||||
///
|
||||
/// // 변형 스타일
|
||||
/// input.Variant = UTKInputField.InputFieldVariant.Outlined;
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace UVC.UIToolkit
|
||||
///
|
||||
/// // 스타일 적용
|
||||
/// label.IsItalic = true;
|
||||
/// label.TextAlign = UTKLabel.TextAlign.Center;
|
||||
/// label.TextAlignment = UTKLabel.TextAlign.Center;
|
||||
///
|
||||
/// // Material Icon과 텍스트 함께 사용
|
||||
/// var iconLabel = new UTKLabel("설정", UTKMaterialIcons.Settings);
|
||||
@@ -83,11 +83,11 @@ namespace UVC.UIToolkit
|
||||
/// // Image Icon과 텍스트 함께 사용
|
||||
/// var imgLabel = new UTKLabel("닫기", UTKImageIcons.BtnClose16, isImageIcon: true);
|
||||
///
|
||||
/// // Material Icon만 사용
|
||||
/// // Material Icon만 사용 (iconSize 파라미터)
|
||||
/// var iconOnly = new UTKLabel(UTKMaterialIcons.Home, 12);
|
||||
///
|
||||
/// // Image Icon만 사용
|
||||
/// var imgOnly = new UTKLabel(UTKImageIcons.IconSetting22, isImageIcon: true);
|
||||
/// var imgOnly = new UTKLabel(UTKImageIcons.IconSetting22, isImageIcon: true, iconSize: 0);
|
||||
///
|
||||
/// // 메서드로 아이콘 설정
|
||||
/// label.SetMaterialIcon(UTKMaterialIcons.Search);
|
||||
|
||||
Reference in New Issue
Block a user