스타일 가이드 적용 완료. UTKCOlorPicker, UTKDatePicker 확인해야 함
This commit is contained in:
@@ -181,6 +181,7 @@ namespace UVC.UIToolkit
|
||||
// Actions
|
||||
_actions = new VisualElement { name = "actions" };
|
||||
_actions.AddToClassList("utk-card__actions");
|
||||
_actions.style.display = DisplayStyle.None; // 기본적으로 숨김
|
||||
hierarchy.Add(_actions);
|
||||
|
||||
UpdateVariant();
|
||||
@@ -281,6 +282,13 @@ namespace UVC.UIToolkit
|
||||
public void AddAction(VisualElement element)
|
||||
{
|
||||
_actions?.Add(element);
|
||||
UpdateActionsVisibility();
|
||||
}
|
||||
|
||||
private void UpdateActionsVisibility()
|
||||
{
|
||||
if (_actions == null) return;
|
||||
_actions.style.display = _actions.childCount > 0 ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -159,6 +159,7 @@ namespace UVC.UIToolkit.Common
|
||||
|
||||
_tooltipLabel.text = displayText;
|
||||
_tooltipContainer.style.display = DisplayStyle.Flex;
|
||||
_tooltipContainer.BringToFront();
|
||||
_isVisible = true;
|
||||
|
||||
// 다음 프레임에 위치 조정 (레이아웃 계산 후)
|
||||
@@ -217,11 +218,18 @@ namespace UVC.UIToolkit.Common
|
||||
_tooltipRegistry[element] = tooltip;
|
||||
|
||||
// 이벤트 콜백 생성 및 등록
|
||||
// 참고: evt.position은 로컬 좌표이므로, 패널 기준 좌표로 변환 필요
|
||||
EventCallback<PointerEnterEvent> enterCallback = evt =>
|
||||
{
|
||||
if (_tooltipRegistry.TryGetValue(element, out var text))
|
||||
{
|
||||
ShowDelayed(text, evt.position).Forget();
|
||||
// 로컬 좌표를 root 좌표로 변환
|
||||
var rootPosition = element.LocalToWorld(evt.localPosition);
|
||||
if (_root != null)
|
||||
{
|
||||
rootPosition = _root.WorldToLocal(rootPosition);
|
||||
}
|
||||
ShowDelayed(text, rootPosition).Forget();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -231,7 +239,13 @@ namespace UVC.UIToolkit.Common
|
||||
{
|
||||
if (_isVisible)
|
||||
{
|
||||
AdjustPosition(evt.position);
|
||||
// 로컬 좌표를 root 좌표로 변환
|
||||
var rootPosition = element.LocalToWorld(evt.localPosition);
|
||||
if (_root != null)
|
||||
{
|
||||
rootPosition = _root.WorldToLocal(rootPosition);
|
||||
}
|
||||
AdjustPosition(rootPosition);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.UIToolkit.Modal;
|
||||
@@ -18,10 +19,10 @@ namespace UVC.UIToolkit
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private static VisualElement? _root;
|
||||
|
||||
private bool _disposed;
|
||||
private UTKModalBlocker? _blocker;
|
||||
private VisualElement? _iconContainer;
|
||||
private Label? _iconLabel;
|
||||
private Label? _titleLabel;
|
||||
private Label? _messageLabel;
|
||||
private VisualElement? _buttonContainer;
|
||||
@@ -29,6 +30,11 @@ namespace UVC.UIToolkit
|
||||
private string _title = "";
|
||||
private string _message = "";
|
||||
private AlertType _alertType = AlertType.Info;
|
||||
private string _confirmLabel = "OK";
|
||||
private string _cancelLabel = "Cancel";
|
||||
|
||||
private EventCallback<KeyDownEvent>? _keyDownCallback;
|
||||
private VisualElement? _keyEventTarget;
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
@@ -116,45 +122,234 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory
|
||||
#region Static Methods
|
||||
/// <summary>
|
||||
/// 기본 루트 요소 설정
|
||||
/// </summary>
|
||||
/// <param name="root">Alert를 표시할 기본 루트 요소</param>
|
||||
public static void SetRoot(VisualElement root)
|
||||
{
|
||||
_root = root;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 기본 루트 요소 반환
|
||||
/// </summary>
|
||||
public static VisualElement? GetRoot() => _root;
|
||||
#endregion
|
||||
|
||||
#region Static Factory (without parent)
|
||||
/// <summary>
|
||||
/// Info 알림 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKAlert ShowInfo(string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, title, message, AlertType.Info, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Success 알림 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKAlert ShowSuccess(string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, title, message, AlertType.Success, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warning 알림 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKAlert ShowWarning(string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, title, message, AlertType.Warning, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error 알림 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKAlert ShowError(string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, title, message, AlertType.Error, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm 대화상자 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKAlert ShowConfirm(string title, string message, Action? onConfirm, Action? onCancel = null, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
ValidateRoot();
|
||||
var alert = Show(_root!, title, message, AlertType.Confirm, null, closeOnBlockerClick, confirmLabel, cancelLabel);
|
||||
alert.OnConfirm = onConfirm;
|
||||
alert.OnCancel = onCancel;
|
||||
return alert;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 알림 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKAlert Show(string title, string message, AlertType type = AlertType.Info, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, title, message, type, onClose, closeOnBlockerClick, confirmLabel, cancelLabel);
|
||||
}
|
||||
|
||||
private static void ValidateRoot()
|
||||
{
|
||||
if (_root == null)
|
||||
{
|
||||
throw new InvalidOperationException("UTKAlert.SetRoot()를 먼저 호출하여 기본 루트 요소를 설정해야 합니다.");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory Async (without parent)
|
||||
/// <summary>
|
||||
/// Info 알림 표시 (비동기, SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UniTask ShowInfoAsync(string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return ShowAsync(_root!, title, message, AlertType.Info, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Success 알림 표시 (비동기, SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UniTask ShowSuccessAsync(string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return ShowAsync(_root!, title, message, AlertType.Success, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warning 알림 표시 (비동기, SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UniTask ShowWarningAsync(string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return ShowAsync(_root!, title, message, AlertType.Warning, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error 알림 표시 (비동기, SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UniTask ShowErrorAsync(string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
ValidateRoot();
|
||||
return ShowAsync(_root!, title, message, AlertType.Error, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm 대화상자 표시 (비동기, SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
/// <returns>확인 버튼 클릭 시 true, 취소 버튼 클릭 시 false</returns>
|
||||
public static UniTask<bool> ShowConfirmAsync(string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
ValidateRoot();
|
||||
return ShowConfirmAsync(_root!, title, message, closeOnBlockerClick, confirmLabel, cancelLabel);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory Async (with parent)
|
||||
/// <summary>
|
||||
/// Info 알림 표시 (비동기)
|
||||
/// </summary>
|
||||
public static UniTask ShowInfoAsync(VisualElement parent, string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return ShowAsync(parent, title, message, AlertType.Info, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Success 알림 표시 (비동기)
|
||||
/// </summary>
|
||||
public static UniTask ShowSuccessAsync(VisualElement parent, string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return ShowAsync(parent, title, message, AlertType.Success, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warning 알림 표시 (비동기)
|
||||
/// </summary>
|
||||
public static UniTask ShowWarningAsync(VisualElement parent, string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return ShowAsync(parent, title, message, AlertType.Warning, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error 알림 표시 (비동기)
|
||||
/// </summary>
|
||||
public static UniTask ShowErrorAsync(VisualElement parent, string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return ShowAsync(parent, title, message, AlertType.Error, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm 대화상자 표시 (비동기)
|
||||
/// </summary>
|
||||
/// <returns>확인 버튼 클릭 시 true, 취소 버튼 클릭 시 false</returns>
|
||||
public static UniTask<bool> ShowConfirmAsync(VisualElement parent, string title, string message, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
var tcs = new UniTaskCompletionSource<bool>();
|
||||
var alert = Show(parent, title, message, AlertType.Confirm, null, closeOnBlockerClick, confirmLabel, cancelLabel);
|
||||
alert.OnConfirm = () => tcs.TrySetResult(true);
|
||||
alert.OnCancel = () => tcs.TrySetResult(false);
|
||||
alert.OnClosed = () => tcs.TrySetResult(false);
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 알림 표시 (비동기)
|
||||
/// </summary>
|
||||
public static UniTask ShowAsync(VisualElement parent, string title, string message, AlertType type, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
var tcs = new UniTaskCompletionSource();
|
||||
var alert = Show(parent, title, message, type, () => tcs.TrySetResult(), closeOnBlockerClick, confirmLabel, cancelLabel);
|
||||
return tcs.Task;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory (with parent)
|
||||
/// <summary>
|
||||
/// Info 알림 표시
|
||||
/// </summary>
|
||||
public static UTKAlert ShowInfo(VisualElement parent, string title, string message, Action? onClose = null)
|
||||
public static UTKAlert ShowInfo(VisualElement parent, string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return Show(parent, title, message, AlertType.Info, onClose);
|
||||
return Show(parent, title, message, AlertType.Info, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Success 알림 표시
|
||||
/// </summary>
|
||||
public static UTKAlert ShowSuccess(VisualElement parent, string title, string message, Action? onClose = null)
|
||||
public static UTKAlert ShowSuccess(VisualElement parent, string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return Show(parent, title, message, AlertType.Success, onClose);
|
||||
return Show(parent, title, message, AlertType.Success, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warning 알림 표시
|
||||
/// </summary>
|
||||
public static UTKAlert ShowWarning(VisualElement parent, string title, string message, Action? onClose = null)
|
||||
public static UTKAlert ShowWarning(VisualElement parent, string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return Show(parent, title, message, AlertType.Warning, onClose);
|
||||
return Show(parent, title, message, AlertType.Warning, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error 알림 표시
|
||||
/// </summary>
|
||||
public static UTKAlert ShowError(VisualElement parent, string title, string message, Action? onClose = null)
|
||||
public static UTKAlert ShowError(VisualElement parent, string title, string message, Action? onClose = null, bool closeOnBlockerClick = false, string confirmLabel = "OK")
|
||||
{
|
||||
return Show(parent, title, message, AlertType.Error, onClose);
|
||||
return Show(parent, title, message, AlertType.Error, onClose, closeOnBlockerClick, confirmLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm 대화상자 표시
|
||||
/// </summary>
|
||||
public static UTKAlert ShowConfirm(VisualElement parent, string title, string message, Action? onConfirm, Action? onCancel = null)
|
||||
public static UTKAlert ShowConfirm(VisualElement parent, string title, string message, Action? onConfirm, Action? onCancel = null, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
var alert = Show(parent, title, message, AlertType.Confirm, null);
|
||||
var alert = Show(parent, title, message, AlertType.Confirm, null, closeOnBlockerClick, confirmLabel, cancelLabel);
|
||||
alert.OnConfirm = onConfirm;
|
||||
alert.OnCancel = onCancel;
|
||||
return alert;
|
||||
@@ -163,13 +358,32 @@ namespace UVC.UIToolkit
|
||||
/// <summary>
|
||||
/// 알림 표시
|
||||
/// </summary>
|
||||
public static UTKAlert Show(VisualElement parent, string title, string message, AlertType type, Action? onClose)
|
||||
/// <param name="parent">부모 요소</param>
|
||||
/// <param name="title">제목</param>
|
||||
/// <param name="message">메시지</param>
|
||||
/// <param name="type">알림 유형</param>
|
||||
/// <param name="onClose">닫힘 콜백</param>
|
||||
/// <param name="closeOnBlockerClick">배경 클릭 시 닫힘 여부</param>
|
||||
/// <param name="confirmLabel">확인 버튼 레이블</param>
|
||||
/// <param name="cancelLabel">취소 버튼 레이블 (Confirm 타입에서만 사용)</param>
|
||||
public static UTKAlert Show(VisualElement parent, string title, string message, AlertType type, Action? onClose, bool closeOnBlockerClick = false, string confirmLabel = "OK", string cancelLabel = "Cancel")
|
||||
{
|
||||
var alert = new UTKAlert(title, message, type);
|
||||
alert.OnClosed = onClose;
|
||||
alert._confirmLabel = confirmLabel;
|
||||
alert._cancelLabel = cancelLabel;
|
||||
alert.UpdateButtons();
|
||||
|
||||
alert._blocker = UTKModalBlocker.Show(parent, 0.5f, true);
|
||||
alert._blocker.OnBlockerClicked += alert.Close;
|
||||
alert._blocker = UTKModalBlocker.Show(parent, 0.5f, closeOnBlockerClick);
|
||||
if (closeOnBlockerClick)
|
||||
{
|
||||
alert._blocker.OnBlockerClicked += alert.Close;
|
||||
}
|
||||
else
|
||||
{
|
||||
// closeOnBlockerClick이 false일 때 blocker 클릭 시 Alert로 포커스 유지
|
||||
alert._blocker.OnBlockerClicked += () => alert.Focus();
|
||||
}
|
||||
alert._blocker.Add(alert);
|
||||
|
||||
// 중앙 정렬
|
||||
@@ -178,6 +392,13 @@ namespace UVC.UIToolkit
|
||||
alert.style.top = Length.Percent(50);
|
||||
alert.style.translate = new Translate(Length.Percent(-50), Length.Percent(-50));
|
||||
|
||||
// ESC 키 이벤트 등록
|
||||
alert.RegisterEscapeKey(parent);
|
||||
|
||||
// Alert에 포커스 설정 (키보드 이벤트 수신을 위해)
|
||||
alert.focusable = true;
|
||||
alert.schedule.Execute(() => alert.Focus());
|
||||
|
||||
return alert;
|
||||
}
|
||||
#endregion
|
||||
@@ -187,26 +408,21 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
AddToClassList("utk-alert");
|
||||
|
||||
_iconContainer = new VisualElement { name = "icon-container" };
|
||||
_iconContainer.AddToClassList("utk-alert__icon-container");
|
||||
Add(_iconContainer);
|
||||
|
||||
_iconLabel = new Label { name = "icon" };
|
||||
_iconLabel.AddToClassList("utk-alert__icon");
|
||||
_iconContainer.Add(_iconLabel);
|
||||
// Title (상단 왼쪽)
|
||||
_titleLabel = new Label { name = "title" };
|
||||
_titleLabel.AddToClassList("utk-alert__title");
|
||||
Add(_titleLabel);
|
||||
|
||||
// Content (가운데 메시지)
|
||||
var contentContainer = new VisualElement { name = "content" };
|
||||
contentContainer.AddToClassList("utk-alert__content");
|
||||
Add(contentContainer);
|
||||
|
||||
_titleLabel = new Label { name = "title" };
|
||||
_titleLabel.AddToClassList("utk-alert__title");
|
||||
contentContainer.Add(_titleLabel);
|
||||
|
||||
_messageLabel = new Label { name = "message" };
|
||||
_messageLabel.AddToClassList("utk-alert__message");
|
||||
contentContainer.Add(_messageLabel);
|
||||
|
||||
// Buttons
|
||||
_buttonContainer = new VisualElement { name = "buttons" };
|
||||
_buttonContainer.AddToClassList("utk-alert__buttons");
|
||||
Add(_buttonContainer);
|
||||
@@ -248,19 +464,6 @@ namespace UVC.UIToolkit
|
||||
};
|
||||
AddToClassList(typeClass);
|
||||
|
||||
// 아이콘 업데이트
|
||||
if (_iconLabel != null)
|
||||
{
|
||||
_iconLabel.text = _alertType switch
|
||||
{
|
||||
AlertType.Success => "✓",
|
||||
AlertType.Warning => "⚠",
|
||||
AlertType.Error => "✕",
|
||||
AlertType.Confirm => "?",
|
||||
_ => "ℹ"
|
||||
};
|
||||
}
|
||||
|
||||
// 버튼 업데이트
|
||||
UpdateButtons();
|
||||
}
|
||||
@@ -273,7 +476,7 @@ namespace UVC.UIToolkit
|
||||
|
||||
if (_alertType == AlertType.Confirm)
|
||||
{
|
||||
var cancelBtn = new UTKButton("Cancel", "", UTKButton.ButtonVariant.Normal);
|
||||
var cancelBtn = new UTKButton(_cancelLabel, "", UTKButton.ButtonVariant.Normal);
|
||||
cancelBtn.AddToClassList("utk-alert__btn");
|
||||
cancelBtn.OnClicked += () =>
|
||||
{
|
||||
@@ -282,7 +485,7 @@ namespace UVC.UIToolkit
|
||||
};
|
||||
_buttonContainer.Add(cancelBtn);
|
||||
|
||||
var confirmBtn = new UTKButton("OK", "", UTKButton.ButtonVariant.Primary);
|
||||
var confirmBtn = new UTKButton(_confirmLabel, "", UTKButton.ButtonVariant.Primary);
|
||||
confirmBtn.AddToClassList("utk-alert__btn");
|
||||
confirmBtn.OnClicked += () =>
|
||||
{
|
||||
@@ -293,18 +496,64 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
else
|
||||
{
|
||||
var okBtn = new UTKButton("OK", "", UTKButton.ButtonVariant.Primary);
|
||||
var okBtn = new UTKButton(_confirmLabel, "", UTKButton.ButtonVariant.Primary);
|
||||
okBtn.AddToClassList("utk-alert__btn");
|
||||
okBtn.OnClicked += Close;
|
||||
_buttonContainer.Add(okBtn);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ESC 키 이벤트 등록
|
||||
/// </summary>
|
||||
private void RegisterEscapeKey(VisualElement parent)
|
||||
{
|
||||
_keyEventTarget = parent;
|
||||
_keyDownCallback = evt =>
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Escape)
|
||||
{
|
||||
evt.StopPropagation();
|
||||
HandleEscapeKey();
|
||||
}
|
||||
};
|
||||
|
||||
// 패널에 키 이벤트 등록 (포커스와 관계없이 캡처)
|
||||
_keyEventTarget.RegisterCallback(_keyDownCallback, TrickleDown.TrickleDown);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ESC 키 해제
|
||||
/// </summary>
|
||||
private void UnregisterEscapeKey()
|
||||
{
|
||||
if (_keyDownCallback != null && _keyEventTarget != null)
|
||||
{
|
||||
_keyEventTarget.UnregisterCallback(_keyDownCallback, TrickleDown.TrickleDown);
|
||||
_keyDownCallback = null;
|
||||
_keyEventTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ESC 키 처리
|
||||
/// </summary>
|
||||
private void HandleEscapeKey()
|
||||
{
|
||||
if (_alertType == AlertType.Confirm)
|
||||
{
|
||||
// Confirm 타입: 취소 처리
|
||||
OnCancel?.Invoke();
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 알림 닫기
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
UnregisterEscapeKey();
|
||||
OnClosed?.Invoke();
|
||||
if (_blocker != null)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,36 @@ namespace UVC.UIToolkit.Modal
|
||||
/// UIToolkit 기반 컬러 피커 모달
|
||||
/// HSV 색공간 + RGB 슬라이더 + Hex 입력 지원
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // 기본 사용법 (Alpha 포함)
|
||||
/// var picker = UTKColorPicker.Show(rootVisualElement, Color.red, "Select Color");
|
||||
/// picker.OnColorChanged += (color) =>
|
||||
/// {
|
||||
/// // 실시간 색상 변경 시 호출
|
||||
/// Debug.Log($"Color changing: {color}");
|
||||
/// };
|
||||
/// picker.OnColorSelected += (color) =>
|
||||
/// {
|
||||
/// // OK 버튼 클릭 시 호출
|
||||
/// Debug.Log($"Color selected: #{ColorUtility.ToHtmlStringRGBA(color)}");
|
||||
/// };
|
||||
///
|
||||
/// // Alpha 없이 사용
|
||||
/// var pickerNoAlpha = UTKColorPicker.Show(rootVisualElement, Color.blue, "Select Color", useAlpha: false);
|
||||
///
|
||||
/// // async/await 사용법 (UniTask)
|
||||
/// Color selectedColor = await UTKColorPicker.ShowAsync(rootVisualElement, Color.red, "Select Color");
|
||||
/// // OK 클릭 시 선택된 색상 반환, 취소/닫기 시 initialColor(Color.red) 반환
|
||||
/// Debug.Log($"Result: #{ColorUtility.ToHtmlStringRGBA(selectedColor)}");
|
||||
///
|
||||
/// // 인스턴스 직접 생성
|
||||
/// var colorPicker = new UTKColorPicker();
|
||||
/// colorPicker.UseAlpha = true; // Alpha 슬라이더 표시 여부 (기본값: true)
|
||||
/// colorPicker.SetColor(Color.green);
|
||||
/// container.Add(colorPicker);
|
||||
/// </code>
|
||||
/// </example>
|
||||
[UxmlElement]
|
||||
public partial class UTKColorPicker : VisualElement, IDisposable
|
||||
{
|
||||
@@ -22,7 +52,7 @@ namespace UVC.UIToolkit.Modal
|
||||
|
||||
#region Fields
|
||||
private bool _disposed;
|
||||
private bool _useAlpha;
|
||||
private bool _useAlpha = true;
|
||||
private bool _isUpdating; // 재귀 업데이트 방지
|
||||
|
||||
private Color _originalColor = Color.white;
|
||||
@@ -61,9 +91,15 @@ namespace UVC.UIToolkit.Modal
|
||||
|
||||
private Label? _titleLabel;
|
||||
private Button? _closeButton;
|
||||
private Button? _cancelButton;
|
||||
private Button? _confirmButton;
|
||||
private UTKButton? _cancelButton;
|
||||
private UTKButton? _confirmButton;
|
||||
private VisualElement? _alphaRow;
|
||||
private VisualElement? _header;
|
||||
|
||||
// 드래그 관련 필드
|
||||
private bool _isDragging;
|
||||
private Vector2 _dragStartPosition;
|
||||
private Vector2 _dragStartMousePosition;
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
@@ -77,6 +113,23 @@ namespace UVC.UIToolkit.Modal
|
||||
public event Action? OnClosed;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// 알파(투명도) 값을 다룰지 여부 (기본값: true)
|
||||
/// </summary>
|
||||
[UxmlAttribute]
|
||||
public bool UseAlpha
|
||||
{
|
||||
get => _useAlpha;
|
||||
set
|
||||
{
|
||||
_useAlpha = value;
|
||||
SetAlphaVisible(value);
|
||||
UpdateHexField();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public UTKColorPicker()
|
||||
{
|
||||
@@ -152,7 +205,7 @@ namespace UVC.UIToolkit.Modal
|
||||
VisualElement parent,
|
||||
Color initialColor,
|
||||
string title = "Color Picker",
|
||||
bool useAlpha = false)
|
||||
bool useAlpha = true)
|
||||
{
|
||||
var picker = new UTKColorPicker();
|
||||
picker._useAlpha = useAlpha;
|
||||
@@ -175,6 +228,41 @@ namespace UVC.UIToolkit.Modal
|
||||
|
||||
return picker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 컬러 피커를 표시하고 색상 선택을 기다립니다.
|
||||
/// OK 버튼 클릭 시 선택된 색상을 반환하고, 취소/닫기 시 initialColor를 반환합니다.
|
||||
/// </summary>
|
||||
/// <param name="parent">부모 VisualElement</param>
|
||||
/// <param name="initialColor">초기 색상</param>
|
||||
/// <param name="title">피커 제목</param>
|
||||
/// <param name="useAlpha">알파 채널 사용 여부</param>
|
||||
/// <returns>선택된 색상 또는 초기 색상</returns>
|
||||
public static async UniTask<Color> ShowAsync(
|
||||
VisualElement parent,
|
||||
Color initialColor,
|
||||
string title = "Color Picker",
|
||||
bool useAlpha = true)
|
||||
{
|
||||
var tcs = new UniTaskCompletionSource<Color>();
|
||||
Color resultColor = initialColor;
|
||||
|
||||
var picker = Show(parent, initialColor, title, useAlpha);
|
||||
|
||||
picker.OnColorSelected += (color) =>
|
||||
{
|
||||
resultColor = color;
|
||||
tcs.TrySetResult(resultColor);
|
||||
};
|
||||
|
||||
picker.OnClosed += () =>
|
||||
{
|
||||
// OnColorSelected가 먼저 호출된 경우 이미 완료됨
|
||||
tcs.TrySetResult(resultColor);
|
||||
};
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
@@ -222,8 +310,8 @@ namespace UVC.UIToolkit.Modal
|
||||
AddToClassList("utk-color-picker");
|
||||
|
||||
// Header
|
||||
var header = new VisualElement { name = "header" };
|
||||
header.AddToClassList("utk-color-picker__header");
|
||||
_header = new VisualElement { name = "header" };
|
||||
_header.AddToClassList("utk-color-picker__header");
|
||||
|
||||
_titleLabel = new Label("Color Picker") { name = "title" };
|
||||
_titleLabel.AddToClassList("utk-color-picker__title");
|
||||
@@ -231,9 +319,9 @@ namespace UVC.UIToolkit.Modal
|
||||
_closeButton = new Button { name = "close-btn", text = "\u2715" }; // ✕
|
||||
_closeButton.AddToClassList("utk-color-picker__close-btn");
|
||||
|
||||
header.Add(_titleLabel);
|
||||
header.Add(_closeButton);
|
||||
Add(header);
|
||||
_header.Add(_titleLabel);
|
||||
_header.Add(_closeButton);
|
||||
Add(_header);
|
||||
|
||||
// SV Box + Hue Bar row
|
||||
var colorArea = new VisualElement { name = "color-area" };
|
||||
@@ -309,10 +397,10 @@ namespace UVC.UIToolkit.Modal
|
||||
var buttonRow = new VisualElement { name = "button-row" };
|
||||
buttonRow.AddToClassList("utk-color-picker__button-row");
|
||||
|
||||
_cancelButton = new Button { name = "cancel-btn", text = "Cancel" };
|
||||
_cancelButton = new UTKButton("Cancel", "", UTKButton.ButtonVariant.Normal) { name = "cancel-btn" };
|
||||
_cancelButton.AddToClassList("utk-color-picker__cancel-btn");
|
||||
|
||||
_confirmButton = new Button { name = "confirm-btn", text = "OK" };
|
||||
_confirmButton = new UTKButton("OK", "", UTKButton.ButtonVariant.Primary) { name = "confirm-btn" };
|
||||
_confirmButton.AddToClassList("utk-color-picker__confirm-btn");
|
||||
|
||||
buttonRow.Add(_cancelButton);
|
||||
@@ -362,17 +450,35 @@ namespace UVC.UIToolkit.Modal
|
||||
|
||||
_titleLabel ??= this.Q<Label>("title");
|
||||
_closeButton ??= this.Q<Button>("close-btn");
|
||||
_cancelButton ??= this.Q<Button>("cancel-btn");
|
||||
_confirmButton ??= this.Q<Button>("confirm-btn");
|
||||
_cancelButton ??= this.Q<UTKButton>("cancel-btn");
|
||||
_confirmButton ??= this.Q<UTKButton>("confirm-btn");
|
||||
_alphaRow ??= this.Q<VisualElement>("row-a");
|
||||
}
|
||||
|
||||
private void SetupEvents()
|
||||
{
|
||||
// Close/Cancel/Confirm buttons
|
||||
_closeButton?.RegisterCallback<ClickEvent>(_ => Cancel());
|
||||
_cancelButton?.RegisterCallback<ClickEvent>(_ => Cancel());
|
||||
_confirmButton?.RegisterCallback<ClickEvent>(_ => Confirm());
|
||||
_closeButton?.RegisterCallback<ClickEvent>(evt =>
|
||||
{
|
||||
Cancel();
|
||||
evt.StopPropagation();
|
||||
});
|
||||
|
||||
if (_cancelButton != null)
|
||||
{
|
||||
_cancelButton.OnClicked += () =>
|
||||
{
|
||||
Cancel();
|
||||
};
|
||||
}
|
||||
|
||||
if (_confirmButton != null)
|
||||
{
|
||||
_confirmButton.OnClicked += () =>
|
||||
{
|
||||
Confirm();
|
||||
};
|
||||
}
|
||||
|
||||
// SV Box interaction
|
||||
_svBox?.RegisterCallback<PointerDownEvent>(OnSVBoxPointerDown);
|
||||
@@ -401,6 +507,11 @@ namespace UVC.UIToolkit.Modal
|
||||
|
||||
// Original preview click - 원래 색상으로 복원
|
||||
_previewOriginal?.RegisterCallback<ClickEvent>(_ => SetColor(_originalColor));
|
||||
|
||||
// Header drag events
|
||||
_header?.RegisterCallback<PointerDownEvent>(OnHeaderPointerDown);
|
||||
_header?.RegisterCallback<PointerMoveEvent>(OnHeaderPointerMove);
|
||||
_header?.RegisterCallback<PointerUpEvent>(OnHeaderPointerUp);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -408,6 +519,38 @@ namespace UVC.UIToolkit.Modal
|
||||
private bool _svDragging;
|
||||
private bool _hueDragging;
|
||||
|
||||
private void OnHeaderPointerDown(PointerDownEvent evt)
|
||||
{
|
||||
// 닫기 버튼 클릭은 무시
|
||||
if (evt.target == _closeButton) return;
|
||||
|
||||
_isDragging = true;
|
||||
_dragStartMousePosition = evt.position;
|
||||
_dragStartPosition = new Vector2(resolvedStyle.left, resolvedStyle.top);
|
||||
_header?.CapturePointer(evt.pointerId);
|
||||
evt.StopPropagation();
|
||||
}
|
||||
|
||||
private void OnHeaderPointerMove(PointerMoveEvent evt)
|
||||
{
|
||||
if (!_isDragging) return;
|
||||
|
||||
Vector2 delta = (Vector2)evt.position - _dragStartMousePosition;
|
||||
style.left = _dragStartPosition.x + delta.x;
|
||||
style.top = _dragStartPosition.y + delta.y;
|
||||
evt.StopPropagation();
|
||||
}
|
||||
|
||||
private void OnHeaderPointerUp(PointerUpEvent evt)
|
||||
{
|
||||
if (_isDragging)
|
||||
{
|
||||
_isDragging = false;
|
||||
_header?.ReleasePointer(evt.pointerId);
|
||||
evt.StopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSVBoxPointerDown(PointerDownEvent evt)
|
||||
{
|
||||
if (_hueDragging) return; // Hue 드래그 중이면 무시
|
||||
@@ -802,8 +945,10 @@ namespace UVC.UIToolkit.Modal
|
||||
{
|
||||
if (_hexField == null) return;
|
||||
|
||||
// 항상 RGBA 형식 (알파값 포함)
|
||||
_hexField.value = ColorUtility.ToHtmlStringRGBA(_currentColor);
|
||||
// UseAlpha에 따라 RGBA(8자리) 또는 RGB(6자리) 형식으로 표시
|
||||
_hexField.value = _useAlpha
|
||||
? ColorUtility.ToHtmlStringRGBA(_currentColor)
|
||||
: ColorUtility.ToHtmlStringRGB(_currentColor);
|
||||
}
|
||||
|
||||
private void UpdateIndicators()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.Locale;
|
||||
@@ -12,6 +13,57 @@ namespace UVC.UIToolkit.Modal
|
||||
/// UIToolkit 기반 날짜/시간 피커 모달
|
||||
/// 캘린더 그리드 + 시간 선택 지원
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // 기본 사용법 (날짜만)
|
||||
/// var picker = UTKDatePicker.Show(rootVisualElement, DateTime.Today, UTKDatePicker.PickerMode.DateOnly, "Select Date");
|
||||
/// picker.OnDateSelected += (date) =>
|
||||
/// {
|
||||
/// Debug.Log($"Date selected: {date:yyyy-MM-dd}");
|
||||
/// };
|
||||
///
|
||||
/// // 날짜 + 시간 선택
|
||||
/// var dateTimePicker = UTKDatePicker.Show(rootVisualElement, DateTime.Now, UTKDatePicker.PickerMode.DateAndTime, "Select Date & Time");
|
||||
/// dateTimePicker.OnDateSelected += (date) =>
|
||||
/// {
|
||||
/// Debug.Log($"DateTime selected: {date:yyyy-MM-dd HH:mm}");
|
||||
/// };
|
||||
///
|
||||
/// // async/await 사용법 (UniTask)
|
||||
/// DateTime? selectedDate = await UTKDatePicker.ShowAsync(rootVisualElement, DateTime.Today);
|
||||
/// if (selectedDate.HasValue)
|
||||
/// {
|
||||
/// Debug.Log($"Selected: {selectedDate.Value:yyyy-MM-dd}");
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// Debug.Log("Cancelled");
|
||||
/// }
|
||||
///
|
||||
/// // 날짜 범위 선택
|
||||
/// var rangePicker = UTKDatePicker.ShowRange(rootVisualElement, DateTime.Today, DateTime.Today.AddDays(7));
|
||||
/// rangePicker.OnDateRangeSelected += (start, end) =>
|
||||
/// {
|
||||
/// Debug.Log($"Range selected: {start:yyyy-MM-dd} ~ {end:yyyy-MM-dd}");
|
||||
/// };
|
||||
///
|
||||
/// // 날짜 범위 async/await 사용법
|
||||
/// var result = await UTKDatePicker.ShowRangeAsync(rootVisualElement, DateTime.Today, DateTime.Today.AddDays(7));
|
||||
/// if (result.HasValue)
|
||||
/// {
|
||||
/// Debug.Log($"Range: {result.Value.Start:yyyy-MM-dd} ~ {result.Value.End:yyyy-MM-dd}");
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// Debug.Log("Cancelled");
|
||||
/// }
|
||||
///
|
||||
/// // 인스턴스 직접 생성
|
||||
/// var datePicker = new UTKDatePicker();
|
||||
/// datePicker.SetDate(DateTime.Today);
|
||||
/// container.Add(datePicker);
|
||||
/// </code>
|
||||
/// </example>
|
||||
[UxmlElement]
|
||||
public partial class UTKDatePicker : VisualElement, IDisposable
|
||||
{
|
||||
@@ -19,7 +71,18 @@ namespace UVC.UIToolkit.Modal
|
||||
public enum PickerMode
|
||||
{
|
||||
DateOnly,
|
||||
DateAndTime
|
||||
DateAndTime,
|
||||
DateRange,
|
||||
DateTimeRange
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 범위 선택 시 현재 선택 중인 날짜 타입
|
||||
/// </summary>
|
||||
private enum RangeSelectionState
|
||||
{
|
||||
SelectingStart,
|
||||
SelectingEnd
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -36,9 +99,17 @@ namespace UVC.UIToolkit.Modal
|
||||
private DateTime _selectedDate = DateTime.Today;
|
||||
private DateTime _displayMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||||
|
||||
// 범위 선택 관련 필드
|
||||
private DateTime? _rangeStartDate;
|
||||
private DateTime? _rangeEndDate;
|
||||
private RangeSelectionState _rangeState = RangeSelectionState.SelectingStart;
|
||||
|
||||
private UTKModalBlocker? _blocker;
|
||||
private readonly List<Button> _dayButtons = new();
|
||||
|
||||
// 범위 선택 UI 요소
|
||||
private Label? _rangeInfoLabel;
|
||||
|
||||
// UI 요소
|
||||
private Label? _titleLabel;
|
||||
private Button? _closeButton;
|
||||
@@ -51,14 +122,17 @@ namespace UVC.UIToolkit.Modal
|
||||
private VisualElement? _timeRow;
|
||||
private UTKNumberStepper? _hourStepper;
|
||||
private UTKNumberStepper? _minuteStepper;
|
||||
private Button? _cancelButton;
|
||||
private Button? _confirmButton;
|
||||
private UTKButton? _cancelButton;
|
||||
private UTKButton? _confirmButton;
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
/// <summary>날짜가 선택되었을 때 발생</summary>
|
||||
public event Action<DateTime>? OnDateSelected;
|
||||
|
||||
/// <summary>날짜 범위가 선택되었을 때 발생 (시작일, 종료일)</summary>
|
||||
public event Action<DateTime, DateTime>? OnDateRangeSelected;
|
||||
|
||||
/// <summary>피커가 닫힐 때 발생</summary>
|
||||
public event Action? OnClosed;
|
||||
#endregion
|
||||
@@ -142,6 +216,155 @@ namespace UVC.UIToolkit.Modal
|
||||
|
||||
return picker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 날짜 피커를 표시하고 날짜 선택을 기다립니다.
|
||||
/// OK 버튼 클릭 시 선택된 날짜를 반환하고, 취소/닫기 시 null을 반환합니다.
|
||||
/// </summary>
|
||||
/// <param name="parent">부모 VisualElement</param>
|
||||
/// <param name="initialDate">초기 날짜</param>
|
||||
/// <param name="mode">피커 모드 (날짜만 또는 날짜+시간)</param>
|
||||
/// <param name="title">피커 제목</param>
|
||||
/// <returns>선택된 날짜 또는 null (취소 시)</returns>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // async/await 사용법
|
||||
/// DateTime? selectedDate = await UTKDatePicker.ShowAsync(rootVisualElement, DateTime.Today);
|
||||
/// if (selectedDate.HasValue)
|
||||
/// {
|
||||
/// Debug.Log($"Selected: {selectedDate.Value:yyyy-MM-dd}");
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// Debug.Log("Cancelled");
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static async UniTask<DateTime?> ShowAsync(
|
||||
VisualElement parent,
|
||||
DateTime initialDate,
|
||||
PickerMode mode = PickerMode.DateOnly,
|
||||
string title = "Select Date")
|
||||
{
|
||||
var tcs = new UniTaskCompletionSource<DateTime?>();
|
||||
DateTime? resultDate = null;
|
||||
|
||||
var picker = Show(parent, initialDate, mode, title);
|
||||
|
||||
picker.OnDateSelected += (date) =>
|
||||
{
|
||||
resultDate = date;
|
||||
tcs.TrySetResult(resultDate);
|
||||
};
|
||||
|
||||
picker.OnClosed += () =>
|
||||
{
|
||||
// OnDateSelected가 먼저 호출된 경우 이미 완료됨
|
||||
tcs.TrySetResult(resultDate);
|
||||
};
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 날짜 범위 피커를 표시합니다.
|
||||
/// </summary>
|
||||
/// <param name="parent">부모 VisualElement</param>
|
||||
/// <param name="initialStartDate">초기 시작 날짜 (null이면 오늘)</param>
|
||||
/// <param name="initialEndDate">초기 종료 날짜 (null이면 시작 날짜와 동일)</param>
|
||||
/// <param name="includeTime">시간 선택 포함 여부</param>
|
||||
/// <param name="title">피커 제목</param>
|
||||
public static UTKDatePicker ShowRange(
|
||||
VisualElement parent,
|
||||
DateTime? initialStartDate = null,
|
||||
DateTime? initialEndDate = null,
|
||||
bool includeTime = false,
|
||||
string title = "Select Date Range")
|
||||
{
|
||||
var picker = new UTKDatePicker();
|
||||
picker._mode = includeTime ? PickerMode.DateTimeRange : PickerMode.DateRange;
|
||||
|
||||
var startDate = initialStartDate ?? DateTime.Today;
|
||||
var endDate = initialEndDate ?? startDate;
|
||||
|
||||
// 시작일이 종료일보다 늦으면 스왑
|
||||
if (startDate > endDate)
|
||||
{
|
||||
(startDate, endDate) = (endDate, startDate);
|
||||
}
|
||||
|
||||
picker._rangeStartDate = startDate;
|
||||
picker._rangeEndDate = endDate;
|
||||
picker._rangeState = RangeSelectionState.SelectingStart;
|
||||
picker._displayMonth = new DateTime(startDate.Year, startDate.Month, 1);
|
||||
|
||||
// 블로커 추가
|
||||
picker._blocker = UTKModalBlocker.Show(parent, 0.5f, false);
|
||||
picker._blocker.OnBlockerClicked += picker.Close;
|
||||
|
||||
// 피커 추가
|
||||
parent.Add(picker);
|
||||
|
||||
// UI 초기화
|
||||
picker.SetTitle(title);
|
||||
picker.SetTimeVisible(includeTime);
|
||||
picker.SetRangeInfoVisible(true);
|
||||
picker.UpdateRangeInfo();
|
||||
picker.UpdateCalendar();
|
||||
picker.CenterOnScreen();
|
||||
|
||||
return picker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 날짜 범위 피커를 표시하고 범위 선택을 기다립니다.
|
||||
/// OK 버튼 클릭 시 선택된 범위를 반환하고, 취소/닫기 시 null을 반환합니다.
|
||||
/// </summary>
|
||||
/// <param name="parent">부모 VisualElement</param>
|
||||
/// <param name="initialStartDate">초기 시작 날짜</param>
|
||||
/// <param name="initialEndDate">초기 종료 날짜</param>
|
||||
/// <param name="includeTime">시간 선택 포함 여부</param>
|
||||
/// <param name="title">피커 제목</param>
|
||||
/// <returns>선택된 범위 (시작일, 종료일) 또는 null (취소 시)</returns>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // async/await 사용법
|
||||
/// var result = await UTKDatePicker.ShowRangeAsync(rootVisualElement);
|
||||
/// if (result.HasValue)
|
||||
/// {
|
||||
/// Debug.Log($"Range: {result.Value.Start:yyyy-MM-dd} ~ {result.Value.End:yyyy-MM-dd}");
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// Debug.Log("Cancelled");
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static async UniTask<(DateTime Start, DateTime End)?> ShowRangeAsync(
|
||||
VisualElement parent,
|
||||
DateTime? initialStartDate = null,
|
||||
DateTime? initialEndDate = null,
|
||||
bool includeTime = false,
|
||||
string title = "Select Date Range")
|
||||
{
|
||||
var tcs = new UniTaskCompletionSource<(DateTime, DateTime)?>();
|
||||
(DateTime, DateTime)? result = null;
|
||||
|
||||
var picker = ShowRange(parent, initialStartDate, initialEndDate, includeTime, title);
|
||||
|
||||
picker.OnDateRangeSelected += (start, end) =>
|
||||
{
|
||||
result = (start, end);
|
||||
tcs.TrySetResult(result);
|
||||
};
|
||||
|
||||
picker.OnClosed += () =>
|
||||
{
|
||||
tcs.TrySetResult(result);
|
||||
};
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
@@ -304,14 +527,20 @@ namespace UVC.UIToolkit.Modal
|
||||
_timeRow.Add(_minuteStepper);
|
||||
Add(_timeRow);
|
||||
|
||||
// Range Info Label (범위 선택 시 시작일/종료일 표시)
|
||||
_rangeInfoLabel = new Label { name = "range-info" };
|
||||
_rangeInfoLabel.AddToClassList("utk-date-picker__range-info");
|
||||
_rangeInfoLabel.style.display = DisplayStyle.None;
|
||||
Add(_rangeInfoLabel);
|
||||
|
||||
// Buttons
|
||||
var buttonRow = new VisualElement { name = "button-row" };
|
||||
buttonRow.AddToClassList("utk-date-picker__button-row");
|
||||
|
||||
_cancelButton = new Button { name = "cancel-btn", text = "Cancel" };
|
||||
_cancelButton = new UTKButton("Cancel", "", UTKButton.ButtonVariant.Normal) { name = "cancel-btn" };
|
||||
_cancelButton.AddToClassList("utk-date-picker__cancel-btn");
|
||||
|
||||
_confirmButton = new Button { name = "confirm-btn", text = "OK" };
|
||||
_confirmButton = new UTKButton("OK", "", UTKButton.ButtonVariant.Primary) { name = "confirm-btn" };
|
||||
_confirmButton.AddToClassList("utk-date-picker__confirm-btn");
|
||||
|
||||
buttonRow.Add(_cancelButton);
|
||||
@@ -339,8 +568,9 @@ namespace UVC.UIToolkit.Modal
|
||||
_timeRow ??= this.Q<VisualElement>("time-row");
|
||||
_hourStepper ??= this.Q<UTKNumberStepper>("hour-stepper");
|
||||
_minuteStepper ??= this.Q<UTKNumberStepper>("minute-stepper");
|
||||
_cancelButton ??= this.Q<Button>("cancel-btn");
|
||||
_confirmButton ??= this.Q<Button>("confirm-btn");
|
||||
_cancelButton ??= this.Q<UTKButton>("cancel-btn");
|
||||
_confirmButton ??= this.Q<UTKButton>("confirm-btn");
|
||||
_rangeInfoLabel ??= this.Q<Label>("range-info");
|
||||
|
||||
// Day buttons 쿼리
|
||||
if (_dayButtons.Count == 0)
|
||||
@@ -361,8 +591,8 @@ namespace UVC.UIToolkit.Modal
|
||||
private void SetupEvents()
|
||||
{
|
||||
_closeButton?.RegisterCallback<ClickEvent>(_ => Close());
|
||||
_cancelButton?.RegisterCallback<ClickEvent>(_ => Close());
|
||||
_confirmButton?.RegisterCallback<ClickEvent>(_ => Confirm());
|
||||
if (_cancelButton != null) _cancelButton.OnClicked += Close;
|
||||
if (_confirmButton != null) _confirmButton.OnClicked += Confirm;
|
||||
|
||||
_prevYearButton?.RegisterCallback<ClickEvent>(_ => PreviousYear());
|
||||
_prevMonthButton?.RegisterCallback<ClickEvent>(_ => PreviousMonth());
|
||||
@@ -426,6 +656,9 @@ namespace UVC.UIToolkit.Modal
|
||||
btn.RemoveFromClassList("utk-date-picker__day-btn--today");
|
||||
btn.RemoveFromClassList("utk-date-picker__day-btn--selected");
|
||||
btn.RemoveFromClassList("utk-date-picker__day-btn--other-month");
|
||||
btn.RemoveFromClassList("utk-date-picker__day-btn--range-start");
|
||||
btn.RemoveFromClassList("utk-date-picker__day-btn--range-end");
|
||||
btn.RemoveFromClassList("utk-date-picker__day-btn--in-range");
|
||||
|
||||
int dayNumber = i - startDayOfWeek + 1;
|
||||
|
||||
@@ -444,34 +677,76 @@ namespace UVC.UIToolkit.Modal
|
||||
DateTime currentDate = new DateTime(_displayMonth.Year, _displayMonth.Month, dayNumber);
|
||||
DayOfWeek dow = currentDate.DayOfWeek;
|
||||
|
||||
// 선택된 날짜인지 확인
|
||||
bool isSelected = currentDate.Date == _selectedDate.Date;
|
||||
|
||||
// 오늘인지 확인
|
||||
bool isToday = currentDate.Date == today;
|
||||
|
||||
// 선택 상태 클래스
|
||||
if (isSelected)
|
||||
// 범위 선택 모드 처리
|
||||
if (IsRangeMode)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--selected");
|
||||
}
|
||||
bool isRangeStart = _rangeStartDate.HasValue && currentDate.Date == _rangeStartDate.Value.Date;
|
||||
bool isRangeEnd = _rangeEndDate.HasValue && currentDate.Date == _rangeEndDate.Value.Date;
|
||||
bool isInRange = _rangeStartDate.HasValue && _rangeEndDate.HasValue &&
|
||||
currentDate.Date > _rangeStartDate.Value.Date &&
|
||||
currentDate.Date < _rangeEndDate.Value.Date;
|
||||
|
||||
// 오늘 클래스 (선택되지 않은 경우에만)
|
||||
if (isToday && !isSelected)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--today");
|
||||
}
|
||||
|
||||
// 요일별 클래스 (선택되지 않은 경우에만)
|
||||
if (!isSelected)
|
||||
{
|
||||
if (dow == DayOfWeek.Sunday)
|
||||
if (isRangeStart)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--sunday");
|
||||
btn.AddToClassList("utk-date-picker__day-btn--range-start");
|
||||
}
|
||||
else if (dow == DayOfWeek.Saturday)
|
||||
|
||||
if (isRangeEnd)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--saturday");
|
||||
btn.AddToClassList("utk-date-picker__day-btn--range-end");
|
||||
}
|
||||
|
||||
if (isInRange)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--in-range");
|
||||
}
|
||||
|
||||
// 오늘 클래스 (범위에 포함되지 않은 경우에만)
|
||||
bool isToday = currentDate.Date == today;
|
||||
if (isToday && !isRangeStart && !isRangeEnd && !isInRange)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--today");
|
||||
}
|
||||
|
||||
// 요일별 클래스 (범위에 포함되지 않은 경우에만)
|
||||
if (!isRangeStart && !isRangeEnd && !isInRange)
|
||||
{
|
||||
if (dow == DayOfWeek.Sunday)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--sunday");
|
||||
}
|
||||
else if (dow == DayOfWeek.Saturday)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--saturday");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 단일 날짜 선택 모드
|
||||
bool isSelected = currentDate.Date == _selectedDate.Date;
|
||||
bool isToday = currentDate.Date == today;
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--selected");
|
||||
}
|
||||
|
||||
if (isToday && !isSelected)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--today");
|
||||
}
|
||||
|
||||
if (!isSelected)
|
||||
{
|
||||
if (dow == DayOfWeek.Sunday)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--sunday");
|
||||
}
|
||||
else if (dow == DayOfWeek.Saturday)
|
||||
{
|
||||
btn.AddToClassList("utk-date-picker__day-btn--saturday");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -493,7 +768,7 @@ namespace UVC.UIToolkit.Modal
|
||||
int hour = _hourStepper?.Value ?? _selectedDate.Hour;
|
||||
int minute = _minuteStepper?.Value ?? _selectedDate.Minute;
|
||||
|
||||
_selectedDate = new DateTime(
|
||||
DateTime clickedDate = new DateTime(
|
||||
_displayMonth.Year,
|
||||
_displayMonth.Month,
|
||||
dayNumber,
|
||||
@@ -502,13 +777,63 @@ namespace UVC.UIToolkit.Modal
|
||||
0
|
||||
);
|
||||
|
||||
if (IsRangeMode)
|
||||
{
|
||||
// 범위 선택 모드
|
||||
if (_rangeState == RangeSelectionState.SelectingStart)
|
||||
{
|
||||
// 시작일 선택
|
||||
_rangeStartDate = clickedDate;
|
||||
_rangeEndDate = null;
|
||||
_rangeState = RangeSelectionState.SelectingEnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 종료일 선택
|
||||
if (_rangeStartDate.HasValue && clickedDate < _rangeStartDate.Value)
|
||||
{
|
||||
// 클릭한 날짜가 시작일보다 이전이면 시작일로 설정하고 기존 시작일을 종료일로
|
||||
_rangeEndDate = _rangeStartDate;
|
||||
_rangeStartDate = clickedDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
_rangeEndDate = clickedDate;
|
||||
}
|
||||
_rangeState = RangeSelectionState.SelectingStart;
|
||||
}
|
||||
|
||||
UpdateRangeInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 단일 날짜 선택 모드
|
||||
_selectedDate = clickedDate;
|
||||
}
|
||||
|
||||
UpdateCalendar();
|
||||
}
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
OnDateSelected?.Invoke(GetDate());
|
||||
if (IsRangeMode)
|
||||
{
|
||||
// 범위 선택 모드
|
||||
if (_rangeStartDate.HasValue && _rangeEndDate.HasValue)
|
||||
{
|
||||
OnDateRangeSelected?.Invoke(_rangeStartDate.Value, _rangeEndDate.Value);
|
||||
}
|
||||
else if (_rangeStartDate.HasValue)
|
||||
{
|
||||
// 종료일이 없으면 시작일을 종료일로도 사용
|
||||
OnDateRangeSelected?.Invoke(_rangeStartDate.Value, _rangeStartDate.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDateSelected?.Invoke(GetDate());
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -549,6 +874,32 @@ namespace UVC.UIToolkit.Modal
|
||||
style.top = (parentHeight - selfHeight) / 2;
|
||||
});
|
||||
}
|
||||
|
||||
private void SetRangeInfoVisible(bool visible)
|
||||
{
|
||||
if (_rangeInfoLabel != null)
|
||||
{
|
||||
_rangeInfoLabel.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRangeInfo()
|
||||
{
|
||||
if (_rangeInfoLabel == null) return;
|
||||
|
||||
string startText = _rangeStartDate?.ToString("yyyy-MM-dd") ?? "---";
|
||||
string endText = _rangeEndDate?.ToString("yyyy-MM-dd") ?? "---";
|
||||
|
||||
string stateIndicator = _rangeState == RangeSelectionState.SelectingStart ? "▶ " : " ";
|
||||
string endStateIndicator = _rangeState == RangeSelectionState.SelectingEnd ? "▶ " : " ";
|
||||
|
||||
_rangeInfoLabel.text = $"{stateIndicator}시작: {startText} {endStateIndicator}종료: {endText}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 범위 선택 모드인지 확인
|
||||
/// </summary>
|
||||
private bool IsRangeMode => _mode == PickerMode.DateRange || _mode == PickerMode.DateTimeRange;
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
||||
@@ -15,12 +15,13 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
#region Constants
|
||||
private const string USS_PATH = "UIToolkit/Modal/UTKToast";
|
||||
private const int DEFAULT_DURATION_MS = 3000;
|
||||
private const int DEFAULT_DURATION_MS = 1000;
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private static VisualElement? _root;
|
||||
|
||||
private bool _disposed;
|
||||
private Label? _iconLabel;
|
||||
private Label? _messageLabel;
|
||||
private Button? _closeButton;
|
||||
|
||||
@@ -116,7 +117,78 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory
|
||||
#region Static Methods
|
||||
/// <summary>
|
||||
/// 기본 루트 요소 설정
|
||||
/// </summary>
|
||||
/// <param name="root">Toast를 표시할 기본 루트 요소</param>
|
||||
public static void SetRoot(VisualElement root)
|
||||
{
|
||||
_root = root;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 기본 루트 요소 반환
|
||||
/// </summary>
|
||||
public static VisualElement? GetRoot() => _root;
|
||||
|
||||
private static void ValidateRoot()
|
||||
{
|
||||
if (_root == null)
|
||||
{
|
||||
throw new InvalidOperationException("UTKToast.SetRoot()를 먼저 호출하여 기본 루트 요소를 설정해야 합니다.");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory (without parent)
|
||||
/// <summary>
|
||||
/// Info 토스트 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKToast ShowInfo(string message, int duration = DEFAULT_DURATION_MS)
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, message, ToastType.Info, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Success 토스트 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKToast ShowSuccess(string message, int duration = DEFAULT_DURATION_MS)
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, message, ToastType.Success, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warning 토스트 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKToast ShowWarning(string message, int duration = DEFAULT_DURATION_MS)
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, message, ToastType.Warning, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error 토스트 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKToast ShowError(string message, int duration = DEFAULT_DURATION_MS)
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, message, ToastType.Error, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 토스트 표시 (SetRoot로 설정된 루트 사용)
|
||||
/// </summary>
|
||||
public static UTKToast Show(string message, ToastType type = ToastType.Info, int duration = DEFAULT_DURATION_MS)
|
||||
{
|
||||
ValidateRoot();
|
||||
return Show(_root!, message, type, duration);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static Factory (with parent)
|
||||
/// <summary>
|
||||
/// Info 토스트 표시
|
||||
/// </summary>
|
||||
@@ -180,10 +252,6 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
AddToClassList("utk-toast");
|
||||
|
||||
_iconLabel = new Label { name = "icon" };
|
||||
_iconLabel.AddToClassList("utk-toast__icon");
|
||||
Add(_iconLabel);
|
||||
|
||||
_messageLabel = new Label { name = "message" };
|
||||
_messageLabel.AddToClassList("utk-toast__message");
|
||||
Add(_messageLabel);
|
||||
@@ -228,17 +296,6 @@ namespace UVC.UIToolkit
|
||||
_ => "utk-toast--info"
|
||||
};
|
||||
AddToClassList(typeClass);
|
||||
|
||||
if (_iconLabel != null)
|
||||
{
|
||||
_iconLabel.text = _type switch
|
||||
{
|
||||
ToastType.Success => "✓",
|
||||
ToastType.Warning => "⚠",
|
||||
ToastType.Error => "✕",
|
||||
_ => "ℹ"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTaskVoid AutoCloseAsync(int delayMs)
|
||||
|
||||
@@ -12,10 +12,6 @@ namespace UVC.UIToolkit
|
||||
[UxmlElement]
|
||||
public partial class UTKTab : Tab, IDisposable
|
||||
{
|
||||
#region Constants
|
||||
private const string USS_PATH = "UIToolkit/Tab/UTKTab";
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private bool _disposed;
|
||||
private bool _isEnabled = true;
|
||||
@@ -54,13 +50,6 @@ namespace UVC.UIToolkit
|
||||
public UTKTab() : base()
|
||||
{
|
||||
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
||||
|
||||
var uss = Resources.Load<StyleSheet>(USS_PATH);
|
||||
if (uss != null)
|
||||
{
|
||||
styleSheets.Add(uss);
|
||||
}
|
||||
|
||||
SetupStyles();
|
||||
SubscribeToThemeChanges();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user