mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-26 03:00:28 +08:00
Refactor BuildInstanceStyles
This commit is contained in:
@@ -4,7 +4,6 @@ using AtomUI.Media;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
@@ -28,7 +27,6 @@ internal class IconButtonTheme : BaseControlTheme
|
||||
{
|
||||
return new FuncControlTemplate<IconButton>((button, scope) =>
|
||||
{
|
||||
BuildInstanceStyles(button);
|
||||
var iconContent = new ContentPresenter
|
||||
{
|
||||
Name = IconContentPart,
|
||||
@@ -85,14 +83,13 @@ internal class IconButtonTheme : BaseControlTheme
|
||||
}
|
||||
|
||||
commonStyle.Add(enableHoverStyle);
|
||||
Add(commonStyle);
|
||||
}
|
||||
|
||||
protected override void BuildInstanceStyles(Control control)
|
||||
{
|
||||
var iconStyle = new Style(selector => selector.Name(IconContentPart).Child().OfType<Icon>());
|
||||
|
||||
var iconStyle = new Style(selector => selector.Nesting().Template().Name(IconContentPart).Descendant().OfType<Icon>());
|
||||
|
||||
iconStyle.Add(Layoutable.HorizontalAlignmentProperty, HorizontalAlignment.Center);
|
||||
iconStyle.Add(Layoutable.VerticalAlignmentProperty, VerticalAlignment.Center);
|
||||
control.Styles.Add(iconStyle);
|
||||
|
||||
commonStyle.Add(iconStyle);
|
||||
Add(commonStyle);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,12 @@
|
||||
using System.Reactive.Disposables;
|
||||
using AtomUI.IconPkg;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.IconPkg;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.LogicalTree;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
internal class PickerClearUpButton : TemplatedControl,
|
||||
ITokenResourceConsumer
|
||||
internal class PickerClearUpButton : TemplatedControl
|
||||
{
|
||||
CompositeDisposable? ITokenResourceConsumer.TokenBindingsDisposable => _tokenBindingsDisposable;
|
||||
private CompositeDisposable? _tokenBindingsDisposable;
|
||||
|
||||
public event EventHandler? ClearRequest;
|
||||
|
||||
public static readonly StyledProperty<bool> IsInClearModeProperty =
|
||||
@@ -39,23 +32,10 @@ internal class PickerClearUpButton : TemplatedControl,
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
this.RunThemeTokenBindingActions();
|
||||
_clearButton = e.NameScope.Get<IconButton>(PickerClearUpButtonTheme.ClearButtonPart);
|
||||
if (_clearButton is not null)
|
||||
{
|
||||
_clearButton.Click += (sender, args) => { ClearRequest?.Invoke(this, EventArgs.Empty); };
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_tokenBindingsDisposable = new CompositeDisposable();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
this.DisposeTokenBindings();
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,6 @@ internal class PickerClearUpButtonTheme : BaseControlTheme
|
||||
{
|
||||
return new FuncControlTemplate<PickerClearUpButton>((pickerClearUpButton, scope) =>
|
||||
{
|
||||
ResetTokenResourceBindings(pickerClearUpButton);
|
||||
BuildInstanceStyles(pickerClearUpButton);
|
||||
var container = new Panel();
|
||||
BuildClearButton(container, scope);
|
||||
BuildClockIconContent(container, scope);
|
||||
@@ -71,14 +69,11 @@ internal class PickerClearUpButtonTheme : BaseControlTheme
|
||||
clearUpButtonStyle.Add(IconButton.ActiveIconColorProperty, SharedTokenKey.ColorTextQuaternary);
|
||||
clearUpButtonStyle.Add(IconButton.SelectedIconColorProperty, SharedTokenKey.ColorText);
|
||||
Add(clearUpButtonStyle);
|
||||
}
|
||||
|
||||
protected override void BuildInstanceStyles(Control control)
|
||||
{
|
||||
var iconStyle = new Style(selector => selector.Name(InfoIconContentPart).Child().OfType<Icon>());
|
||||
|
||||
var iconStyle = new Style(selector => selector.Nesting().Template().Name(InfoIconContentPart).Descendant().OfType<Icon>());
|
||||
iconStyle.Add(Icon.WidthProperty, SharedTokenKey.IconSize);
|
||||
iconStyle.Add(Icon.HeightProperty, SharedTokenKey.IconSize);
|
||||
iconStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorTextQuaternary);
|
||||
control.Styles.Add(iconStyle);
|
||||
Add(iconStyle);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using AtomUI.Controls.Utils;
|
||||
using AtomUI.IconPkg;
|
||||
using AtomUI.Theme;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
@@ -88,7 +87,6 @@ public abstract class RangeInfoPickerInput : InfoPickerInput
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
this.RunThemeTokenBindingActions();
|
||||
_secondaryInfoInputBox = e.NameScope.Get<TextBox>(RangeInfoPickerInputTheme.SecondaryInfoInputBoxPart);
|
||||
_rangePickerIndicator = e.NameScope.Get<Rectangle>(RangeInfoPickerInputTheme.RangePickerIndicatorPart);
|
||||
_rangePickerArrow = e.NameScope.Get<Icon>(RangeInfoPickerInputTheme.RangePickerArrowPart);
|
||||
|
||||
@@ -142,37 +142,6 @@ internal class PopupConfirmContainerTheme : BaseControlTheme
|
||||
return buttonLayout;
|
||||
}
|
||||
|
||||
protected override void BuildInstanceStyles(Control control)
|
||||
{
|
||||
{
|
||||
var iconStyle = new Style(selector => selector.Name(IconContentPart).Child().OfType<Icon>());
|
||||
iconStyle.Add(Layoutable.WidthProperty, SharedTokenKey.IconSizeLG);
|
||||
iconStyle.Add(Layoutable.HeightProperty, SharedTokenKey.IconSizeLG);
|
||||
iconStyle.Add(Layoutable.VerticalAlignmentProperty, VerticalAlignment.Top);
|
||||
control.Styles.Add(iconStyle);
|
||||
}
|
||||
var infoStatusStyle = new Style(selector => selector
|
||||
.PropertyEquals(PopupConfirmContainer.ConfirmStatusProperty,
|
||||
PopupConfirmStatus.Info)
|
||||
.Descendant().Name(IconContentPart).Child().OfType<Icon>());
|
||||
infoStatusStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorPrimary);
|
||||
control.Styles.Add(infoStatusStyle);
|
||||
|
||||
var warningStatusStyle = new Style(selector => selector
|
||||
.PropertyEquals(PopupConfirmContainer.ConfirmStatusProperty,
|
||||
PopupConfirmStatus.Warning)
|
||||
.Descendant().Name(IconContentPart).Child().OfType<Icon>());
|
||||
warningStatusStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorWarning);
|
||||
control.Styles.Add(warningStatusStyle);
|
||||
|
||||
var errorStatusStyle = new Style(selector => selector
|
||||
.PropertyEquals(PopupConfirmContainer.ConfirmStatusProperty,
|
||||
PopupConfirmStatus.Error)
|
||||
.Descendant().Name(IconContentPart).Child().OfType<Icon>());
|
||||
errorStatusStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorError);
|
||||
control.Styles.Add(errorStatusStyle);
|
||||
}
|
||||
|
||||
protected override void BuildStyles()
|
||||
{
|
||||
var commonStyle = new Style(selector => selector.Nesting());
|
||||
@@ -202,5 +171,38 @@ internal class PopupConfirmContainerTheme : BaseControlTheme
|
||||
commonStyle.Add(buttonContainerStyle);
|
||||
|
||||
Add(commonStyle);
|
||||
|
||||
BuildInfoIconStyle();
|
||||
}
|
||||
|
||||
private void BuildInfoIconStyle()
|
||||
{
|
||||
{
|
||||
var iconStyle = new Style(selector => selector.Name(IconContentPart).Descendant().OfType<Icon>());
|
||||
iconStyle.Add(Layoutable.WidthProperty, SharedTokenKey.IconSizeLG);
|
||||
iconStyle.Add(Layoutable.HeightProperty, SharedTokenKey.IconSizeLG);
|
||||
iconStyle.Add(Layoutable.VerticalAlignmentProperty, VerticalAlignment.Top);
|
||||
Add(iconStyle);
|
||||
}
|
||||
var infoStatusStyle = new Style(selector => selector
|
||||
.PropertyEquals(PopupConfirmContainer.ConfirmStatusProperty,
|
||||
PopupConfirmStatus.Info)
|
||||
.Descendant().Name(IconContentPart).Descendant().OfType<Icon>());
|
||||
infoStatusStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorPrimary);
|
||||
Add(infoStatusStyle);
|
||||
|
||||
var warningStatusStyle = new Style(selector => selector
|
||||
.PropertyEquals(PopupConfirmContainer.ConfirmStatusProperty,
|
||||
PopupConfirmStatus.Warning)
|
||||
.Descendant().Name(IconContentPart).Descendant().OfType<Icon>());
|
||||
warningStatusStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorWarning);
|
||||
Add(warningStatusStyle);
|
||||
|
||||
var errorStatusStyle = new Style(selector => selector
|
||||
.PropertyEquals(PopupConfirmContainer.ConfirmStatusProperty,
|
||||
PopupConfirmStatus.Error)
|
||||
.Descendant().Name(IconContentPart).Descendant().OfType<Icon>());
|
||||
errorStatusStyle.Add(Icon.NormalFilledBrushProperty, SharedTokenKey.ColorError);
|
||||
Add(errorStatusStyle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user