diff --git a/CHANGELOG.md b/CHANGELOG.md index bc086fcf6..30a934e56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,14 @@ Also, as previews that follow the main version: `TKCode.Arc.Graphics3D`, `TKCode - `ToggleGroup` and `SegmentedControl` (`TKCode.Arc`): `SelectedItemBackground` and `SelectedItemForeground` brush properties set the fill behind the selected option (the gliding fill, or each pressed option's fill in multiple mode; the segmented pill) and its text and icon color, per instance or from a style, for backgrounds where the default selected look is hard to tell from the other options. Null (cleared) keeps the theme's colors (#227). - `SegmentedItem` (`TKCode.Arc`) is now public (it was internal), so that XAML styles and Rider's checks can address `arc|SegmentedItem` (#231). It has a token of its own, `SegmentedItemToken` (identity `SegmentedControlItem`, because `TKCode.Arc.Mobile` already has a `SegmentedItem` token). `TKCode.Arc.Mobile` also has a `SegmentedItem` in its own namespace; a C# file that imports both namespaces aliases one side. - `ArcWindow` / `TitleBar` / `WindowCaptionButtons` (`TKCode.Arc`): `CaptionButtonVariant` (`Round` | `Rectangle`, #230) picks the shape of the drawn caption buttons. `Round` is the default and the look is unchanged; `Rectangle` draws Windows-style flat buttons that are as tall as the title bar, 46 wide (`WindowCaptionButtonsToken.RectangleButtonWidth`), touch each other and the window's right edge (`TitleBarToken.RectangleButtonsPadding`), with square corners, and the close button turns solid danger under the pointer. Inherited, so setting it on the `ArcWindow` is enough; it applies only while the bar draws the buttons (`CaptionButtons` `Drawn`, or `Auto` outside macOS). New token entries: `WindowCaptionButtonsTokenKind.RectangleButtonWidth` and `RectangleCloseHoverForeground`, `TitleBarTokenKind.RectangleButtonsPadding`. +- `FieldVariant` (`TKCode.Arc.Core`, `Outline` default | `Ghost`) and a `Variant` property on `Select`, `Combobox`, `MultiSelect` and `DropdownMenu` ([#229](https://github.com/AIDotNet/TKCode.Arc/issues/229)). `Ghost` drops the border, the fill and the minimum width of the trigger at rest (the border keeps its thickness, so nothing shifts) and fills with `SurfaceMuted` on hover, press and open; the keyboard focus ring stays. It has a tighter horizontal padding from the new token property `GhostTriggerPadding` (8, compact 6) on `SelectToken`, `ComboboxToken` and `MultiSelectToken`. On `DropdownMenu` the built-in trigger button uses `ButtonVariant.Ghost` instead of `Secondary`. The defaults are unchanged (`Outline`). +- `DropdownMenu.Size` (`ControlSize`) for the built-in trigger button. Its default is `Small`, not `Medium` as on most controls, because the trigger was always a small button, so the default look does not change. +- The select triggers get the `:ghost` and `:raised` pseudo-classes (`Select.GhostPseudoClass`, `Select.RaisedPseudoClass`, and the same constants on `Combobox`, `MultiSelect`; `DropdownMenu.GhostPseudoClass`). + +### Fixed + +- `Select`, `Combobox` and `MultiSelect`: the resting fill, border (and padding, chevron margin and chip fill on `MultiSelect`) of the trigger were written as local values on the template, so the hover, pressed, open, focus and `:has-selection` styles of the theme could not override them. They are style setters now and those states show as the theme declares them (a `SurfaceMuted` fill and a stronger border while hovered, pressed or open; room for the clear button on a `MultiSelect` with a selection). +- The `ControlSize` documentation said the heights are 36 / 44 / 50; they depend on the density (36 / 44 / 50, or 28 / 34 / 40 with `ArcDensity.Compact`). Documentation only. ## 1.3.3-preview.2 - 2026-12-01 diff --git a/src/TKCode.Arc.Core/Primitives/ControlSize.cs b/src/TKCode.Arc.Core/Primitives/ControlSize.cs index 4505983f7..98bac6060 100644 --- a/src/TKCode.Arc.Core/Primitives/ControlSize.cs +++ b/src/TKCode.Arc.Core/Primitives/ControlSize.cs @@ -1,6 +1,9 @@ namespace TKCode.Arc; -/// Arc control sizes: heights 36 / 44 / 50 (ControlSizeSM / MD / LG). +/// +/// Arc control sizes (ControlSizeSM / MD / LG). The heights depend on the density: 36 / 44 / 50 by default and +/// 28 / 34 / 40 with ArcDensity.Compact. +/// public enum ControlSize { Small, diff --git a/src/TKCode.Arc.Core/Primitives/FieldVariant.cs b/src/TKCode.Arc.Core/Primitives/FieldVariant.cs new file mode 100644 index 000000000..3fa8be20c --- /dev/null +++ b/src/TKCode.Arc.Core/Primitives/FieldVariant.cs @@ -0,0 +1,14 @@ +namespace TKCode.Arc; + +/// Chrome of a select-like field's trigger (Select, Combobox, MultiSelect, DropdownMenu). +public enum FieldVariant +{ + /// A bordered box on the surface color: Arc's look (default). + Outline, + + /// + /// No border and no fill at rest: the value and the chevron only, as wide as the content needs. Hover, press and open show + /// a muted fill; the keyboard focus ring stays visible. + /// + Ghost +} diff --git a/src/TKCode.Arc.Core/PublicAPI.Unshipped.txt b/src/TKCode.Arc.Core/PublicAPI.Unshipped.txt index 7dc5c5811..4589f615e 100644 --- a/src/TKCode.Arc.Core/PublicAPI.Unshipped.txt +++ b/src/TKCode.Arc.Core/PublicAPI.Unshipped.txt @@ -1 +1,4 @@ #nullable enable +TKCode.Arc.FieldVariant +TKCode.Arc.FieldVariant.Ghost = 1 -> TKCode.Arc.FieldVariant +TKCode.Arc.FieldVariant.Outline = 0 -> TKCode.Arc.FieldVariant diff --git a/src/TKCode.Arc/Menus/DropdownMenu/DropdownMenu.cs b/src/TKCode.Arc/Menus/DropdownMenu/DropdownMenu.cs index 0831c3d42..c4e8231e2 100644 --- a/src/TKCode.Arc/Menus/DropdownMenu/DropdownMenu.cs +++ b/src/TKCode.Arc/Menus/DropdownMenu/DropdownMenu.cs @@ -33,13 +33,14 @@ namespace TKCode.Arc; /// [TemplatePart(TriggerPart, typeof(AvaloniaButton))] [TemplatePart(TriggerPresenterPart, typeof(ContentPresenter))] -[PseudoClasses(OpenPseudoClass, CustomTriggerPseudoClass)] +[PseudoClasses(OpenPseudoClass, CustomTriggerPseudoClass, GhostPseudoClass)] public class DropdownMenu : TemplatedControl { public const string TriggerPart = "PART_Trigger"; public const string TriggerPresenterPart = "PART_TriggerPresenter"; public const string OpenPseudoClass = ":open"; public const string CustomTriggerPseudoClass = ":custom-trigger"; + public const string GhostPseudoClass = ":ghost"; #region 公共属性定义 @@ -68,6 +69,21 @@ public class DropdownMenu : TemplatedControl public static readonly StyledProperty TriggerProperty = AvaloniaProperty.Register(nameof(Trigger)); + /// + /// Chrome of the built-in trigger button: Outline (default) keeps the bordered ButtonVariant.Secondary look, Ghost + /// uses ButtonVariant.Ghost (no border or fill at rest). A custom is not affected. + /// + public static readonly StyledProperty VariantProperty = + Select.VariantProperty.AddOwner(); + + /// + /// Size of the built-in trigger button. The default is (not Medium as for most controls), + /// which is what the trigger always used, so the look does not change; set Medium or Large for a taller trigger. + /// A custom is not affected. + /// + public static readonly StyledProperty SizeProperty = + Field.SizeProperty.AddOwner(new StyledPropertyMetadata(ControlSize.Small)); + /// Whether the menu is open (two-way). public static readonly StyledProperty IsOpenProperty = AvaloniaProperty.Register(nameof(IsOpen), defaultBindingMode: BindingMode.TwoWay); @@ -131,6 +147,20 @@ public object? Trigger set => SetValue(TriggerProperty, value); } + /// + public FieldVariant Variant + { + get => GetValue(VariantProperty); + set => SetValue(VariantProperty, value); + } + + /// + public ControlSize Size + { + get => GetValue(SizeProperty); + set => SetValue(SizeProperty, value); + } + /// public bool IsOpen { @@ -274,6 +304,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { SetMenu(_trigger, Menu); AutomationProperties.SetName(_trigger, Label); + ApplyTriggerVariant(); } _triggerPresenter?.PropertyChanged += OnTriggerPresenterPropertyChanged; AttachCustomTrigger(_triggerPresenter?.Child); @@ -289,10 +320,24 @@ protected override void OnLoaded(RoutedEventArgs e) } } + private void ApplyTriggerVariant() + { + // The built-in trigger is a template part, so its variant is synced here: a style setter would lose to the template's value. + if (_trigger is Button button) + { + button.Variant = Variant == FieldVariant.Ghost ? ButtonVariant.Ghost : ButtonVariant.Secondary; + } + } + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); - if (change.Property == IsOpenProperty) + if (change.Property == VariantProperty) + { + PseudoClasses.Set(GhostPseudoClass, change.GetNewValue() == FieldVariant.Ghost); + ApplyTriggerVariant(); + } + else if (change.Property == IsOpenProperty) { var open = change.GetNewValue(); PseudoClasses.Set(OpenPseudoClass, open); diff --git a/src/TKCode.Arc/Menus/DropdownMenu/Themes/DropdownMenuTheme.axaml b/src/TKCode.Arc/Menus/DropdownMenu/Themes/DropdownMenuTheme.axaml index 8722934e9..c06038ce9 100644 --- a/src/TKCode.Arc/Menus/DropdownMenu/Themes/DropdownMenuTheme.axaml +++ b/src/TKCode.Arc/Menus/DropdownMenu/Themes/DropdownMenuTheme.axaml @@ -10,7 +10,7 @@ @@ -68,6 +68,19 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +