mirror of
https://gitee.com/chinware/atomui.git
synced 2024-11-29 18:38:16 +08:00
完成基本日期功能
This commit is contained in:
parent
7b6fdac913
commit
b765f58c87
17
samples/AtomUI.Demo.Desktop/ShowCase/CalendarShowCase.axaml
Normal file
17
samples/AtomUI.Demo.Desktop/ShowCase/CalendarShowCase.axaml
Normal file
@ -0,0 +1,17 @@
|
||||
<UserControl
|
||||
x:Class="AtomUI.Demo.Desktop.ShowCase.CalendarShowCase"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:atom="https://atomui.net"
|
||||
xmlns:showcase="clr-namespace:AtomUI.Demo.Desktop.ShowCase"
|
||||
mc:Ignorable="d">
|
||||
<showcase:ShowCasePanel>
|
||||
<showcase:ShowCaseItem
|
||||
Title="Basic"
|
||||
Description="The simplest usage for Calendar.">
|
||||
<atom:Calendar/>
|
||||
</showcase:ShowCaseItem>
|
||||
</showcase:ShowCasePanel>
|
||||
</UserControl>
|
@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace AtomUI.Demo.Desktop.ShowCase;
|
||||
|
||||
public partial class CalendarShowCase : UserControl
|
||||
{
|
||||
public CalendarShowCase()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
@ -3,9 +3,11 @@
|
||||
// Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details.
|
||||
// All other rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme.Styling;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
@ -13,6 +15,7 @@ using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
@ -225,8 +228,8 @@ public class CalendarModeChangedEventArgs : RoutedEventArgs
|
||||
/// element in XAML.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[TemplatePart(PART_ElementMonth, typeof(CalendarItem))]
|
||||
[TemplatePart(PART_ElementRoot, typeof(Panel))]
|
||||
[TemplatePart(CalendarTheme.CalendarItemPart, typeof(CalendarItem))]
|
||||
[TemplatePart(CalendarTheme.RootPart, typeof(Panel))]
|
||||
public class Calendar : TemplatedControl
|
||||
{
|
||||
internal const int RowsPerMonth = 7;
|
||||
@ -1189,7 +1192,6 @@ public class Calendar : TemplatedControl
|
||||
if (!LastSelectedDate.HasValue || DateTimeHelper.CompareYearMonth(LastSelectedDate.Value, d.Value) != 0) {
|
||||
LastSelectedDate = d.Value;
|
||||
}
|
||||
|
||||
SetCurrentValue(DisplayDateProperty, d.Value);
|
||||
}
|
||||
} else {
|
||||
@ -1934,11 +1936,10 @@ public class Calendar : TemplatedControl
|
||||
BlackoutDates = new CalendarBlackoutDatesCollection(this);
|
||||
SelectedDates = new SelectedDatesCollection(this);
|
||||
RemovedItems = new Collection<DateTime>();
|
||||
HorizontalAlignmentProperty.OverrideDefaultValue<Calendar>(HorizontalAlignment.Left);
|
||||
VerticalAlignmentProperty.OverrideDefaultValue<Calendar>(VerticalAlignment.Top);
|
||||
}
|
||||
|
||||
private const string PART_ElementRoot = "PART_Root";
|
||||
private const string PART_ElementMonth = "PART_CalendarItem";
|
||||
|
||||
/// <summary>
|
||||
/// Builds the visual tree for the
|
||||
/// <see cref="T:System.Windows.Controls.Calendar" /> when a new
|
||||
@ -1946,17 +1947,25 @@ public class Calendar : TemplatedControl
|
||||
/// </summary>
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
Root = e.NameScope.Find<Panel>(PART_ElementRoot);
|
||||
Root = e.NameScope.Find<Panel>(CalendarTheme.RootPart);
|
||||
|
||||
SelectedMonth = DisplayDate;
|
||||
SelectedYear = DisplayDate;
|
||||
|
||||
if (Root != null) {
|
||||
CalendarItem? month = e.NameScope.Find<CalendarItem>(PART_ElementMonth);
|
||||
CalendarItem? month = e.NameScope.Find<CalendarItem>(CalendarTheme.CalendarItemPart);
|
||||
|
||||
if (month != null) {
|
||||
month.Owner = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
TokenResourceBinder.CreateGlobalTokenBinding(this, BorderThicknessProperty, GlobalTokenResourceKey.BorderThickness,
|
||||
BindingPriority.Template,
|
||||
new RenderScaleAwareThicknessConfigure(this));
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using AvaloniaButton = Avalonia.Controls.Button;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
@ -10,7 +11,7 @@ namespace AtomUI.Controls;
|
||||
/// <see cref="T:Avalonia.Controls.Calendar" />.
|
||||
/// </summary>
|
||||
[PseudoClasses(":selected", ":inactive", ":btnfocused")]
|
||||
public sealed class CalendarButton : Button
|
||||
internal sealed class CalendarButton : AvaloniaButton
|
||||
{
|
||||
/// <summary>
|
||||
/// A value indicating whether the button is focused.
|
||||
|
@ -3,12 +3,18 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using AvaloniaButton = Avalonia.Controls.Button;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
[PseudoClasses(":pressed", ":disabled", ":selected", ":inactive", ":today", ":blackout", ":dayfocused")]
|
||||
public sealed class CalendarDayButton : Button
|
||||
[PseudoClasses(StdPseudoClass.Pressed, StdPseudoClass.Disabled, StdPseudoClass.Selected, InactivePC, TodayPC, BlackoutPC, DayfocusedPC)]
|
||||
internal sealed class CalendarDayButton : AvaloniaButton
|
||||
{
|
||||
private const string InactivePC = ":inactive";
|
||||
private const string TodayPC = ":today";
|
||||
private const string BlackoutPC = ":blackout";
|
||||
private const string DayfocusedPC = ":dayfocused";
|
||||
|
||||
/// <summary>
|
||||
/// Default content for the CalendarDayButton.
|
||||
/// </summary>
|
||||
@ -27,7 +33,6 @@ public sealed class CalendarDayButton : Button
|
||||
/// class.
|
||||
/// </summary>
|
||||
public CalendarDayButton()
|
||||
: base()
|
||||
{
|
||||
//Focusable = false;
|
||||
SetCurrentValue(ContentProperty, DefaultContent.ToString(CultureInfo.CurrentCulture));
|
||||
@ -152,15 +157,15 @@ public sealed class CalendarDayButton : Button
|
||||
private void SetPseudoClasses()
|
||||
{
|
||||
if (_ignoringMouseOverState) {
|
||||
PseudoClasses.Set(":pressed", IsPressed);
|
||||
PseudoClasses.Set(":disabled", !IsEnabled);
|
||||
PseudoClasses.Set(StdPseudoClass.Pressed, IsPressed);
|
||||
PseudoClasses.Set(StdPseudoClass.Disabled, !IsEnabled);
|
||||
}
|
||||
|
||||
PseudoClasses.Set(":selected", IsSelected);
|
||||
PseudoClasses.Set(":inactive", IsInactive);
|
||||
PseudoClasses.Set(":today", IsToday);
|
||||
PseudoClasses.Set(":blackout", IsBlackout);
|
||||
PseudoClasses.Set(":dayfocused", IsCurrent && IsEnabled);
|
||||
PseudoClasses.Set(StdPseudoClass.Selected, IsSelected);
|
||||
PseudoClasses.Set(InactivePC, IsInactive);
|
||||
PseudoClasses.Set(TodayPC, IsToday);
|
||||
PseudoClasses.Set(BlackoutPC, IsBlackout);
|
||||
PseudoClasses.Set(DayfocusedPC, IsCurrent && IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -9,6 +9,7 @@ using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using AvaloniaButton = Avalonia.Controls.Button;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
@ -16,28 +17,23 @@ namespace AtomUI.Controls;
|
||||
/// Represents the currently displayed month or year on a
|
||||
/// <see cref="T:Avalonia.Controls.Calendar" />.
|
||||
/// </summary>
|
||||
[TemplatePart(PART_ElementHeaderButton, typeof(Button))]
|
||||
[TemplatePart(PART_ElementMonthView, typeof(Grid))]
|
||||
[TemplatePart(PART_ElementNextButton, typeof(Button))]
|
||||
[TemplatePart(PART_ElementPreviousButton, typeof(Button))]
|
||||
[TemplatePart(PART_ElementYearView, typeof(Grid))]
|
||||
[PseudoClasses(":calendardisabled")]
|
||||
public sealed class CalendarItem : TemplatedControl
|
||||
[TemplatePart(CalendarItemTheme.HeaderButtonPart, typeof(AvaloniaButton))]
|
||||
[TemplatePart(CalendarItemTheme.MonthViewPart, typeof(Grid))]
|
||||
[TemplatePart(CalendarItemTheme.NextButtonPart, typeof(AvaloniaButton))]
|
||||
[TemplatePart(CalendarItemTheme.PreviousButtonPart, typeof(AvaloniaButton))]
|
||||
[TemplatePart(CalendarItemTheme.YearViewPart, typeof(Grid))]
|
||||
[PseudoClasses(CalendarDisabledPC)]
|
||||
internal sealed class CalendarItem : TemplatedControl
|
||||
{
|
||||
private const string CalendarDisabledPC = ":calendardisabled";
|
||||
/// <summary>
|
||||
/// The number of days per week.
|
||||
/// </summary>
|
||||
private const int NumberOfDaysPerWeek = 7;
|
||||
|
||||
private const string PART_ElementHeaderButton = "PART_HeaderButton";
|
||||
private const string PART_ElementPreviousButton = "PART_PreviousButton";
|
||||
private const string PART_ElementNextButton = "PART_NextButton";
|
||||
private const string PART_ElementMonthView = "PART_MonthView";
|
||||
private const string PART_ElementYearView = "PART_YearView";
|
||||
|
||||
private Button? _headerButton;
|
||||
private Button? _nextButton;
|
||||
private Button? _previousButton;
|
||||
private AvaloniaButton? _headerButton;
|
||||
private AvaloniaButton? _nextButton;
|
||||
private AvaloniaButton? _previousButton;
|
||||
|
||||
private DateTime _currentMonth;
|
||||
private bool _isMouseLeftButtonDown;
|
||||
@ -73,7 +69,7 @@ public sealed class CalendarItem : TemplatedControl
|
||||
/// Gets the button that allows switching between month mode, year mode,
|
||||
/// and decade mode.
|
||||
/// </summary>
|
||||
internal Button? HeaderButton
|
||||
internal AvaloniaButton? HeaderButton
|
||||
{
|
||||
get => _headerButton;
|
||||
private set
|
||||
@ -93,7 +89,7 @@ public sealed class CalendarItem : TemplatedControl
|
||||
/// Gets the button that displays the next page of the calendar when it
|
||||
/// is clicked.
|
||||
/// </summary>
|
||||
internal Button? NextButton
|
||||
internal AvaloniaButton? NextButton
|
||||
{
|
||||
get => _nextButton;
|
||||
private set
|
||||
@ -122,7 +118,7 @@ public sealed class CalendarItem : TemplatedControl
|
||||
/// Gets the button that displays the previous page of the calendar when
|
||||
/// it is clicked.
|
||||
/// </summary>
|
||||
internal Button? PreviousButton
|
||||
internal AvaloniaButton? PreviousButton
|
||||
{
|
||||
get => _previousButton;
|
||||
private set
|
||||
@ -234,11 +230,11 @@ public sealed class CalendarItem : TemplatedControl
|
||||
/// </summary>
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
HeaderButton = e.NameScope.Find<Button>(PART_ElementHeaderButton);
|
||||
PreviousButton = e.NameScope.Find<Button>(PART_ElementPreviousButton);
|
||||
NextButton = e.NameScope.Find<Button>(PART_ElementNextButton);
|
||||
MonthView = e.NameScope.Find<Grid>(PART_ElementMonthView);
|
||||
YearView = e.NameScope.Find<Grid>(PART_ElementYearView);
|
||||
HeaderButton = e.NameScope.Find<AvaloniaButton>(CalendarItemTheme.HeaderButtonPart);
|
||||
PreviousButton = e.NameScope.Find<AvaloniaButton>(CalendarItemTheme.PreviousButtonPart);
|
||||
NextButton = e.NameScope.Find<AvaloniaButton>(CalendarItemTheme.NextButtonPart);
|
||||
MonthView = e.NameScope.Find<Grid>(CalendarItemTheme.MonthViewPart);
|
||||
YearView = e.NameScope.Find<Grid>(CalendarItemTheme.YearViewPart);
|
||||
|
||||
if (Owner != null) {
|
||||
UpdateDisabled(Owner.IsEnabled);
|
||||
@ -695,7 +691,7 @@ public sealed class CalendarItem : TemplatedControl
|
||||
Owner.Focus();
|
||||
}
|
||||
|
||||
Button b = (Button)sender!;
|
||||
AvaloniaButton b = (AvaloniaButton)sender!;
|
||||
DateTime d;
|
||||
|
||||
if (b.IsEnabled) {
|
||||
@ -720,7 +716,7 @@ public sealed class CalendarItem : TemplatedControl
|
||||
Owner.Focus();
|
||||
}
|
||||
|
||||
Button b = (Button)sender!;
|
||||
AvaloniaButton b = (AvaloniaButton)sender!;
|
||||
if (b.IsEnabled) {
|
||||
Owner.OnPreviousClick();
|
||||
}
|
||||
@ -734,7 +730,7 @@ public sealed class CalendarItem : TemplatedControl
|
||||
Owner.Focus();
|
||||
}
|
||||
|
||||
Button b = (Button)sender!;
|
||||
AvaloniaButton b = (AvaloniaButton)sender!;
|
||||
|
||||
if (b.IsEnabled) {
|
||||
Owner.OnNextClick();
|
||||
@ -990,6 +986,6 @@ public sealed class CalendarItem : TemplatedControl
|
||||
|
||||
internal void UpdateDisabled(bool isEnabled)
|
||||
{
|
||||
PseudoClasses.Set(":calendardisabled", !isEnabled);
|
||||
PseudoClasses.Set(CalendarDisabledPC, !isEnabled);
|
||||
}
|
||||
}
|
174
src/AtomUI.Controls/Calendar/CalendarItemTheme.cs
Normal file
174
src/AtomUI.Controls/Calendar/CalendarItemTheme.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Styling;
|
||||
using AvaloniaButton = Avalonia.Controls.Button;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
[ControlThemeProvider]
|
||||
internal class CalendarItemTheme : BaseControlTheme
|
||||
{
|
||||
public const string ItemFramePart = "PART_ItemFrame";
|
||||
public const string ItemRootLayoutPart = "PART_ItemRootLayout";
|
||||
public const string MonthViewPart = "PART_MonthView";
|
||||
public const string YearViewPart = "PART_YearView";
|
||||
|
||||
public const string PreviousButtonPart = "PART_PreviousButton";
|
||||
public const string HeaderButtonPart = "PART_HeaderButton";
|
||||
public const string NextButtonPart = "PART_NextButton";
|
||||
|
||||
public CalendarItemTheme()
|
||||
: base(typeof(CalendarItem))
|
||||
{
|
||||
}
|
||||
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
{
|
||||
return new FuncControlTemplate<CalendarItem>((calendarItem, scope) =>
|
||||
{
|
||||
var frame = new Border()
|
||||
{
|
||||
Name = ItemFramePart
|
||||
};
|
||||
|
||||
CreateTemplateParentBinding(frame, Border.BorderBrushProperty, CalendarItem.BorderBrushProperty);
|
||||
CreateTemplateParentBinding(frame, Border.BorderThicknessProperty, CalendarItem.BorderThicknessProperty);
|
||||
CreateTemplateParentBinding(frame, Border.CornerRadiusProperty, CalendarItem.CornerRadiusProperty);
|
||||
CreateTemplateParentBinding(frame, Border.BackgroundProperty, CalendarItem.BackgroundProperty);
|
||||
|
||||
var rootLayout = new DockPanel()
|
||||
{
|
||||
Name = ItemRootLayoutPart,
|
||||
LastChildFill = true
|
||||
};
|
||||
BuildHeader(rootLayout, scope);
|
||||
BuildContentView(rootLayout, scope);
|
||||
|
||||
BuildDayTitleTemplate(calendarItem);
|
||||
frame.Child = rootLayout;
|
||||
|
||||
return frame;
|
||||
});
|
||||
}
|
||||
|
||||
private void BuildDayTitleTemplate(CalendarItem calendarItem)
|
||||
{
|
||||
calendarItem.DayTitleTemplate = new DayTitleTemplate();
|
||||
}
|
||||
|
||||
private void BuildHeader(DockPanel layout, INameScope scope)
|
||||
{
|
||||
var headerLayout = new Grid()
|
||||
{
|
||||
ColumnDefinitions = new ColumnDefinitions()
|
||||
{
|
||||
new ColumnDefinition(GridLength.Auto),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Auto),
|
||||
}
|
||||
};
|
||||
var previousButton = new AvaloniaButton()
|
||||
{
|
||||
Name = PreviousButtonPart
|
||||
};
|
||||
previousButton.RegisterInNameScope(scope);
|
||||
Grid.SetColumn(previousButton, 0);
|
||||
headerLayout.Children.Add(previousButton);
|
||||
|
||||
var headerButton = new AvaloniaButton()
|
||||
{
|
||||
Name = HeaderButtonPart
|
||||
};
|
||||
Grid.SetColumn(headerButton, 1);
|
||||
headerButton.RegisterInNameScope(scope);
|
||||
headerLayout.Children.Add(headerButton);
|
||||
|
||||
var nextButton = new AvaloniaButton()
|
||||
{
|
||||
Name = NextButtonPart
|
||||
};
|
||||
Grid.SetColumn(nextButton, 2);
|
||||
nextButton.RegisterInNameScope(scope);
|
||||
headerLayout.Children.Add(nextButton);
|
||||
DockPanel.SetDock(headerLayout, Dock.Top);
|
||||
layout.Children.Add(headerLayout);
|
||||
}
|
||||
|
||||
private void BuildContentView(DockPanel layout, INameScope scope)
|
||||
{
|
||||
var monthView = new Grid()
|
||||
{
|
||||
Name = MonthViewPart,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
IsVisible = false,
|
||||
RowDefinitions = new RowDefinitions()
|
||||
{
|
||||
new RowDefinition(30, GridUnitType.Pixel),
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
},
|
||||
ColumnDefinitions = new ColumnDefinitions()
|
||||
{
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
}
|
||||
};
|
||||
monthView.RegisterInNameScope(scope);
|
||||
layout.Children.Add(monthView);
|
||||
|
||||
var yearView = new Grid()
|
||||
{
|
||||
Name = YearViewPart,
|
||||
IsVisible = false,
|
||||
RowDefinitions = new RowDefinitions()
|
||||
{
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Star),
|
||||
},
|
||||
ColumnDefinitions = new ColumnDefinitions()
|
||||
{
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
}
|
||||
};
|
||||
yearView.RegisterInNameScope(scope);
|
||||
layout.Children.Add(yearView);
|
||||
}
|
||||
|
||||
protected override void BuildStyles()
|
||||
{
|
||||
var commonStyle = new Style(selector => selector.Nesting());
|
||||
commonStyle.Add(CalendarItem.BorderBrushProperty, GlobalTokenResourceKey.ColorBorder);
|
||||
commonStyle.Add(CalendarItem.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadius);
|
||||
commonStyle.Add(CalendarItem.BackgroundProperty, GlobalTokenResourceKey.ColorBgContainer);
|
||||
Add(commonStyle);
|
||||
}
|
||||
}
|
||||
|
||||
internal class DayTitleTemplate : ITemplate<Control>
|
||||
{
|
||||
public Control Build()
|
||||
{
|
||||
return new TextBlock();
|
||||
}
|
||||
|
||||
object? ITemplate.Build()
|
||||
{
|
||||
return Build();
|
||||
}
|
||||
}
|
55
src/AtomUI.Controls/Calendar/CalendarTheme.cs
Normal file
55
src/AtomUI.Controls/Calendar/CalendarTheme.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
[ControlThemeProvider]
|
||||
internal class CalendarTheme : BaseControlTheme
|
||||
{
|
||||
public const string RootPart = "PART_Root";
|
||||
public const string CalendarItemPart = "PART_CalendarItem";
|
||||
|
||||
public CalendarTheme()
|
||||
: base(typeof(Calendar))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override IControlTemplate BuildControlTemplate()
|
||||
{
|
||||
return new FuncControlTemplate<Calendar>((calendar, scope) =>
|
||||
{
|
||||
var rootLayout = new StackPanel()
|
||||
{
|
||||
Name = RootPart,
|
||||
ClipToBounds = true
|
||||
};
|
||||
rootLayout.RegisterInNameScope(scope);
|
||||
|
||||
var calendarItem = new CalendarItem()
|
||||
{
|
||||
Name = CalendarItemPart
|
||||
};
|
||||
calendarItem.RegisterInNameScope(scope);
|
||||
CreateTemplateParentBinding(calendarItem, CalendarItem.BorderBrushProperty, Calendar.BorderBrushProperty);
|
||||
CreateTemplateParentBinding(calendarItem, CalendarItem.BorderThicknessProperty, Calendar.BorderThicknessProperty);
|
||||
CreateTemplateParentBinding(calendarItem, CalendarItem.CornerRadiusProperty, Calendar.CornerRadiusProperty);
|
||||
CreateTemplateParentBinding(calendarItem, CalendarItem.BackgroundProperty, Calendar.BackgroundProperty);
|
||||
rootLayout.Children.Add(calendarItem);
|
||||
|
||||
return rootLayout;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void BuildStyles()
|
||||
{
|
||||
var commonStyle = new Style(selector => selector.Nesting());
|
||||
commonStyle.Add(Calendar.BorderBrushProperty, GlobalTokenResourceKey.ColorBorder);
|
||||
commonStyle.Add(Calendar.CornerRadiusProperty, GlobalTokenResourceKey.BorderRadius);
|
||||
commonStyle.Add(Calendar.BackgroundProperty, GlobalTokenResourceKey.ColorBgContainer);
|
||||
Add(commonStyle);
|
||||
}
|
||||
}
|
78
src/AtomUI.Controls/Calendar/CalendarToken.cs
Normal file
78
src/AtomUI.Controls/Calendar/CalendarToken.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Theme.TokenSystem;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
[ControlDesignToken]
|
||||
internal class CalendarToken : AbstractControlDesignToken
|
||||
{
|
||||
public const string ID = "Calendar";
|
||||
|
||||
public CalendarToken()
|
||||
: base(ID)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单元格悬浮态背景色
|
||||
/// </summary>
|
||||
public Color CellHoverBg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 选取范围内的单元格背景色
|
||||
/// </summary>
|
||||
public Color CellActiveWithRangeBg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 选取范围内的单元格悬浮态背景色
|
||||
/// </summary>
|
||||
public Color CellHoverWithRangeBg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单元格禁用态背景色
|
||||
/// </summary>
|
||||
public Color CellBgDisabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 选取范围时单元格边框色
|
||||
/// </summary>
|
||||
public Color CellRangeBorderColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单元格高度
|
||||
/// </summary>
|
||||
public double CellHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单元格宽度
|
||||
/// </summary>
|
||||
public double CellWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单元格文本高度
|
||||
/// </summary>
|
||||
public double TextHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 十年/年/季/月/周单元格高度
|
||||
/// </summary>
|
||||
public double WithoutTimeCellHeight { get; set; }
|
||||
|
||||
internal override void CalculateFromAlias()
|
||||
{
|
||||
base.CalculateFromAlias();
|
||||
|
||||
var colorPrimary = _globalToken.ColorToken.ColorPrimaryToken.ColorPrimary;
|
||||
|
||||
CellHoverBg = _globalToken.ControlItemBgHover;
|
||||
CellActiveWithRangeBg = _globalToken.ControlItemBgActive;
|
||||
CellHoverWithRangeBg = colorPrimary.Lighten(35);
|
||||
CellRangeBorderColor = colorPrimary.Lighten(20);
|
||||
CellBgDisabled = _globalToken.ColorBgContainerDisabled;
|
||||
CellWidth = _globalToken.HeightToken.ControlHeightSM * 1.5;
|
||||
CellHeight = _globalToken.HeightToken.ControlHeightSM;
|
||||
TextHeight = _globalToken.HeightToken.ControlHeightLG;
|
||||
WithoutTimeCellHeight = _globalToken.HeightToken.ControlHeightLG * 1.65;
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.SplitButtonTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.TextButtonTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.ToggleIconButtonTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.CalendarItemTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.CalendarTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.CheckBoxTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.CollapseItemTheme());
|
||||
ThemeManager.Current.RegisterControlTheme(new AtomUI.Controls.CollapseTheme());
|
||||
|
@ -10,6 +10,7 @@
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.BadgeToken));
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.ButtonSpinnerToken));
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.ButtonToken));
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.CalendarToken));
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.CheckBoxToken));
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.CollapseToken));
|
||||
ThemeManager.Current.RegisterControlTokenType(typeof(AtomUI.Controls.ComboBoxToken));
|
||||
|
@ -128,6 +128,19 @@ namespace AtomUI.Theme.Styling
|
||||
public static readonly TokenResourceKey IconOnyPaddingSM = new TokenResourceKey("Button.IconOnyPaddingSM", "AtomUI.Token");
|
||||
}
|
||||
|
||||
public static class CalendarTokenResourceKey
|
||||
{
|
||||
public static readonly TokenResourceKey CellHoverBg = new TokenResourceKey("Calendar.CellHoverBg", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey CellActiveWithRangeBg = new TokenResourceKey("Calendar.CellActiveWithRangeBg", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey CellHoverWithRangeBg = new TokenResourceKey("Calendar.CellHoverWithRangeBg", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey CellBgDisabled = new TokenResourceKey("Calendar.CellBgDisabled", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey CellRangeBorderColor = new TokenResourceKey("Calendar.CellRangeBorderColor", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey CellHeight = new TokenResourceKey("Calendar.CellHeight", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey CellWidth = new TokenResourceKey("Calendar.CellWidth", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey TextHeight = new TokenResourceKey("Calendar.TextHeight", "AtomUI.Token");
|
||||
public static readonly TokenResourceKey WithoutTimeCellHeight = new TokenResourceKey("Calendar.WithoutTimeCellHeight", "AtomUI.Token");
|
||||
}
|
||||
|
||||
public static class CheckBoxTokenResourceKey
|
||||
{
|
||||
public static readonly TokenResourceKey CheckIndicatorSize = new TokenResourceKey("CheckBox.CheckIndicatorSize", "AtomUI.Token");
|
||||
|
Loading…
Reference in New Issue
Block a user