From aae21ff6ddac9c346130ee32d2f32bb9c8a33c71 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:11:26 +0800 Subject: [PATCH 01/61] fix: streamline slider glass interaction path --- .../include/KubeSliderVisualModel.hpp | 179 +++++++++++------- 1 file changed, 112 insertions(+), 67 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp index 9b408a98..c8e130b3 100644 --- a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp @@ -38,30 +38,61 @@ namespace winrt::WinUI::LiquidGlass::detail m_pressed = false; }); - auto refresh = [this](auto const&, auto const&) + self->RegisterPropertyChangedCallback(Self::GlassBrushProperty(), [this](auto const&, auto const&) { - if (m_loaded) RefreshVisual(); - }; - self->RegisterPropertyChangedCallback(Self::GlassBrushProperty(), refresh); + if (!m_loaded) return; + // If the brush is replaced while pressed, never carry the old brush's + // active baseline into the new instance. + auto self = static_cast(this); + auto current = self->GlassBrush(); + if (m_pressOptics.active && + (!current || !m_pressOptics.brush || get_abi(current) != get_abi(m_pressOptics.brush))) + { + m_pressOptics = {}; + m_pressed = false; + } + ApplyBrush(); + ApplyInteractionState(false); + RefreshPointerField(); + }); self->RegisterPropertyChangedCallback( - Microsoft::UI::Xaml::Controls::Slider::OrientationProperty(), refresh); + Microsoft::UI::Xaml::Controls::Slider::OrientationProperty(), + [this](auto const&, auto const&) { if (m_loaded) RefreshVisual(); }); self->RegisterPropertyChangedCallback( - Microsoft::UI::Xaml::Controls::Slider::IsDirectionReversedProperty(), refresh); + Microsoft::UI::Xaml::Controls::Slider::IsDirectionReversedProperty(), + [this](auto const&, auto const&) { if (m_loaded) RefreshVisual(); }); + + auto updateValue = [this](auto const&, auto const&) + { + if (!m_loaded) return; + // Value changes can occur at pointer frequency. Keep this path strictly + // Composition-only; native Slider layout will move the semantic Thumb and + // LayoutUpdated performs the cheap post-layout lens correction. + UpdateProgressVisual(); + }; self->RegisterPropertyChangedCallback( - Microsoft::UI::Xaml::Controls::Primitives::RangeBase::ValueProperty(), - [this](auto const&, auto const&) { if (m_loaded) UpdateValueVisuals(); }); + Microsoft::UI::Xaml::Controls::Primitives::RangeBase::ValueProperty(), updateValue); self->RegisterPropertyChangedCallback( - Microsoft::UI::Xaml::Controls::Primitives::RangeBase::MinimumProperty(), - [this](auto const&, auto const&) { if (m_loaded) UpdateValueVisuals(); }); + Microsoft::UI::Xaml::Controls::Primitives::RangeBase::MinimumProperty(), updateValue); self->RegisterPropertyChangedCallback( - Microsoft::UI::Xaml::Controls::Primitives::RangeBase::MaximumProperty(), - [this](auto const&, auto const&) { if (m_loaded) UpdateValueVisuals(); }); + Microsoft::UI::Xaml::Controls::Primitives::RangeBase::MaximumProperty(), updateValue); - self->LayoutUpdated([this](auto const&, auto const&) + self->SizeChanged([this](auto const&, auto const&) { if (!m_loaded) return; - if (!m_thumb || !m_track) ResolveTemplateParts(); - UpdateValueVisuals(); + UpdateProgressVisual(); + UpdateLensPosition(DisplayRatio(NormalizedValue())); + }); + + // WinUI updates the native Thumb position during layout. We still need one + // post-layout coordinate correction because the 90x60 glass lens deliberately + // has a different footprint from the 18x18 semantic Thumb. This handler must + // stay lightweight: no tree walking, resource creation, brush allocation, or + // template mutation is allowed here. + self->LayoutUpdated([this](auto const&, auto const&) + { + if (!m_loaded || !m_thumb || !m_surface || !m_track) return; + UpdateLensPosition(DisplayRatio(NormalizedValue())); }); auto bind = [self](auto routedEvent, Windows::Foundation::IInspectable& storage, auto&& callback) @@ -85,7 +116,8 @@ namespace winrt::WinUI::LiquidGlass::detail if (!m_loaded) return; ResolveTemplateParts(); ApplyBrush(); - UpdateValueVisuals(); + UpdateProgressVisual(); + UpdateLensPosition(DisplayRatio(NormalizedValue())); ApplyInteractionState(false); RefreshPointerField(); } @@ -97,7 +129,7 @@ namespace winrt::WinUI::LiquidGlass::detail static constexpr double kRestScale = 0.6; static constexpr double kRestElevation = 6.0; static constexpr double kPressedElevation = 10.0; - static constexpr double kScaleDampingRatio = 0.8944271909999159; + static constexpr double kScaleDampingRatio = 0.8944271909999159; // k=2000,d=80 static constexpr double kScalePeriodMs = 140.49629462081452; static Microsoft::UI::Xaml::Media::SolidColorBrush SolidBrush( @@ -177,40 +209,55 @@ namespace winrt::WinUI::LiquidGlass::detail auto decrease = FindNamedDescendant(root, decreaseName).try_as(); if (!thumb || !track) return; - thumb.Width(kSemanticThumbExtent); - thumb.Height(kSemanticThumbExtent); - thumb.Margin({ 0.0, 0.0, 0.0, 0.0 }); + bool const thumbChanged = !m_thumb || get_abi(m_thumb) != get_abi(thumb); + bool const trackChanged = !m_track || get_abi(m_track) != get_abi(track); m_thumb = thumb; + m_track = track; + m_decrease = decrease; - auto surface = FindFirstDescendant(thumb); - m_surface = surface; - if (surface) + if (thumbChanged) { - surface.Width(horizontal ? kVisualWidth : kVisualHeight); - surface.Height(horizontal ? kVisualHeight : kVisualWidth); - surface.HorizontalAlignment(Microsoft::UI::Xaml::HorizontalAlignment::Center); - surface.VerticalAlignment(Microsoft::UI::Xaml::VerticalAlignment::Center); - surface.Margin({ 0.0, 0.0, 0.0, 0.0 }); - surface.CornerRadius({ 30.0, 30.0, 30.0, 30.0 }); - surface.BorderBrush(SolidBrush(0x33, 0xff, 0xff, 0xff)); - surface.BorderThickness({ 1.0, 1.0, 1.0, 1.0 }); - Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(surface, true); - if (!surface.Shadow()) surface.Shadow(Microsoft::UI::Xaml::Media::ThemeShadow{}); + thumb.Width(kSemanticThumbExtent); + thumb.Height(kSemanticThumbExtent); + thumb.Margin({ 0.0, 0.0, 0.0, 0.0 }); + + auto surface = FindFirstDescendant(thumb); + m_surface = surface; + if (surface) + { + surface.Width(horizontal ? kVisualWidth : kVisualHeight); + surface.Height(horizontal ? kVisualHeight : kVisualWidth); + surface.HorizontalAlignment(Microsoft::UI::Xaml::HorizontalAlignment::Center); + surface.VerticalAlignment(Microsoft::UI::Xaml::VerticalAlignment::Center); + surface.Margin({ 0.0, 0.0, 0.0, 0.0 }); + surface.CornerRadius({ 30.0, 30.0, 30.0, 30.0 }); + surface.BorderBrush(SolidBrush(0x33, 0xff, 0xff, 0xff)); + surface.BorderThickness({ 1.0, 1.0, 1.0, 1.0 }); + Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(surface, true); + if (!surface.Shadow()) surface.Shadow(Microsoft::UI::Xaml::Media::ThemeShadow{}); + } + + if (auto inner = FindNamedDescendant(thumb, L"SliderInnerThumb") + .try_as()) + { + inner.Visibility(Microsoft::UI::Xaml::Visibility::Collapsed); + } } - - if (auto inner = FindNamedDescendant(thumb, L"SliderInnerThumb") - .try_as()) + else if (!m_surface) { - inner.Visibility(Microsoft::UI::Xaml::Visibility::Collapsed); + m_surface = FindFirstDescendant(thumb); } - track.Fill(SolidBrush(0x66, 0x89, 0x89, 0x8f)); - if (decrease) decrease.Opacity(0.0); - - bool const trackChanged = !m_track || get_abi(m_track) != get_abi(track); - m_track = track; - m_decrease = decrease; - if (trackChanged) BuildProgressVisual(); + if (trackChanged) + { + track.Fill(SolidBrush(0x66, 0x89, 0x89, 0x8f)); + if (decrease) decrease.Opacity(0.0); + BuildProgressVisual(); + } + else if (decrease && decrease.Opacity() != 0.0) + { + decrease.Opacity(0.0); + } } void BuildProgressVisual() @@ -244,14 +291,13 @@ namespace winrt::WinUI::LiquidGlass::detail return self->IsDirectionReversed() ? logicalRatio : 1.0 - logicalRatio; } - void UpdateValueVisuals() + void UpdateProgressVisual() { if (!m_track || !m_progressVisual || !m_progressGeometry || !m_progressShape) return; auto self = static_cast(this); auto const horizontal = self->Orientation() == Microsoft::UI::Xaml::Controls::Orientation::Horizontal; auto const ratio = NormalizedValue(); - auto const displayRatio = DisplayRatio(ratio); auto const width = std::max(0.0, m_track.ActualWidth()); auto const height = std::max(0.0, m_track.ActualHeight()); if (width <= 0.0 || height <= 0.0) return; @@ -276,8 +322,6 @@ namespace winrt::WinUI::LiquidGlass::detail auto const startY = self->IsDirectionReversed() ? 0.0 : height - progressHeight; m_progressShape.Offset({ 0.0f, static_cast(startY) }); } - - UpdateLensPosition(displayRatio); } void UpdateLensPosition(double displayRatio) @@ -290,11 +334,6 @@ namespace winrt::WinUI::LiquidGlass::detail auto const trackExtent = horizontal ? m_track.ActualWidth() : m_track.ActualHeight(); if (trackExtent <= 0.0) return; - // Compute the native Thumb center in the *actual track coordinate system*. - // The stock WinUI Slider template has pre/post content margins and other layout - // details, so assuming the semantic 18-DIP thumb begins exactly at track x=0 - // produces the visible 0% left-edge mismatch. Kube instead positions the lens - // from its rendered 54-DIP rest footprint; reproduce that in real coordinates. double nativeCenter = kSemanticThumbExtent * .5; try { @@ -306,8 +345,7 @@ namespace winrt::WinUI::LiquidGlass::detail } catch (...) { - // During a transient template/layout pass, keep the semantic fallback and - // let the next LayoutUpdated iteration resolve the exact coordinate. + return; } auto const halfVisual = visualExtent * .5; @@ -316,17 +354,18 @@ namespace winrt::WinUI::LiquidGlass::detail auto const correction = desiredCenter - nativeCenter; auto translation = m_surface.Translation(); - if (horizontal) + auto const newX = horizontal ? correction : 0.0; + auto const newY = horizontal ? 0.0 : correction; + auto const newZ = m_pressed ? kPressedElevation : kRestElevation; + if (std::abs(static_cast(translation.x) - newX) <= .01 && + std::abs(static_cast(translation.y) - newY) <= .01 && + std::abs(static_cast(translation.z) - newZ) <= .01) { - translation.x = static_cast(correction); - translation.y = 0.0f; - } - else - { - translation.x = 0.0f; - translation.y = static_cast(correction); + return; } - translation.z = static_cast(m_pressed ? kPressedElevation : kRestElevation); + translation.x = static_cast(newX); + translation.y = static_cast(newY); + translation.z = static_cast(newZ); m_surface.Translation(translation); } @@ -341,9 +380,15 @@ namespace winrt::WinUI::LiquidGlass::detail } if (m_surface) { - m_surface.Background(brush + auto desired = brush ? brush.as() - : Microsoft::UI::Xaml::Media::Brush{ nullptr }); + : Microsoft::UI::Xaml::Media::Brush{ nullptr }; + auto current = m_surface.Background(); + if ((!current && desired) || (current && !desired) || + (current && desired && get_abi(current) != get_abi(desired))) + { + m_surface.Background(desired); + } } } @@ -410,7 +455,7 @@ namespace winrt::WinUI::LiquidGlass::detail { LeavePressedOptics(owner, m_pressOptics); } - UpdateValueVisuals(); + UpdateLensPosition(DisplayRatio(NormalizedValue())); } void RefreshPointerField() From f803310c40923ce9128f5403bc8af9fda6b70499 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:12:05 +0800 Subject: [PATCH 02/61] tune slider active glass response --- src/WinUI.LiquidGlass/LiquidGlassControls.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp index d45cac89..30cdb826 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp @@ -149,16 +149,19 @@ namespace winrt::WinUI::LiquidGlass::implementation GlassBrush(CreateBrush(Preset::SliderThumb)); SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.6)); SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(1.0)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(85.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(85.0)); - SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.08)); - SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.12)); - SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(.01)); - SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(1.45)); - SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(.35)); - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(.02)); - SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.18)); - SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.025)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(70.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(65.0)); + SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.12)); + SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.15)); + SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); + // Kube's slider drives the refraction scale from 0.4 at rest to 0.9 while active. + // Preserve that 2.25x relation instead of the older, much weaker 1.45x response. + SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); + SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); + // The active lens should reveal the refracted backdrop, not become more opaque. + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.05)); + SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); + SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.03)); } From a165f09f6dc3a7c06fb296273000faa57867df9e Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:13:50 +0800 Subject: [PATCH 03/61] docs: document WinUI.LiquidGlass controls --- docs/liquid-glass-controls.md | 177 ++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 docs/liquid-glass-controls.md diff --git a/docs/liquid-glass-controls.md b/docs/liquid-glass-controls.md new file mode 100644 index 00000000..044c20f5 --- /dev/null +++ b/docs/liquid-glass-controls.md @@ -0,0 +1,177 @@ +# WinUI.LiquidGlass controls + +`WinUI.LiquidGlass` is the native C++/WinRT WinUI 3 control package built on top of `WinUI.Composition.Hlsl`. It keeps normal XAML controls, WinUI input semantics, UI Automation, layout, and Composition while replacing the visual material with `LiquidGlassBrush`. + +The controls package is intentionally separate from the core shader/effect package: + +```text +WinUI.Composition.Hlsl + custom HLSL effect runtime + LiquidGlassMaterial + LiquidGlassBrush + +WinUI.LiquidGlass + native C++/WinRT WinUI controls + XAML templates and resources + interaction/motion helpers + per-control glass presets +``` + +## Installation + +Use matching package versions: + +```xml + + + + +``` + +`WinUI.LiquidGlass` has an exact-version dependency on the core package when packed by this repository. + +## Controls + +The package currently contains: + +- `LiquidGlassCard` +- `LiquidGlassMagnifier` +- `LiquidGlassButton` +- `LiquidGlassToggleButton` +- `LiquidGlassHyperlinkButton` +- `LiquidGlassCheckBox` +- `LiquidGlassRadioButton` +- `LiquidGlassSlider` +- `LiquidGlassTextBox` +- `LiquidGlassPasswordBox` +- `LiquidGlassComboBox` +- `LiquidGlassToggleSwitch` +- `LiquidGlassTabBarItem` +- `LiquidGlassTabBar` + +Each control owns its own `LiquidGlassBrush` instance. Replacing `GlassBrush` does not rebuild the shader graph; material parameters remain animatable through Composition property paths. + +## Interaction ownership + +The control library follows one important rule: one visual property has one interaction owner. + +For example, a control should not have XAML VisualState storyboards and a C++ Composition helper both writing the same `Scale`, `Translation`, or optical material property. The current controls split responsibilities between: + +- native WinUI state and input semantics; +- Composition scale/translation/elevation; +- `LiquidGlassBrush` optical parameters; +- shared pointer-field data for local highlight/refraction response. + +This rule is especially important for Slider, ToggleSwitch, and Magnifier, where multiple independent animation systems quickly produce jumps, delayed response, or teardown-time writes. + +## LiquidGlassSlider + +`LiquidGlassSlider` deliberately keeps the real WinUI Slider mechanics. + +The native semantic Thumb remains `18 x 18` DIPs. WinUI uses the real Thumb `ActualWidth`/`ActualHeight` for track layout and pointer-to-value conversion, so the 90 x 60 glass lens must not replace that semantic footprint. + +```text +native Thumb: 18 x 18 + owns value/layout/input/UIA + +visual glass lens: 90 x 60 + owns material/scale/elevation/pointer field +``` + +At rest the glass lens is scaled to `0.6`, producing a visible width of 54 DIPs. While pressed it scales to `1.0`. The scale spring follows the Kube reference values (`stiffness=2000`, `damping=80`). + +The progress fill is a separate Composition rounded-rectangle visual over the real WinUI track. Its width represents the full normalized Slider value, so the blue/gray boundary can move through the glass lens instead of always stopping at the semantic Thumb center. + +A lightweight `LayoutUpdated` correction is still required because WinUI lays out the native Thumb after value changes. That callback only transforms the native Thumb center into track coordinates and updates lens translation. It must not walk the template tree, allocate brushes, or rewrite resources on every layout pass. + +The active optical response mirrors the Kube reference conceptually: + +- rest scale: `0.6` +- pressed scale: `1.0` +- refraction target: approximately `0.4 -> 0.9` relative strength (`2.25x`) +- active tint is reduced so the refracted backdrop becomes more visible +- the native Slider remains responsible for keyboard, pointer value changes, RTL/direction behavior, and UI Automation + +## LiquidGlassToggleSwitch + +`LiquidGlassToggleSwitch` uses a composable `ToggleButton` semantic base because the WinUI `ToggleSwitch` runtime class is sealed. + +The visual model uses the Kube geometry: + +- track: `160 x 67` +- glass knob: `146 x 92` +- rest scale: `0.65` +- pressed scale: `0.9` +- travel: `57.9` DIPs +- overscroll damping: `/22` +- drag threshold: 4 DIPs + +Semantic `IsChecked` remains the source of truth. Drag interaction may preview an intermediate ratio, but release commits the semantic state before the final spring settles. This prevents native `ToggleButton::OnToggle`, pointer capture loss, and the visual ratio from starting conflicting transitions. + +## LiquidGlassMagnifier + +The magnifier follows the Kube interaction model rather than filtering pointer position itself: + +- pointer translation follows input directly (`dragMomentum=false` behavior); +- object scale uses a continuous unit-mass spring (`stiffness=340`, `damping=20`); +- horizontal velocity drives squash/stretch through a second spring (`stiffness=340`, `damping=30`); +- `scaleY = objectScale * max(0.7, 1 - abs(velocityX) / 5000)`; +- `scaleX = objectScale + (1 - scaleY)`; +- magnification and refraction strengthen while dragging; +- external elevation and shader inner-shadow remain separate layers. + +The spring state is continuous across pointer updates. Restarting a new Composition spring for every `PointerMoved` event discards accumulated velocity and makes high-polling-rate mice look unnaturally rigid. + +## Liquid-glass rendering pipeline + +The current material pipeline is: + +```text +Backdrop + -> separable Gaussian horizontal pass + -> separable Gaussian vertical pass + -> LiquidGlass HLSL + -> final SDF coverage +``` + +The Gaussian passes are materialized before the final custom sampler. Rounded coverage is applied after blur/refraction rather than before the blur, so the material does not blur a pre-cut transparent rounded rectangle. + +The primary source sample order remains: + +```text +Source(x + Refraction(x) + Magnification(x + Refraction(x))) +``` + +The shader is built with FXC as SM4/DXBC. The project does not migrate this path to DXC/SM6 because the private Windows Composition effect linker used by this repository consumes the SM4/DXBC form. + +## Pointer specular highlight + +Pointer highlight is calculated in the HLSL material rather than by placing a generic Fluent Reveal overlay above the control. + +Conceptually: + +```text +pointer specular + = edge profile + * angular response + * radial pointer light field +``` + +The shared pointer field supplies local pointer position/velocity to glass surfaces. This allows large control groups to share pointer routing while each surface evaluates its own local specular/refraction response. + +## Teardown and lifetime rules + +`Unloaded` can race `XamlCompositionBrushBase::OnDisconnected`. Control helpers therefore follow a no-write teardown rule: + +- release references and transient pointer state; +- do not restore optics by writing to a closing `CompositionEffectBrush`; +- preserve numeric baselines when required; +- restore/recompute them on the next `Loaded` only after a live brush is available. + +This rule avoids close-time `RO_E_CLOSED`/closed-object writes while still preventing pressed/focused values from becoming a new baseline after navigation or template replacement. + +## Reference implementations + +The interaction and optical work has been compared against several public liquid-glass implementations, including Kube's CSS/SVG examples, `LiquidGlassWinUI`, WebGL liquid-glass experiments, and WinUIEssentials reveal/focus helpers. Reference projects are used to validate interaction structure and optical ideas; the production library keeps native WinUI mechanics and its own C++/WinRT/Composition architecture. + +See `THIRD-PARTY-NOTICES.md` in `WinUI.LiquidGlass` for attribution where applicable. From 9e23177eb6d0270cd937ba696ddec8b98426e16a Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:14:06 +0800 Subject: [PATCH 04/61] docs: link liquid glass controls guide --- docs/index.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 2af21abb..6d168d53 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,6 +2,8 @@ `WinUI.Composition.Hlsl` adds custom HLSL nodes to the normal Windows Graphics Effects / `Microsoft.UI.Composition` / WinUI 3 XAML pipeline. It supports C++/WinRT and C#, build-time or runtime compilation, linked multi-source effects, typed animatable properties, and packaged material brushes. +The repository also ships `WinUI.LiquidGlass`, a native C++/WinRT WinUI 3 control package built on the liquid-glass material. See [WinUI.LiquidGlass controls](liquid-glass-controls.md) for control architecture, interaction ownership, Slider/ToggleSwitch/Magnifier behavior, and teardown rules. + ## Start here If this is your first time using the package, read these in order: @@ -9,7 +11,8 @@ If this is your first time using the package, read these in order: 1. [Get started](get-started.md) — install the package, compile a shader, and create a Composition brush. 2. [Concepts](concepts.md) — HLSL vs DXBC vs `.g.h`, shader profiles, effect kinds, linked sources, materialization, and typed properties. 3. [Architecture](architecture.md) — how the WinRT API, shader compiler, Graphics Effects graph, and private Composition adapter fit together. -4. [API reference](api/index.md) — class-by-class public WinRT reference. +4. [WinUI.LiquidGlass controls](liquid-glass-controls.md) — native glass controls, interaction ownership, and control-specific geometry. +5. [API reference](api/index.md) — class-by-class public WinRT reference. ## Installation and compatibility @@ -97,6 +100,7 @@ The package deliberately avoids moving errors that can be detected by FXC/MSBuil ## Design reference +- [WinUI.LiquidGlass controls](liquid-glass-controls.md) - [Sampler resource binding contract](design/resource-binding-contract.md) - [Materialized graph compilation](design/materialized-graph-runtime.md) - [Precompiled and asynchronous shader libraries](design/precompiled-shaders.md) From c4ab62e64c645ee8cda4e596ace5259cc0e6484c Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:14:56 +0800 Subject: [PATCH 05/61] docs: surface WinUI.LiquidGlass package --- README.md | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5520ec82..5c590362 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,19 @@

WinUI.Composition.Hlsl

-

Native HLSL nodes for WinUI 3 Composition, plus XAML material brushes.

+

Native HLSL nodes for WinUI 3 Composition, plus XAML material brushes and native liquid-glass controls.

English · 简体中文

CI - NuGet + WinUI.Composition.Hlsl NuGet + WinUI.LiquidGlass NuGet License C++23 WinUI 3

-## What this package does +## What this repository does `WinUI.Composition.Hlsl` lets application HLSL participate in the existing Windows Graphics Effects / `Microsoft.UI.Composition` / WinUI 3 XAML pipeline: @@ -30,9 +31,27 @@ HLSL / FXC linkable library It is not an app-owned D3D renderer: no `SwapChainPanel`, custom presentation loop, overlay HWND, or second visual tree is required. The public API is WinRT and is consumable from C++/WinRT and C#. +The repository also contains `WinUI.LiquidGlass`, a native C++/WinRT WinUI 3 control library built on top of the core material. It keeps native WinUI input/layout/UI Automation semantics while adding liquid-glass visuals, optical interaction, spring motion, and reusable control presets. + +## Packages + +| Package | Purpose | +| --- | --- | +| `WinUI.Composition.Hlsl` | Core HLSL/Composition runtime, effect graph API, `LiquidGlassMaterial`, and `LiquidGlassBrush`. | +| `WinUI.LiquidGlass` | Native WinUI 3 liquid-glass controls and templates; depends on the matching core package. | + +For controls, reference both packages using matching versions: + +```xml + + + + +``` + ## Requirements and compatibility -The NuGet package requires **Windows App SDK 1.6 or later** and ships native runtime assets for **x86, x64, and ARM64**. +The NuGet packages require **Windows App SDK 1.6 or later** and ship native runtime assets for **x86, x64, and ARM64**. Each validated `master` push is published automatically to NuGet.org as a stable `1.0.` package. @@ -50,12 +69,14 @@ Custom shader execution relies on a private, undocumented Composition implementa - Immutable/cachable `HlslShaderLibrary` objects. - Composition property paths/setters and Composition-thread animation. - `LiquidGlassMaterial` and `LiquidGlassBrush`. +- Native `WinUI.LiquidGlass` controls including card, magnifier, buttons, choice controls, Slider, input controls, ToggleSwitch, and TabBar. +- Separable Gaussian backdrop blur, SDF coverage, refraction/magnification, chromatic dispersion, pointer specular lighting, and control-specific motion/elevation. The public contract does not yet claim multi-source `MaterializedSampler`, arbitrary multi-custom-node graph lowering, or arbitrary native nodes after a custom materialized pass. Those graph-planning features are being developed separately rather than being enabled by removing safety checks. ## Quick start -Add the package and a shader item: +Add the core package and a shader item: ```xml @@ -132,7 +153,7 @@ Compilation and structural validation are setup operations, not rendering operat - rendering does not repeatedly reflect DXBC; - `GetRuntimeCapabilities()` is side-effect free and does not probe/patch the private runtime. -The package keeps runtime checks for facts that are only known at runtime (for example source object/count validity), while deterministic shader-authoring errors are handled by the compiler/build pipeline whenever possible. +Control hot paths follow the same principle. Value/pointer updates should modify existing Composition state, not walk XAML templates or allocate brushes every frame. See the Slider section in [WinUI.LiquidGlass controls](docs/liquid-glass-controls.md). ## Documentation @@ -141,8 +162,9 @@ Start with the documentation set rather than treating the README as the API manu 1. [Get started](docs/get-started.md) 2. [Concepts](docs/concepts.md) 3. [Architecture](docs/architecture.md) -4. [API reference](docs/api/index.md) -5. [Design notes](docs/index.md#design-reference) +4. [WinUI.LiquidGlass controls](docs/liquid-glass-controls.md) +5. [API reference](docs/api/index.md) +6. [Design notes](docs/index.md#design-reference) Useful references: @@ -152,6 +174,9 @@ Useful references: - [HlslShaderLibrary](docs/api/hlsl-shader-library.md) - [HlslProperty](docs/api/hlsl-property.md) - [HlslRuntimeCapabilities](docs/api/hlsl-runtime-capabilities.md) +- [LiquidGlassBrush](docs/api/liquid-glass-brush.md) +- [LiquidGlassMaterial](docs/api/liquid-glass-material.md) +- [WinUI.LiquidGlass controls](docs/liquid-glass-controls.md) - [Sampler resource binding contract](docs/design/resource-binding-contract.md) - [Materialized graph compilation](docs/design/materialized-graph-runtime.md) @@ -166,7 +191,7 @@ Useful references: .\tests\build.ps1 -Language CSharp ``` -CI builds x64/Win32/ARM64 native assets, the CsWinRT projection, generated shader fixtures, a NuGet package, and downstream C++/C# package consumers. Successful `master` push runs publish that validated package directly from `ci.yml` to NuGet.org through OIDC trusted publishing. +CI builds x64/Win32/ARM64 native assets, the CsWinRT projection, generated shader fixtures, both NuGet packages, and downstream C++/C# package consumers. Successful `master` push runs publish the validated packages directly from `ci.yml` to NuGet.org through OIDC trusted publishing. ## License @@ -174,4 +199,4 @@ CI builds x64/Win32/ARM64 native assets, the CsWinRT projection, generated shade ## Thanks -Inspired by @apkipa's WUILiquidGlassDemo work. \ No newline at end of file +Inspired by @apkipa's WUILiquidGlassDemo work. From 0dae4d578925b7d1fb35aa9a48ade4a2c82fba92 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:15:20 +0800 Subject: [PATCH 06/61] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20WinUI.Liquid?= =?UTF-8?q?Glass=20=E6=8E=A7=E4=BB=B6=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_zh_cn.md | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/README_zh_cn.md b/README_zh_cn.md index a37ca9fc..60dd5152 100644 --- a/README_zh_cn.md +++ b/README_zh_cn.md @@ -4,18 +4,19 @@

WinUI.Composition.Hlsl

-

让自定义 HLSL 作为 WinUI 3 Composition 原生 effect node 工作,并最终回到 XAML Brush。

+

让自定义 HLSL 作为 WinUI 3 Composition 原生 effect node 工作,并提供 XAML Brush 与原生液态玻璃控件。

English · 简体中文

CI - NuGet + WinUI.Composition.Hlsl NuGet + WinUI.LiquidGlass NuGet License C++23 WinUI 3

-## 这个包解决什么问题 +## 这个仓库解决什么问题 `WinUI.Composition.Hlsl` 把应用自己的 HLSL 接入现有 Windows Graphics Effects / `Microsoft.UI.Composition` / WinUI 3 XAML 渲染链: @@ -30,11 +31,29 @@ HLSL / FXC linkable library 它不是应用自管的 D3D renderer,不需要 `SwapChainPanel`、自己的 present loop、额外 HWND overlay 或第二套 visual tree。公共 API 是 WinRT,可同时供 C++/WinRT 和 C# 使用。 +仓库还包含 `WinUI.LiquidGlass`:建立在 core material 之上的原生 C++/WinRT WinUI 3 控件库。它保留 WinUI 原生输入、布局和 UI Automation 语义,同时提供液态玻璃材质、光学交互、spring 动效与控件预设。 + +## NuGet 包 + +| 包 | 用途 | +| --- | --- | +| `WinUI.Composition.Hlsl` | HLSL/Composition 核心运行时、effect graph API、`LiquidGlassMaterial`、`LiquidGlassBrush`。 | +| `WinUI.LiquidGlass` | 原生 WinUI 3 液态玻璃控件与模板;依赖相同版本的 core 包。 | + +使用控件库时建议两个包保持相同版本: + +```xml + + + + +``` + ## 版本与兼容性 NuGet 包最低依赖 **Windows App SDK 1.6**,并提供 **x86、x64、ARM64** 三种 native runtime asset。 -每次通过验证的 `master` push 都会自动发布正式 NuGet 包,版本格式为 `1.0.`;例如 CI #80 对应 `1.0.80`。 +每次通过验证的 `master` push 都会自动发布正式 NuGet 包,版本格式为 `1.0.`。 Custom shader backend 依赖未公开的 Composition 私有实现 ABI。遇到无法安全识别的布局时会 fail closed,而不是继续向未知私有结构写入猜测数据。实现细节、支持边界和运行时安全约束见 [整体架构](docs/architecture.md) 与 [Runtime safety](docs/design/runtime-safety.md)。 @@ -49,13 +68,15 @@ Custom shader backend 依赖未公开的 Composition 私有实现 ABI。遇到 - `HlslCompiler` 提供真正需要动态源码时的异步编译; - `HlslShaderLibrary` 可缓存、持久化、重新加载; - Composition property path/setter 与 Composition animation; -- `LiquidGlassMaterial` / `LiquidGlassBrush`。 +- `LiquidGlassMaterial` / `LiquidGlassBrush`; +- `WinUI.LiquidGlass` 原生控件:Card、Magnifier、Button、Choice、Slider、输入控件、ToggleSwitch、TabBar 等; +- separable Gaussian backdrop blur、SDF coverage、折射/放大、色散、pointer specular、按控件区分的 motion/elevation。 当前还没有把 multi-source `MaterializedSampler`、任意多个 custom node 的 graph lowering、custom materialized pass 后任意 native node 宣布为公开稳定能力。这些会通过正式 graph/pass planner 继续推进,而不是简单删掉安全判断。 ## 最短上手 -项目中加入包和 shader: +项目中加入 core 包和 shader: ```xml @@ -132,7 +153,7 @@ Sampler 所需的 private `PSBody*` edge-mode wrapper 以及 `textureN` / `sampl - render 时不会反复做 DXBC reflection; - `GetRuntimeCapabilities()` 无副作用,不会为了查询 capability 去扫描/patch 私有 runtime。 -只有运行时才能知道的问题,例如 source brush 对象、source 数量和 compositor 归属,才保留在 API 边界检查。能在编译/构建阶段确定的错误尽量在那里解决。 +控件 hot path 同样遵守这个原则:高频 Value/pointer 更新应该只改已有 Composition 状态,不能每一帧重新遍历 XAML template、分配 brush 或重写 resource。Slider 的实现约束见 [WinUI.LiquidGlass 控件](docs/liquid-glass-controls.md)。 ## 文档 @@ -141,8 +162,9 @@ README 只负责项目入口,完整文档从这里开始: 1. [上手指南](docs/get-started.md) 2. [基础概念](docs/concepts.md) 3. [整体架构](docs/architecture.md) -4. [API Reference](docs/api/index.md) -5. [设计文档索引](docs/index.md#design-reference) +4. [WinUI.LiquidGlass 控件](docs/liquid-glass-controls.md) +5. [API Reference](docs/api/index.md) +6. [设计文档索引](docs/index.md#design-reference) 常用参考: @@ -152,6 +174,9 @@ README 只负责项目入口,完整文档从这里开始: - [HlslShaderLibrary](docs/api/hlsl-shader-library.md) - [HlslProperty](docs/api/hlsl-property.md) - [HlslRuntimeCapabilities](docs/api/hlsl-runtime-capabilities.md) +- [LiquidGlassBrush](docs/api/liquid-glass-brush.md) +- [LiquidGlassMaterial](docs/api/liquid-glass-material.md) +- [WinUI.LiquidGlass 控件](docs/liquid-glass-controls.md) - [Sampler 资源绑定 ABI](docs/design/resource-binding-contract.md) - [Materialized graph runtime](docs/design/materialized-graph-runtime.md) @@ -166,7 +191,7 @@ README 只负责项目入口,完整文档从这里开始: .\tests\build.ps1 -Language CSharp ``` -CI 会构建 x64/Win32/ARM64 native asset、CsWinRT projection、generated shader fixture、NuGet 包,并使用生成的 NuGet 再构建下游 C++/C# consumer。`master` push 全部验证通过后,会直接由 `ci.yml` 通过 OIDC trusted publishing 发布该包到 NuGet.org。 +CI 会构建 x64/Win32/ARM64 native asset、CsWinRT projection、generated shader fixture、两个 NuGet 包,并使用生成的 NuGet 再构建下游 C++/C# consumer。`master` push 全部验证通过后,会直接由 `ci.yml` 通过 OIDC trusted publishing 发布经过验证的包。 ## License @@ -174,4 +199,4 @@ CI 会构建 x64/Win32/ARM64 native asset、CsWinRT projection、generated shade ## Thanks -项目受到 @apkipa 的 WUILiquidGlassDemo 工作启发。 \ No newline at end of file +项目受到 @apkipa 的 WUILiquidGlassDemo 工作启发。 From cf33b079d81a75932b8c3f0217b1850824b4577a Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 02:17:23 +0800 Subject: [PATCH 07/61] perf: narrow slider optical hot path --- .../include/KubeSliderVisualModel.hpp | 109 +++++++++++++++--- 1 file changed, 96 insertions(+), 13 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp index c8e130b3..5d18af19 100644 --- a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp @@ -41,8 +41,6 @@ namespace winrt::WinUI::LiquidGlass::detail self->RegisterPropertyChangedCallback(Self::GlassBrushProperty(), [this](auto const&, auto const&) { if (!m_loaded) return; - // If the brush is replaced while pressed, never carry the old brush's - // active baseline into the new instance. auto self = static_cast(this); auto current = self->GlassBrush(); if (m_pressOptics.active && @@ -65,9 +63,6 @@ namespace winrt::WinUI::LiquidGlass::detail auto updateValue = [this](auto const&, auto const&) { if (!m_loaded) return; - // Value changes can occur at pointer frequency. Keep this path strictly - // Composition-only; native Slider layout will move the semantic Thumb and - // LayoutUpdated performs the cheap post-layout lens correction. UpdateProgressVisual(); }; self->RegisterPropertyChangedCallback( @@ -84,11 +79,6 @@ namespace winrt::WinUI::LiquidGlass::detail UpdateLensPosition(DisplayRatio(NormalizedValue())); }); - // WinUI updates the native Thumb position during layout. We still need one - // post-layout coordinate correction because the 90x60 glass lens deliberately - // has a different footprint from the 18x18 semantic Thumb. This handler must - // stay lightweight: no tree walking, resource creation, brush allocation, or - // template mutation is allowed here. self->LayoutUpdated([this](auto const&, auto const&) { if (!m_loaded || !m_thumb || !m_surface || !m_track) return; @@ -143,6 +133,99 @@ namespace winrt::WinUI::LiquidGlass::detail return brush; } + static void AnimateSliderOpticsTransition( + Microsoft::UI::Xaml::DependencyObject const& owner, + WinUI::Composition::Hlsl::LiquidGlassBrush const& brush, + OpticsSnapshot const& from) + { + if (!owner || !brush || !from.active || !MotionAnimationsEnabled(owner)) return; + + auto const durationMs = std::clamp( + implementation::LiquidGlassInteraction::GetOpticsTransitionDuration(owner), 0.0, 2000.0); + if (durationMs <= 0.0) return; + + auto material = brush.Material(); + if (!material) return; + auto effect = material.EffectBrush(); + if (!effect) return; + auto compositionBrush = effect.EffectBrush(); + if (!compositionBrush) return; + + auto easing = compositionBrush.Compositor().CreateCubicBezierEasingFunction( + { .20f, 0.0f }, { 0.0f, 1.0f }); + auto const duration = std::chrono::milliseconds{ + static_cast(std::lround(durationMs)) }; + + AnimateOpticsScalar(effect, compositionBrush, easing, duration, + L"RefractionStrength", from.refraction, brush.RefractionStrength()); + AnimateOpticsScalar(effect, compositionBrush, easing, duration, + L"TintOpacity", from.tintOpacity, brush.TintOpacity()); + AnimateOpticsScalar(effect, compositionBrush, easing, duration, + L"HighlightStrength", from.highlight, brush.HighlightStrength()); + AnimateOpticsScalar(effect, compositionBrush, easing, duration, + L"InnerShadowStrength", from.innerShadow, brush.InnerShadowStrength()); + } + + static void RestoreSliderOptics(OpticsSnapshot& state) + { + if (!state.active || !state.brush) return; + state.brush.RefractionStrength(state.refraction); + state.brush.TintOpacity(state.tintOpacity); + state.brush.HighlightStrength(state.highlight); + state.brush.InnerShadowStrength(state.innerShadow); + state.brush = nullptr; + state.owner = nullptr; + state.active = false; + } + + static void EnterSliderPressedOptics( + Microsoft::UI::Xaml::DependencyObject const& owner, + WinUI::Composition::Hlsl::LiquidGlassBrush const& brush, + OpticsSnapshot& state) + { + if (state.active || !owner || !brush) return; + CaptureOptics(brush, state); + state.owner = owner; + auto const from = state; + + brush.RefractionStrength(std::clamp( + state.refraction * std::clamp( + implementation::LiquidGlassInteraction::GetPressedRefractionMultiplier(owner), 0.0, 4.0) + + std::clamp(implementation::LiquidGlassInteraction::GetPressedRefractionBoost(owner), -128.0, 128.0), + 0.0, + 128.0)); + brush.TintOpacity(std::clamp( + state.tintOpacity + std::clamp( + implementation::LiquidGlassInteraction::GetPressedTintBoost(owner), -1.0, 1.0), + 0.0, + 1.0)); + brush.HighlightStrength(std::clamp( + state.highlight * std::clamp( + implementation::LiquidGlassInteraction::GetPressedHighlightMultiplier(owner), 0.0, 4.0) + + std::clamp(implementation::LiquidGlassInteraction::GetPressedHighlightBoost(owner), -4.0, 4.0), + 0.0, + 4.0)); + brush.InnerShadowStrength(std::clamp( + state.innerShadow + std::clamp( + implementation::LiquidGlassInteraction::GetPressedInnerShadowBoost(owner), -1.0, 1.0), + 0.0, + 1.0)); + + AnimateSliderOpticsTransition(owner, brush, from); + } + + static void LeaveSliderPressedOptics( + Microsoft::UI::Xaml::DependencyObject const& owner, + OpticsSnapshot& state) + { + if (!state.active || !state.brush) return; + auto brush = state.brush; + OpticsSnapshot from; + CaptureOptics(brush, from); + RestoreSliderOptics(state); + AnimateSliderOpticsTransition(owner, brush, from); + } + void ConfigureResources() { auto self = static_cast(this); @@ -398,7 +481,7 @@ namespace winrt::WinUI::LiquidGlass::detail auto self = static_cast(this); auto brush = self->GlassBrush(); if (brush && m_pressOptics.brush && get_abi(brush) == get_abi(m_pressOptics.brush)) - RestoreOptics(m_pressOptics); + RestoreSliderOptics(m_pressOptics); else m_pressOptics = {}; } @@ -449,11 +532,11 @@ namespace winrt::WinUI::LiquidGlass::detail if (m_pressed) { if (!m_pressOptics.active) - EnterPressedOptics(owner, self->GlassBrush(), m_pressOptics); + EnterSliderPressedOptics(owner, self->GlassBrush(), m_pressOptics); } else { - LeavePressedOptics(owner, m_pressOptics); + LeaveSliderPressedOptics(owner, m_pressOptics); } UpdateLensPosition(DisplayRatio(NormalizedValue())); } From b5b575ef0844c5bc5c20d93c38594e5faca52097 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:22:32 +0800 Subject: [PATCH 08/61] fix: detach slider glass lens from native thumb --- .../include/KubeSliderVisualModel.hpp | 117 +++++++++++------- 1 file changed, 70 insertions(+), 47 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp index 5d18af19..fd75e040 100644 --- a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp @@ -30,6 +30,7 @@ namespace winrt::WinUI::LiquidGlass::detail m_pointerField.Detach(false); m_thumb = nullptr; m_surface = nullptr; + m_templateHost = nullptr; m_track = nullptr; m_decrease = nullptr; m_progressVisual = nullptr; @@ -64,6 +65,9 @@ namespace winrt::WinUI::LiquidGlass::detail { if (!m_loaded) return; UpdateProgressVisual(); + // The glass lens is a sibling overlay, so its position can follow Value + // immediately instead of waiting for the native Thumb's next layout pass. + UpdateLensPosition(DisplayRatio(NormalizedValue())); }; self->RegisterPropertyChangedCallback( Microsoft::UI::Xaml::Controls::Primitives::RangeBase::ValueProperty(), updateValue); @@ -79,12 +83,6 @@ namespace winrt::WinUI::LiquidGlass::detail UpdateLensPosition(DisplayRatio(NormalizedValue())); }); - self->LayoutUpdated([this](auto const&, auto const&) - { - if (!m_loaded || !m_thumb || !m_surface || !m_track) return; - UpdateLensPosition(DisplayRatio(NormalizedValue())); - }); - auto bind = [self](auto routedEvent, Windows::Foundation::IInspectable& storage, auto&& callback) { using Handler = Microsoft::UI::Xaml::Input::PointerEventHandler; @@ -284,51 +282,63 @@ namespace winrt::WinUI::LiquidGlass::detail auto const thumbName = horizontal ? L"HorizontalThumb" : L"VerticalThumb"; auto const trackName = horizontal ? L"HorizontalTrackRect" : L"VerticalTrackRect"; auto const decreaseName = horizontal ? L"HorizontalDecreaseRect" : L"VerticalDecreaseRect"; + auto const templateName = horizontal ? L"HorizontalTemplate" : L"VerticalTemplate"; auto thumb = FindNamedDescendant(root, thumbName) .try_as(); if (!thumb) thumb = FindFirstDescendant(root); auto track = FindNamedDescendant(root, trackName).try_as(); auto decrease = FindNamedDescendant(root, decreaseName).try_as(); - if (!thumb || !track) return; + auto templateHost = FindNamedDescendant(root, templateName) + .try_as(); + if (!thumb || !track || !templateHost) return; bool const thumbChanged = !m_thumb || get_abi(m_thumb) != get_abi(thumb); bool const trackChanged = !m_track || get_abi(m_track) != get_abi(track); + bool const hostChanged = !m_templateHost || get_abi(m_templateHost) != get_abi(templateHost); + m_thumb = thumb; m_track = track; m_decrease = decrease; if (thumbChanged) { + // Keep the real WinUI Slider contract intact. The native Thumb remains + // exactly 18x18 and owns all value/layout/input/UIA mechanics. thumb.Width(kSemanticThumbExtent); thumb.Height(kSemanticThumbExtent); thumb.Margin({ 0.0, 0.0, 0.0, 0.0 }); - - auto surface = FindFirstDescendant(thumb); - m_surface = surface; - if (surface) - { - surface.Width(horizontal ? kVisualWidth : kVisualHeight); - surface.Height(horizontal ? kVisualHeight : kVisualWidth); - surface.HorizontalAlignment(Microsoft::UI::Xaml::HorizontalAlignment::Center); - surface.VerticalAlignment(Microsoft::UI::Xaml::VerticalAlignment::Center); - surface.Margin({ 0.0, 0.0, 0.0, 0.0 }); - surface.CornerRadius({ 30.0, 30.0, 30.0, 30.0 }); - surface.BorderBrush(SolidBrush(0x33, 0xff, 0xff, 0xff)); - surface.BorderThickness({ 1.0, 1.0, 1.0, 1.0 }); - Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(surface, true); - if (!surface.Shadow()) surface.Shadow(Microsoft::UI::Xaml::Media::ThemeShadow{}); - } - if (auto inner = FindNamedDescendant(thumb, L"SliderInnerThumb") .try_as()) { inner.Visibility(Microsoft::UI::Xaml::Visibility::Collapsed); } } - else if (!m_surface) + + // Do not place the 90x60 glass inside the 18x18 Thumb subtree. The stock + // Thumb template can clip/measure descendants to the semantic footprint, + // which is exactly what reduced the lens to the tiny dark ring seen at runtime. + // Instead add an independent, non-hit-test sibling to the stock Slider template. + if (hostChanged || !m_surface) { - m_surface = FindFirstDescendant(thumb); + m_templateHost = templateHost; + Microsoft::UI::Xaml::Controls::Border surface; + surface.Width(horizontal ? kVisualWidth : kVisualHeight); + surface.Height(horizontal ? kVisualHeight : kVisualWidth); + surface.HorizontalAlignment(Microsoft::UI::Xaml::HorizontalAlignment::Left); + surface.VerticalAlignment(Microsoft::UI::Xaml::VerticalAlignment::Top); + surface.IsHitTestVisible(false); + surface.CornerRadius({ 30.0, 30.0, 30.0, 30.0 }); + surface.BorderBrush(SolidBrush(0x33, 0xff, 0xff, 0xff)); + surface.BorderThickness({ 1.0, 1.0, 1.0, 1.0 }); + Microsoft::UI::Xaml::Controls::Grid::SetRow(surface, 0); + Microsoft::UI::Xaml::Controls::Grid::SetRowSpan(surface, 3); + Microsoft::UI::Xaml::Controls::Grid::SetColumn(surface, 0); + Microsoft::UI::Xaml::Controls::Grid::SetColumnSpan(surface, 3); + Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(surface, true); + surface.Shadow(Microsoft::UI::Xaml::Media::ThemeShadow{}); + templateHost.Children().Append(surface); + m_surface = surface; } if (trackChanged) @@ -409,46 +419,58 @@ namespace winrt::WinUI::LiquidGlass::detail void UpdateLensPosition(double displayRatio) { - if (!m_surface || !m_thumb || !m_track) return; + if (!m_surface || !m_track || !m_templateHost) return; auto self = static_cast(this); auto const horizontal = self->Orientation() == Microsoft::UI::Xaml::Controls::Orientation::Horizontal; - auto const visualExtent = (horizontal ? kVisualWidth : kVisualHeight) * kRestScale; + auto const authoredPrimary = horizontal ? kVisualWidth : kVisualHeight; + auto const authoredCross = horizontal ? kVisualHeight : kVisualWidth; + auto const visualExtent = authoredPrimary * kRestScale; auto const trackExtent = horizontal ? m_track.ActualWidth() : m_track.ActualHeight(); if (trackExtent <= 0.0) return; - double nativeCenter = kSemanticThumbExtent * .5; + double trackOriginPrimary = 0.0; + double trackCenterCross = authoredCross * .5; try { - auto transform = m_thumb.TransformToVisual(m_track); - auto center = transform.TransformPoint({ - static_cast(m_thumb.ActualWidth() * .5), - static_cast(m_thumb.ActualHeight() * .5) }); - nativeCenter = horizontal ? center.X : center.Y; + auto transform = m_track.TransformToVisual(m_templateHost); + auto origin = transform.TransformPoint({ 0.0f, 0.0f }); + trackOriginPrimary = horizontal ? origin.X : origin.Y; + trackCenterCross = horizontal + ? origin.Y + m_track.ActualHeight() * .5 + : origin.X + m_track.ActualWidth() * .5; } catch (...) { - return; + // The next SizeChanged/value update will retry after the template is arranged. } + // Kube constrains the lens center using its rendered rest footprint (54 DIPs), + // not the 18-DIP native input Thumb. Keep that visual mapping while the native + // Slider remains the sole semantic/value owner. auto const halfVisual = visualExtent * .5; auto const usable = std::max(0.0, trackExtent - visualExtent); - auto const desiredCenter = halfVisual + std::clamp(displayRatio, 0.0, 1.0) * usable; - auto const correction = desiredCenter - nativeCenter; + auto const desiredCenter = trackOriginPrimary + + halfVisual + std::clamp(displayRatio, 0.0, 1.0) * usable; + auto const primaryTranslation = desiredCenter - authoredPrimary * .5; + auto const crossTranslation = trackCenterCross - authoredCross * .5; auto translation = m_surface.Translation(); - auto const newX = horizontal ? correction : 0.0; - auto const newY = horizontal ? 0.0 : correction; - auto const newZ = m_pressed ? kPressedElevation : kRestElevation; - if (std::abs(static_cast(translation.x) - newX) <= .01 && - std::abs(static_cast(translation.y) - newY) <= .01 && - std::abs(static_cast(translation.z) - newZ) <= .01) + auto const newPrimary = static_cast(primaryTranslation); + auto const newCross = static_cast(crossTranslation); + auto const newZ = static_cast(m_pressed ? kPressedElevation : kRestElevation); + + if (horizontal) { - return; + translation.x = newPrimary; + translation.y = newCross; + } + else + { + translation.x = newCross; + translation.y = newPrimary; } - translation.x = static_cast(newX); - translation.y = static_cast(newY); - translation.z = static_cast(newZ); + translation.z = newZ; m_surface.Translation(translation); } @@ -562,6 +584,7 @@ namespace winrt::WinUI::LiquidGlass::detail PointerFieldSurface m_pointerField; Microsoft::UI::Xaml::Controls::Primitives::Thumb m_thumb{ nullptr }; Microsoft::UI::Xaml::Controls::Border m_surface{ nullptr }; + Microsoft::UI::Xaml::Controls::Grid m_templateHost{ nullptr }; Microsoft::UI::Xaml::Shapes::Rectangle m_track{ nullptr }; Microsoft::UI::Xaml::Shapes::Rectangle m_decrease{ nullptr }; Microsoft::UI::Composition::ShapeVisual m_progressVisual{ nullptr }; From 54d91d5371a59c6e9b9ad53680d10b95e80b1242 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:22:36 +0800 Subject: [PATCH 09/61] fix: restore switch glass body contrast --- src/WinUI.LiquidGlass/LiquidGlassPresets.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp index 16588944..3915f989 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp @@ -62,8 +62,11 @@ namespace winrt::WinUI::LiquidGlass::implementation b.RefractionStrength(10.8); b.DispersionStrength(.5); b.BezelWidth(19); b.GlassThickness(47); b.RefractiveIndex(1.5); b.HighlightStrength(.52); b.HighlightSharpness(1.6); b.SpecularSaturation(6); b.SpecularWidth(1); - b.TintOpacity(.07); b.InnerShadowStrength(.04); - b.FallbackColor({ 0x38, 0xff, 0xff, 0xff }); break; + // Kube keeps a visible white glass body at rest and reveals substantially + // more of the refracted backdrop while pressed. A moderate authored tint + // preserves the material on WinUI without flattening it to an opaque pill. + b.TintOpacity(.42); b.InnerShadowStrength(.04); + b.FallbackColor({ 0x70, 0xff, 0xff, 0xff }); break; case LiquidGlassPreset::Magnifier: b.CornerRadius(75); b.BlurRadius(0); b.RefractionStrength(19.2); b.DispersionStrength(.55); b.BezelWidth(25); b.GlassThickness(110); From cb831a45786159cfd76bcd309ce3a05cf5ba0370 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:22:59 +0800 Subject: [PATCH 10/61] fix: align switch active glass response with Kube --- src/WinUI.LiquidGlass/LiquidGlassControls.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp index 30cdb826..f690b9c3 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp @@ -171,17 +171,19 @@ namespace winrt::WinUI::LiquidGlass::implementation GlassBrush(CreateBrush(Preset::ToggleSwitchKnob)); SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.65)); SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(.9)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(90.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(85.0)); - SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.08)); - SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.12)); - SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(.01)); - SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(1.35)); - SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(.25)); - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(.02)); - SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.18)); - SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.025)); - SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.08)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(75.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(70.0)); + SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.10)); + SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.14)); + SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); + // Kube drives the optical scale from 0.4 at rest to 0.9 while active. + SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); + SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); + // The authored knob body is .42 tint; pressed should reveal the backdrop at ~.10. + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.32)); + SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); + SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); + SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.05)); } Windows::Foundation::IInspectable LiquidGlassToggleSwitch::Header() const { return m_header; } From 06ac9cbc7b024965e59942b54b3316cfafb5b4c3 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:24:19 +0800 Subject: [PATCH 11/61] fix: bind switch glass directly to knob surface --- .../include/KubeToggleSwitchVisualModel.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp index 2a79afd5..9ce79a83 100644 --- a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp @@ -66,13 +66,24 @@ namespace winrt::WinUI::LiquidGlass::detail m_knob = FindNamedDescendant(root, L"SwitchKnob").try_as(); m_surface = FindNamedDescendant(root, L"SwitchKnobSurface").try_as(); auto track = FindNamedDescendant(root, L"Track").try_as(); - if (!m_knob || !track) + if (!m_knob || !m_surface || !track) { m_pointerField.Detach(false); ClearTrackVisual(false); return; } + // Bind the authored material directly to the rendered knob surface. Do not + // rely on the ToggleButton Background -> TemplateBinding chain here: control + // state/template precedence can otherwise leave only the rim/shadow visible. + if (auto surfaceBorder = m_surface.try_as()) + { + auto glass = self->GlassBrush(); + surfaceBorder.Background(glass + ? glass.as() + : Microsoft::UI::Xaml::Media::Brush{ nullptr }); + } + if (!m_trackHost || get_abi(m_trackHost) != get_abi(track)) { ClearTrackVisual(true); From bc7a70f37226adeea2043a66073845045646a302 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:56:08 +0800 Subject: [PATCH 12/61] fix: hide native slider thumb visual completely --- src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp index fd75e040..332f924a 100644 --- a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp @@ -229,7 +229,6 @@ namespace winrt::WinUI::LiquidGlass::detail auto self = static_cast(this); auto const track = SolidBrush(0x66, 0x89, 0x89, 0x8f); auto const transparent = SolidBrush(0x00, 0x00, 0x00, 0x00); - auto const stroke = SolidBrush(0x33, 0xff, 0xff, 0xff); self->Background(track); self->Foreground(transparent); @@ -245,7 +244,7 @@ namespace winrt::WinUI::LiquidGlass::detail insert(L"SliderThumbBackgroundPressed", transparent); insert(L"SliderThumbBackgroundDisabled", transparent); insert(L"SliderOuterThumbBackground", transparent); - insert(L"SliderThumbBorderBrush", stroke); + insert(L"SliderThumbBorderBrush", transparent); insert(L"SliderTrackFill", track); insert(L"SliderTrackFillPointerOver", track); insert(L"SliderTrackFillPressed", track); @@ -308,6 +307,10 @@ namespace winrt::WinUI::LiquidGlass::detail thumb.Width(kSemanticThumbExtent); thumb.Height(kSemanticThumbExtent); thumb.Margin({ 0.0, 0.0, 0.0, 0.0 }); + // The semantic Thumb must remain fully interactive, but none of the + // stock WinUI thumb visuals should render behind the sibling glass lens. + // Opacity does not disable hit testing or native Slider mechanics. + thumb.Opacity(0.0); if (auto inner = FindNamedDescendant(thumb, L"SliderInnerThumb") .try_as()) { From 4c9e26cbd4e4631824ef7cc664dc6e61c21a63bb Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:56:51 +0800 Subject: [PATCH 13/61] refactor: keep switch spring state continuous --- .../include/KubeToggleSwitchVisualModel.hpp | 273 ++++++++++++------ 1 file changed, 191 insertions(+), 82 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp index 9ce79a83..74d28f2e 100644 --- a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp @@ -93,7 +93,22 @@ namespace winrt::WinUI::LiquidGlass::detail m_trackHost.Background(nullptr); Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(m_knob, true); - if (!m_dragging) SyncSemanticState(false); + if (!m_initialized) + { + m_currentRatio = SemanticRatio(self->IsChecked()); + m_targetRatio = m_currentRatio; + m_visualRatio = m_currentRatio; + m_currentScale = kRestScale; + m_targetScale = kRestScale; + m_ratioVelocity = 0.0; + m_scaleVelocity = 0.0; + m_initialized = true; + ApplyDynamicVisual(); + } + else if (!m_dragging) + { + SyncSemanticState(false); + } RefreshPointerField(); } @@ -120,12 +135,15 @@ namespace winrt::WinUI::LiquidGlass::detail static constexpr double kTravelDips = 57.9; static constexpr double kOverscrollDamping = 22.0; static constexpr double kDragThresholdDips = 4.0; + using Clock = std::chrono::steady_clock; static constexpr double kRestScale = .65; static constexpr double kPressedScale = .9; - static constexpr double kPositionDampingRatio = 1.2649110640673518; // k=1000,d=80 - static constexpr double kPositionPeriodMs = 198.69176531592203; - static constexpr double kScaleDampingRatio = .8944271909999159; // k=2000,d=80 - static constexpr double kScalePeriodMs = 140.49629462081452; + // Kube / Motion uses unit-mass springs with these literal coefficients. + static constexpr double kPositionStiffness = 1000.0; + static constexpr double kPositionDamping = 80.0; + static constexpr double kScaleStiffness = 2000.0; + static constexpr double kScaleDamping = 80.0; + static constexpr auto kDynamicsInterval = std::chrono::milliseconds{ 16 }; static double SemanticRatio(Windows::Foundation::IReference const& value) { @@ -146,19 +164,43 @@ namespace winrt::WinUI::LiquidGlass::detail return { static_cast(PhysicalRatio(semanticRatio) * kTravelDips), 0.0f, 0.0f }; } - static Microsoft::UI::Composition::ShapeVisual CreateTrackLayer( - Microsoft::UI::Composition::Compositor const& compositor, - Windows::UI::Color const& color) + static uint8_t LerpByte(uint8_t from, uint8_t to, double t) { - auto geometry = compositor.CreateRoundedRectangleGeometry(); - geometry.Size({ static_cast(kTrackWidth), static_cast(kTrackHeight) }); - geometry.CornerRadius({ static_cast(kTrackRadius), static_cast(kTrackRadius) }); - auto shape = compositor.CreateSpriteShape(geometry); - shape.FillBrush(compositor.CreateColorBrush(color)); - auto visual = compositor.CreateShapeVisual(); - visual.Size({ static_cast(kTrackWidth), static_cast(kTrackHeight) }); - visual.Shapes().Append(shape); - return visual; + return static_cast(std::lround( + static_cast(from) + + (static_cast(to) - static_cast(from)) * std::clamp(t, 0.0, 1.0))); + } + + static Windows::UI::Color TrackColor(double ratio) + { + auto const t = std::clamp(ratio, 0.0, 1.0); + // CSS #94949F77 -> #3BBF4EEE from Kube Switch.tsx. + return { + LerpByte(0x77, 0xee, t), + LerpByte(0x94, 0x3b, t), + LerpByte(0x94, 0xbf, t), + LerpByte(0x9f, 0x4e, t) + }; + } + + static void StepSpring( + double target, + double stiffness, + double damping, + double dt, + double& value, + double& velocity) + { + // Preserve spring velocity across rapid target changes. Substep at 120 Hz + // so k=2000 remains stable even if the UI thread briefly misses a frame. + auto const steps = std::max(1, static_cast(std::ceil(dt / (1.0 / 120.0)))); + auto const h = dt / static_cast(steps); + for (int i = 0; i < steps; ++i) + { + auto const acceleration = stiffness * (target - value) - damping * velocity; + velocity += acceleration * h; + value += velocity * h; + } } void BuildTrackVisual() @@ -166,19 +208,19 @@ namespace winrt::WinUI::LiquidGlass::detail if (!m_trackHost) return; auto hostVisual = Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(m_trackHost); auto compositor = hostVisual.Compositor(); - m_ratio = compositor.CreatePropertySet(); - m_ratio.InsertScalar(L"Value", 0.0f); - m_rootVisual = compositor.CreateContainerVisual(); - m_rootVisual.Size({ static_cast(kTrackWidth), static_cast(kTrackHeight) }); - m_baseVisual = CreateTrackLayer(compositor, { 0x77, 0x94, 0x94, 0x9f }); - m_checkedVisual = CreateTrackLayer(compositor, { 0xee, 0x3b, 0xbf, 0x4e }); - m_rootVisual.Children().InsertAtBottom(m_baseVisual); - m_rootVisual.Children().InsertAtTop(m_checkedVisual); - - auto checkedOpacity = compositor.CreateExpressionAnimation(L"ratio.Value"); - checkedOpacity.SetReferenceParameter(L"ratio", m_ratio); - m_checkedVisual.StartAnimation(L"Opacity", checkedOpacity); - Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetElementChildVisual(m_trackHost, m_rootVisual); + + auto geometry = compositor.CreateRoundedRectangleGeometry(); + geometry.Size({ static_cast(kTrackWidth), static_cast(kTrackHeight) }); + geometry.CornerRadius({ static_cast(kTrackRadius), static_cast(kTrackRadius) }); + + m_trackBrush = compositor.CreateColorBrush(TrackColor(m_currentRatio)); + auto shape = compositor.CreateSpriteShape(geometry); + shape.FillBrush(m_trackBrush); + + m_trackVisual = compositor.CreateShapeVisual(); + m_trackVisual.Size({ static_cast(kTrackWidth), static_cast(kTrackHeight) }); + m_trackVisual.Shapes().Append(shape); + Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetElementChildVisual(m_trackHost, m_trackVisual); } void ClearTrackVisual(bool detachHost) @@ -186,70 +228,125 @@ namespace winrt::WinUI::LiquidGlass::detail if (detachHost && m_trackHost) Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetElementChildVisual(m_trackHost, nullptr); m_trackHost = nullptr; - m_ratio = nullptr; - m_rootVisual = nullptr; - m_baseVisual = nullptr; - m_checkedVisual = nullptr; + m_trackVisual = nullptr; + m_trackBrush = nullptr; } - void SetVisualRatio(double ratio, bool animate) + void ApplyDynamicVisual() { - if (!m_knob || !m_ratio) return; - m_visualRatio = ratio; - auto const trackRatio = static_cast(std::clamp(ratio, 0.0, 1.0)); - m_ratio.StopAnimation(L"Value"); + if (m_knob) + { + SetElementTranslation(m_knob, TranslationForRatio(m_currentRatio)); + SetElementScale(m_knob, m_currentScale, m_currentScale); + } + if (m_trackBrush) + m_trackBrush.Color(TrackColor(m_currentRatio)); + } + + void EnsureDynamicsTimer() + { + if (!m_loaded) return; + auto self = static_cast(this); + if (!m_dynamicsTimer) + { + m_dynamicsTimer = self->DispatcherQueue().CreateTimer(); + m_dynamicsTimer.Interval(kDynamicsInterval); + m_dynamicsTimer.IsRepeating(true); + m_dynamicsTimer.Tick([this](auto const&, auto const&) { TickDynamics(); }); + } + if (!m_dynamicsTimer.IsRunning()) + { + m_lastDynamicsTick = Clock::now(); + m_dynamicsTimer.Start(); + } + } - if (!animate) + void TickDynamics() + { + if (!m_loaded) { - m_ratio.InsertScalar(L"Value", trackRatio); - SetElementTranslation(m_knob, TranslationForRatio(ratio)); + if (m_dynamicsTimer) m_dynamicsTimer.Stop(); return; } + auto const now = Clock::now(); + auto dt = std::chrono::duration(now - m_lastDynamicsTick).count(); + m_lastDynamicsTick = now; + dt = std::clamp(dt, 1.0 / 240.0, 1.0 / 30.0); + + StepSpring( + m_targetRatio, + kPositionStiffness, + kPositionDamping, + dt, + m_currentRatio, + m_ratioVelocity); + StepSpring( + m_targetScale, + kScaleStiffness, + kScaleDamping, + dt, + m_currentScale, + m_scaleVelocity); + + ApplyDynamicVisual(); + + auto const settled = + std::abs(m_currentRatio - m_targetRatio) < .0005 && + std::abs(m_ratioVelocity) < .005 && + std::abs(m_currentScale - m_targetScale) < .0005 && + std::abs(m_scaleVelocity) < .005; + if (settled) + { + m_currentRatio = m_targetRatio; + m_ratioVelocity = 0.0; + m_currentScale = m_targetScale; + m_scaleVelocity = 0.0; + ApplyDynamicVisual(); + if (m_dynamicsTimer) m_dynamicsTimer.Stop(); + } + } + + void SetRatioTarget(double ratio, bool animate) + { + m_visualRatio = ratio; + m_targetRatio = ratio; + auto self = static_cast(this); auto owner = self->template try_as(); - if (!owner || !MotionAnimationsEnabled(owner)) + if (!animate || !owner || !MotionAnimationsEnabled(owner)) { - m_ratio.InsertScalar(L"Value", trackRatio); - SetElementTranslation(m_knob, TranslationForRatio(ratio)); + m_currentRatio = ratio; + m_ratioVelocity = 0.0; + ApplyDynamicVisual(); return; } - - auto scalarSpring = m_ratio.Compositor().CreateSpringScalarAnimation(); - scalarSpring.FinalValue(box_value(trackRatio).as>()); - scalarSpring.DampingRatio(static_cast(kPositionDampingRatio)); - scalarSpring.Period(std::chrono::milliseconds{ static_cast(std::lround(kPositionPeriodMs)) }); - m_ratio.StartAnimation(L"Value", scalarSpring); - - auto visual = Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(m_knob); - auto vectorSpring = visual.Compositor().CreateSpringVector3Animation(); - vectorSpring.FinalValue(box_value(TranslationForRatio(ratio)).as< - Windows::Foundation::IReference>()); - vectorSpring.DampingRatio(static_cast(kPositionDampingRatio)); - vectorSpring.Period(std::chrono::milliseconds{ static_cast(std::lround(kPositionPeriodMs)) }); - visual.StartAnimation(L"Translation", vectorSpring); + EnsureDynamicsTimer(); } - void AnimateKnobScale(bool pressed) + void SetScaleTarget(double scale, bool animate) { - if (!m_knob) return; + m_targetScale = scale; + auto self = static_cast(this); auto owner = self->template try_as(); - if (!owner) return; - auto const value = pressed ? kPressedScale : kRestScale; - AnimateElementScaleSpring(owner, m_knob, value, value, kScaleDampingRatio, kScalePeriodMs); + if (!animate || !owner || !MotionAnimationsEnabled(owner)) + { + m_currentScale = scale; + m_scaleVelocity = 0.0; + ApplyDynamicVisual(); + return; + } + EnsureDynamicsTimer(); } void SyncSemanticState(bool animate) { - if (!m_knob || !m_ratio) return; + if (!m_knob || !m_trackBrush) return; auto self = static_cast(this); - SetVisualRatio(SemanticRatio(self->IsChecked()), animate); + SetRatioTarget(SemanticRatio(self->IsChecked()), animate); if (!m_dragging) - { - if (animate) AnimateKnobScale(false); - else SetElementScale(m_knob, kRestScale, kRestScale); - } + SetScaleTarget(kRestScale, animate); } void BeginDrag(Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) @@ -259,8 +356,8 @@ namespace winrt::WinUI::LiquidGlass::detail auto element = self->template try_as(); auto frameworkElement = self->template try_as(); if (!element || !frameworkElement) return; - if (!m_knob || !m_ratio) RefreshVisualModel(); - if (!m_knob || !m_ratio) return; + if (!m_knob || !m_trackBrush) RefreshVisualModel(); + if (!m_knob || !m_trackBrush) return; auto xamlRoot = frameworkElement.XamlRoot(); m_coordinateRoot = xamlRoot ? xamlRoot.Content() : Microsoft::UI::Xaml::UIElement{ nullptr }; @@ -279,7 +376,7 @@ namespace winrt::WinUI::LiquidGlass::detail m_nativeToggleConsumedThisGesture = false; m_consumeNextToggle = false; m_dragging = true; - AnimateKnobScale(true); + SetScaleTarget(kPressedScale, true); } void UpdateDrag(Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) @@ -295,7 +392,7 @@ namespace winrt::WinUI::LiquidGlass::detail auto ratio = m_baseRatio + delta / kTravelDips; if (ratio < 0.0) ratio /= kOverscrollDamping; else if (ratio > 1.0) ratio = 1.0 + (ratio - 1.0) / kOverscrollDamping; - SetVisualRatio(ratio, false); + SetRatioTarget(ratio, true); } void EndDragFromRelease(Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) @@ -327,7 +424,7 @@ namespace winrt::WinUI::LiquidGlass::detail else { // No semantic callback will fire; settle the overscrolled ratio explicitly. - SetVisualRatio(targetChecked ? 1.0 : 0.0, true); + SetRatioTarget(targetChecked ? 1.0 : 0.0, true); } FinishPointer(true, false); return; @@ -368,9 +465,8 @@ namespace winrt::WinUI::LiquidGlass::detail m_pointerId = 0; if (settlePosition) - SetVisualRatio(SemanticRatio(self->IsChecked()), animate); - if (animate) AnimateKnobScale(false); - else if (m_knob) SetElementScale(m_knob, kRestScale, kRestScale); + SetRatioTarget(SemanticRatio(self->IsChecked()), animate); + SetScaleTarget(kRestScale, animate); if (element && m_ownsCapture) element.ReleasePointerCaptures(); m_ownsCapture = false; @@ -411,8 +507,14 @@ namespace winrt::WinUI::LiquidGlass::detail m_pointerField.Detach(false); m_coordinateRoot = nullptr; m_pointerId = 0; + if (m_dynamicsTimer) + { + m_dynamicsTimer.Stop(); + m_dynamicsTimer = nullptr; + } m_knob = nullptr; m_surface = nullptr; + m_initialized = false; ClearTrackVisual(false); } @@ -421,19 +523,26 @@ namespace winrt::WinUI::LiquidGlass::detail Microsoft::UI::Xaml::FrameworkElement m_surface{ nullptr }; Microsoft::UI::Xaml::Controls::Border m_trackHost{ nullptr }; Microsoft::UI::Xaml::UIElement m_coordinateRoot{ nullptr }; - Microsoft::UI::Composition::CompositionPropertySet m_ratio{ nullptr }; - Microsoft::UI::Composition::ContainerVisual m_rootVisual{ nullptr }; - Microsoft::UI::Composition::ShapeVisual m_baseVisual{ nullptr }; - Microsoft::UI::Composition::ShapeVisual m_checkedVisual{ nullptr }; + Microsoft::UI::Composition::ShapeVisual m_trackVisual{ nullptr }; + Microsoft::UI::Composition::CompositionColorBrush m_trackBrush{ nullptr }; + Microsoft::UI::Dispatching::DispatcherQueueTimer m_dynamicsTimer{ nullptr }; Windows::Foundation::IInspectable m_pointerPressedHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerMovedHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerReleasedHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerCaptureLostHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerCanceledHandler{ nullptr }; Windows::Foundation::Point m_dragStart{}; + Clock::time_point m_lastDynamicsTick{}; double m_baseRatio{}; double m_visualRatio{}; + double m_currentRatio{}; + double m_targetRatio{}; + double m_ratioVelocity{}; + double m_currentScale{ kRestScale }; + double m_targetScale{ kRestScale }; + double m_scaleVelocity{}; std::uint32_t m_pointerId{}; + bool m_initialized{}; bool m_loaded{}; bool m_dragging{}; bool m_dragOverrideArmed{}; From 7e99d1bf5cf8bfe32b84570fa9370910ea5a83f5 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:57:21 +0800 Subject: [PATCH 14/61] fix: strengthen switch rest glass body --- src/WinUI.LiquidGlass/LiquidGlassPresets.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp index 3915f989..b7c99594 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp @@ -65,8 +65,8 @@ namespace winrt::WinUI::LiquidGlass::implementation // Kube keeps a visible white glass body at rest and reveals substantially // more of the refracted backdrop while pressed. A moderate authored tint // preserves the material on WinUI without flattening it to an opaque pill. - b.TintOpacity(.42); b.InnerShadowStrength(.04); - b.FallbackColor({ 0x70, 0xff, 0xff, 0xff }); break; + b.TintOpacity(.78); b.InnerShadowStrength(.04); + b.FallbackColor({ 0xc0, 0xff, 0xff, 0xff }); break; case LiquidGlassPreset::Magnifier: b.CornerRadius(75); b.BlurRadius(0); b.RefractionStrength(19.2); b.DispersionStrength(.55); b.BezelWidth(25); b.GlassThickness(110); From 052958ab7049dca00bfa724470c91bfa26a84d5a Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 20:57:24 +0800 Subject: [PATCH 15/61] fix: preserve transparent pressed switch state --- src/WinUI.LiquidGlass/LiquidGlassControls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp index f690b9c3..a3f1e927 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp @@ -180,7 +180,7 @@ namespace winrt::WinUI::LiquidGlass::implementation SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); // The authored knob body is .42 tint; pressed should reveal the backdrop at ~.10. - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.32)); + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.68)); SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.05)); From 3c33b0c8d177283aa4303ed2f290dfefae15b2f1 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:09:12 +0800 Subject: [PATCH 16/61] fix: center initial scale before first layout --- .../include/MotionAnimation.hpp | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/MotionAnimation.hpp b/src/WinUI.LiquidGlass/include/MotionAnimation.hpp index fb4c23ba..e060736f 100644 --- a/src/WinUI.LiquidGlass/include/MotionAnimation.hpp +++ b/src/WinUI.LiquidGlass/include/MotionAnimation.hpp @@ -29,6 +29,35 @@ namespace winrt::WinUI::LiquidGlass::detail Windows::Foundation::Numerics::float2{ 0.0f, 1.0f }); } + inline Windows::Foundation::Numerics::float3 ResolveScaleCenter( + Microsoft::UI::Xaml::FrameworkElement const& element) + { + // Runtime-created visuals (for example the Slider's sibling glass lens) can be + // scaled before their first arrange pass. In that window ActualWidth/Height are + // still zero even when explicit Width/Height are already authored. Falling back + // to the authored dimensions keeps the initial scale centered instead of scaling + // around the top-left corner and visibly shifting the control. + auto width = element.ActualWidth(); + auto height = element.ActualHeight(); + + if (!(width > 0.0)) + { + auto const authoredWidth = element.Width(); + if (authoredWidth > 0.0) width = authoredWidth; + } + if (!(height > 0.0)) + { + auto const authoredHeight = element.Height(); + if (authoredHeight > 0.0) height = authoredHeight; + } + + return { + static_cast(std::max(0.0, width) * .5), + static_cast(std::max(0.0, height) * .5), + 0.0f + }; + } + inline void SetElementScale( Microsoft::UI::Xaml::FrameworkElement const& element, double x, @@ -37,10 +66,7 @@ namespace winrt::WinUI::LiquidGlass::detail if (!element) return; auto visual = Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(element); - visual.CenterPoint({ - static_cast(element.ActualWidth() * .5), - static_cast(element.ActualHeight() * .5), - 0.0f }); + visual.CenterPoint(ResolveScaleCenter(element)); visual.StopAnimation(L"Scale"); visual.Scale({ static_cast(std::clamp(x, .25, 4.0)), @@ -67,10 +93,7 @@ namespace winrt::WinUI::LiquidGlass::detail } auto visual = Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(element); - visual.CenterPoint({ - static_cast(element.ActualWidth() * .5), - static_cast(element.ActualHeight() * .5), - 0.0f }); + visual.CenterPoint(ResolveScaleCenter(element)); auto animation = visual.Compositor().CreateSpringVector3Animation(); auto const finalValue = Windows::Foundation::Numerics::float3{ static_cast(x), static_cast(y), 1.0f }; @@ -95,10 +118,7 @@ namespace winrt::WinUI::LiquidGlass::detail y = std::clamp(y, .25, 4.0); auto visual = Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(element); - visual.CenterPoint({ - static_cast(element.ActualWidth() * .5), - static_cast(element.ActualHeight() * .5), - 0.0f }); + visual.CenterPoint(ResolveScaleCenter(element)); auto const duration = std::clamp(durationMs, 0.0, 2000.0); if (!MotionAnimationsEnabled(owner) || duration <= 0.0) From b4057ccf141c5041a0755a6c0610f301cc7ab09b Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:27:31 +0800 Subject: [PATCH 17/61] fix: sync slider after layout and match Kube press spring --- .../include/KubeSliderVisualModel.hpp | 162 ++++++++++++++++-- 1 file changed, 146 insertions(+), 16 deletions(-) diff --git a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp index 332f924a..0a9dd953 100644 --- a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "ChildSurfaceInteraction.hpp" @@ -27,7 +28,16 @@ namespace winrt::WinUI::LiquidGlass::detail self->Unloaded([this](auto const&, auto const&) { m_loaded = false; + DetachInitialLayoutSync(); m_pointerField.Detach(false); + if (m_scaleTimer) + { + m_scaleTimer.Stop(); + m_scaleTimer = nullptr; + } + m_currentScale = kRestScale; + m_targetScale = kRestScale; + m_scaleVelocity = 0.0; m_thumb = nullptr; m_surface = nullptr; m_templateHost = nullptr; @@ -114,11 +124,13 @@ namespace winrt::WinUI::LiquidGlass::detail static constexpr double kSemanticThumbExtent = 18.0; static constexpr double kVisualWidth = 90.0; static constexpr double kVisualHeight = 60.0; + using Clock = std::chrono::steady_clock; static constexpr double kRestScale = 0.6; static constexpr double kRestElevation = 6.0; static constexpr double kPressedElevation = 10.0; - static constexpr double kScaleDampingRatio = 0.8944271909999159; // k=2000,d=80 - static constexpr double kScalePeriodMs = 140.49629462081452; + static constexpr double kScaleStiffness = 2000.0; + static constexpr double kScaleDamping = 80.0; + static constexpr auto kScaleInterval = std::chrono::milliseconds{ 16 }; static Microsoft::UI::Xaml::Media::SolidColorBrush SolidBrush( uint8_t alpha, @@ -156,6 +168,8 @@ namespace winrt::WinUI::LiquidGlass::detail AnimateOpticsScalar(effect, compositionBrush, easing, duration, L"RefractionStrength", from.refraction, brush.RefractionStrength()); + AnimateOpticsScalar(effect, compositionBrush, easing, duration, + L"DispersionStrength", from.dispersion, brush.DispersionStrength()); AnimateOpticsScalar(effect, compositionBrush, easing, duration, L"TintOpacity", from.tintOpacity, brush.TintOpacity()); AnimateOpticsScalar(effect, compositionBrush, easing, duration, @@ -168,6 +182,7 @@ namespace winrt::WinUI::LiquidGlass::detail { if (!state.active || !state.brush) return; state.brush.RefractionStrength(state.refraction); + state.brush.DispersionStrength(state.dispersion); state.brush.TintOpacity(state.tintOpacity); state.brush.HighlightStrength(state.highlight); state.brush.InnerShadowStrength(state.innerShadow); @@ -192,6 +207,11 @@ namespace winrt::WinUI::LiquidGlass::detail std::clamp(implementation::LiquidGlassInteraction::GetPressedRefractionBoost(owner), -128.0, 128.0), 0.0, 128.0)); + brush.DispersionStrength(std::clamp( + state.dispersion * std::clamp( + implementation::LiquidGlassInteraction::GetPressedDispersionMultiplier(owner), 0.0, 8.0), + 0.0, + 16.0)); brush.TintOpacity(std::clamp( state.tintOpacity + std::clamp( implementation::LiquidGlassInteraction::GetPressedTintBoost(owner), -1.0, 1.0), @@ -271,6 +291,119 @@ namespace winrt::WinUI::LiquidGlass::detail return reversed; } + static void StepSpring( + double target, + double stiffness, + double damping, + double dt, + double& value, + double& velocity) + { + auto const steps = std::max(1, static_cast(std::ceil(dt / (1.0 / 120.0)))); + auto const h = dt / static_cast(steps); + for (int i = 0; i < steps; ++i) + { + auto const acceleration = stiffness * (target - value) - damping * velocity; + velocity += acceleration * h; + value += velocity * h; + } + } + + void EnsureScaleTimer() + { + if (!m_loaded) return; + auto self = static_cast(this); + if (!m_scaleTimer) + { + m_scaleTimer = self->DispatcherQueue().CreateTimer(); + m_scaleTimer.Interval(kScaleInterval); + m_scaleTimer.IsRepeating(true); + m_scaleTimer.Tick([this](auto const&, auto const&) { TickScaleDynamics(); }); + } + if (!m_scaleTimer.IsRunning()) + { + m_lastScaleTick = Clock::now(); + m_scaleTimer.Start(); + } + } + + void TickScaleDynamics() + { + if (!m_loaded || !m_surface) + { + if (m_scaleTimer) m_scaleTimer.Stop(); + return; + } + + auto const now = Clock::now(); + auto dt = std::chrono::duration(now - m_lastScaleTick).count(); + m_lastScaleTick = now; + dt = std::clamp(dt, 1.0 / 240.0, 1.0 / 30.0); + + StepSpring( + m_targetScale, + kScaleStiffness, + kScaleDamping, + dt, + m_currentScale, + m_scaleVelocity); + SetElementScale(m_surface, m_currentScale, m_currentScale); + + auto const settled = + std::abs(m_currentScale - m_targetScale) < .0005 && + std::abs(m_scaleVelocity) < .005; + if (settled) + { + m_currentScale = m_targetScale; + m_scaleVelocity = 0.0; + SetElementScale(m_surface, m_currentScale, m_currentScale); + if (m_scaleTimer) m_scaleTimer.Stop(); + } + } + + void SetScaleTarget(double scale, bool animate) + { + m_targetScale = scale; + auto self = static_cast(this); + auto owner = self->template try_as(); + if (!animate || !owner || !MotionAnimationsEnabled(owner)) + { + m_currentScale = scale; + m_scaleVelocity = 0.0; + if (m_surface) SetElementScale(m_surface, scale, scale); + return; + } + EnsureScaleTimer(); + } + + void DetachInitialLayoutSync() + { + if (m_templateHost && m_initialLayoutHooked) + m_templateHost.LayoutUpdated(m_initialLayoutToken); + m_initialLayoutHooked = false; + } + + void ArmInitialLayoutSync() + { + if (!m_templateHost || m_initialLayoutHooked) return; + m_initialLayoutHooked = true; + m_initialLayoutToken = m_templateHost.LayoutUpdated([this](auto const&, auto const&) + { + if (!m_loaded || !m_track || !m_surface || !m_templateHost) return; + + auto self = static_cast(this); + auto const horizontal = self->Orientation() == Microsoft::UI::Xaml::Controls::Orientation::Horizontal; + auto const extent = horizontal ? m_track.ActualWidth() : m_track.ActualHeight(); + if (!(extent > 0.0)) return; + + UpdateProgressVisual(); + UpdateLensPosition(DisplayRatio(NormalizedValue())); + ApplyInteractionState(false); + RefreshPointerField(); + DetachInitialLayoutSync(); + }); + } + void ResolveTemplateParts() { auto self = static_cast(this); @@ -324,6 +457,7 @@ namespace winrt::WinUI::LiquidGlass::detail // Instead add an independent, non-hit-test sibling to the stock Slider template. if (hostChanged || !m_surface) { + if (hostChanged) DetachInitialLayoutSync(); m_templateHost = templateHost; Microsoft::UI::Xaml::Controls::Border surface; surface.Width(horizontal ? kVisualWidth : kVisualHeight); @@ -354,6 +488,8 @@ namespace winrt::WinUI::LiquidGlass::detail { decrease.Opacity(0.0); } + + ArmInitialLayoutSync(); } void BuildProgressVisual() @@ -539,20 +675,7 @@ namespace winrt::WinUI::LiquidGlass::detail if (!owner) return; auto const targetScale = m_pressed ? 1.0 : kRestScale; - if (animate) - { - AnimateElementScaleSpring( - owner, - m_surface, - targetScale, - targetScale, - kScaleDampingRatio, - kScalePeriodMs); - } - else - { - SetElementScale(m_surface, targetScale, targetScale); - } + SetScaleTarget(targetScale, animate); if (m_pressed) { @@ -593,11 +716,18 @@ namespace winrt::WinUI::LiquidGlass::detail Microsoft::UI::Composition::ShapeVisual m_progressVisual{ nullptr }; Microsoft::UI::Composition::CompositionRoundedRectangleGeometry m_progressGeometry{ nullptr }; Microsoft::UI::Composition::CompositionSpriteShape m_progressShape{ nullptr }; + Microsoft::UI::Dispatching::DispatcherQueueTimer m_scaleTimer{ nullptr }; + Clock::time_point m_lastScaleTick{}; + Microsoft::UI::Xaml::event_token m_initialLayoutToken{}; + double m_currentScale{ kRestScale }; + double m_targetScale{ kRestScale }; + double m_scaleVelocity{}; Windows::Foundation::IInspectable m_pointerPressedHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerReleasedHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerCaptureLostHandler{ nullptr }; Windows::Foundation::IInspectable m_pointerCanceledHandler{ nullptr }; OpticsSnapshot m_pressOptics; + bool m_initialLayoutHooked{}; bool m_loaded{}; bool m_pressed{}; }; From cc49f68a4b6864d65f8a096e1ac20ae3ef237e71 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:27:57 +0800 Subject: [PATCH 18/61] fix: use WinRT event token for slider layout sync --- src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp index 0a9dd953..68cc3df1 100644 --- a/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeSliderVisualModel.hpp @@ -718,7 +718,7 @@ namespace winrt::WinUI::LiquidGlass::detail Microsoft::UI::Composition::CompositionSpriteShape m_progressShape{ nullptr }; Microsoft::UI::Dispatching::DispatcherQueueTimer m_scaleTimer{ nullptr }; Clock::time_point m_lastScaleTick{}; - Microsoft::UI::Xaml::event_token m_initialLayoutToken{}; + winrt::event_token m_initialLayoutToken{}; double m_currentScale{ kRestScale }; double m_targetScale{ kRestScale }; double m_scaleVelocity{}; From 79037afa2eda354ebc39f9ba458ea3718ad40dab Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:28:01 +0800 Subject: [PATCH 19/61] fix: commit switch drag state on capture loss --- .../include/KubeToggleSwitchVisualModel.hpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp index 74d28f2e..fbf51b8c 100644 --- a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp @@ -51,7 +51,7 @@ namespace winrt::WinUI::LiquidGlass::detail bind(Microsoft::UI::Xaml::UIElement::PointerReleasedEvent(), m_pointerReleasedHandler, [this](auto const&, Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) { EndDragFromRelease(args); }); bind(Microsoft::UI::Xaml::UIElement::PointerCaptureLostEvent(), m_pointerCaptureLostHandler, - [this](auto const&, auto const&) { CancelDrag(true); }); + [this](auto const&, auto const&) { EndDragFromCaptureLoss(); }); bind(Microsoft::UI::Xaml::UIElement::PointerCanceledEvent(), m_pointerCanceledHandler, [this](auto const&, auto const&) { CancelDrag(true); }); } @@ -410,6 +410,9 @@ namespace winrt::WinUI::LiquidGlass::detail if (m_dragOverrideArmed) { + // A real drag owns the release semantics. Prevent a later native click + // from toggling the state a second time. + args.Handled(true); auto const targetChecked = std::clamp(m_visualRatio, 0.0, 1.0) >= .5; auto current = self->IsChecked(); bool const changed = !current || current.Value() != targetChecked; @@ -439,6 +442,46 @@ namespace winrt::WinUI::LiquidGlass::detail FinishPointer(true, !releaseInside); } + void EndDragFromCaptureLoss() + { + if (!m_loaded || !m_dragging) + { + m_dragOverrideArmed = false; + return; + } + + // ButtonBase may release its capture before our routed PointerReleased + // handler is reached. If the pointer crossed the drag threshold, treat + // capture loss as the end of that drag rather than silently snapping back. + if (m_dragOverrideArmed) + { + auto self = static_cast(this); + auto const targetChecked = std::clamp(m_visualRatio, 0.0, 1.0) >= .5; + auto current = self->IsChecked(); + bool const changed = !current || current.Value() != targetChecked; + + m_dragOverrideArmed = false; + m_nativeToggleConsumedThisGesture = true; + m_consumeNextToggle = true; + m_ownsCapture = false; + + if (changed) + { + self->IsChecked(box_value(targetChecked).as< + Windows::Foundation::IReference>()); + } + else + { + SetRatioTarget(targetChecked ? 1.0 : 0.0, true); + } + + FinishPointer(true, false); + return; + } + + CancelDrag(true); + } + void CancelDrag(bool animate) { if (!m_loaded || !m_dragging) From d50ba51ce573b35991f1d908d4978666e9c940a4 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:28:25 +0800 Subject: [PATCH 20/61] tune active slider and switch glass response --- src/WinUI.LiquidGlass/LiquidGlassControls.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp index a3f1e927..1ba3dd47 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp @@ -149,8 +149,8 @@ namespace winrt::WinUI::LiquidGlass::implementation GlassBrush(CreateBrush(Preset::SliderThumb)); SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.6)); SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(1.0)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(70.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(65.0)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(60.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(55.0)); SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.12)); SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.15)); SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); @@ -158,8 +158,12 @@ namespace winrt::WinUI::LiquidGlass::implementation // Preserve that 2.25x relation instead of the older, much weaker 1.45x response. SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); - // The active lens should reveal the refracted backdrop, not become more opaque. - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.05)); + // Kube's displacement map keeps strong colored/specular edges while the white + // body fades away. Our HLSL has an explicit RGB dispersion control, so raise it + // only for the active lens rather than baking excessive chroma into the rest state. + SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(1.55)); + // The authored slider body is .55 tint; pressed should reveal the backdrop at ~.10. + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.45)); SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.03)); @@ -172,14 +176,15 @@ namespace winrt::WinUI::LiquidGlass::implementation SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.65)); SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(.9)); SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(75.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(70.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(60.0)); SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.10)); SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.14)); SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); // Kube drives the optical scale from 0.4 at rest to 0.9 while active. SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); - // The authored knob body is .42 tint; pressed should reveal the backdrop at ~.10. + SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(1.45)); + // The authored knob body is .78 tint; pressed should reveal the backdrop at ~.10. SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.68)); SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); From 7e706b144a573650a23a51b55ce6f166f21d3e44 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:28:27 +0800 Subject: [PATCH 21/61] refine compact glass optical presets --- src/WinUI.LiquidGlass/LiquidGlassPresets.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp index b7c99594..34903f17 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp @@ -53,13 +53,13 @@ namespace winrt::WinUI::LiquidGlass::implementation b.FallbackColor({ 0x36, 0xff, 0xff, 0xff }); break; case LiquidGlassPreset::SliderThumb: b.CornerRadius(30); b.BlurRadius(0); b.RefractionStrength(13.2); - b.DispersionStrength(.5); b.BezelWidth(16); b.GlassThickness(80); + b.DispersionStrength(.85); b.BezelWidth(16); b.GlassThickness(80); b.RefractiveIndex(1.45); b.HighlightStrength(.48); b.HighlightSharpness(1.7); - b.SpecularSaturation(7); b.SpecularWidth(1); b.TintOpacity(.07); - b.InnerShadowStrength(.07); b.FallbackColor({ 0x38, 0xff, 0xff, 0xff }); break; + b.SpecularSaturation(7); b.SpecularWidth(1); b.TintOpacity(.55); + b.InnerShadowStrength(.07); b.FallbackColor({ 0x90, 0xff, 0xff, 0xff }); break; case LiquidGlassPreset::ToggleSwitchKnob: b.SurfaceProfile(Profile::Lip); b.CornerRadius(46); b.BlurRadius(.2); - b.RefractionStrength(10.8); b.DispersionStrength(.5); b.BezelWidth(19); + b.RefractionStrength(10.8); b.DispersionStrength(.70); b.BezelWidth(19); b.GlassThickness(47); b.RefractiveIndex(1.5); b.HighlightStrength(.52); b.HighlightSharpness(1.6); b.SpecularSaturation(6); b.SpecularWidth(1); // Kube keeps a visible white glass body at rest and reveals substantially From f188cd1ed82f284805d3f59f5472e432f12f9d9f Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:40:43 +0800 Subject: [PATCH 22/61] fix: match Kube slider rest material --- src/WinUI.LiquidGlass/LiquidGlassPresets.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp index 34903f17..28562974 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassPresets.cpp @@ -55,8 +55,11 @@ namespace winrt::WinUI::LiquidGlass::implementation b.CornerRadius(30); b.BlurRadius(0); b.RefractionStrength(13.2); b.DispersionStrength(.85); b.BezelWidth(16); b.GlassThickness(80); b.RefractiveIndex(1.45); b.HighlightStrength(.48); b.HighlightSharpness(1.7); - b.SpecularSaturation(7); b.SpecularWidth(1); b.TintOpacity(.55); - b.InnerShadowStrength(.07); b.FallbackColor({ 0x90, 0xff, 0xff, 0xff }); break; + b.SpecularSaturation(7); b.SpecularWidth(1); + // Kube's slider thumb is an opaque white body at rest. The track should + // disappear completely underneath it and only become visible after press. + b.TintOpacity(1.0); b.InnerShadowStrength(.07); + b.FallbackColor({ 0xff, 0xff, 0xff, 0xff }); break; case LiquidGlassPreset::ToggleSwitchKnob: b.SurfaceProfile(Profile::Lip); b.CornerRadius(46); b.BlurRadius(.2); b.RefractionStrength(10.8); b.DispersionStrength(.70); b.BezelWidth(19); From 3dfd3b9b82a61bd29de29e11d93f8348c92e7fd8 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:40:47 +0800 Subject: [PATCH 23/61] fix: strengthen active slider glass optics --- src/WinUI.LiquidGlass/LiquidGlassControls.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp index 1ba3dd47..051b0dbb 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp @@ -161,9 +161,9 @@ namespace winrt::WinUI::LiquidGlass::implementation // Kube's displacement map keeps strong colored/specular edges while the white // body fades away. Our HLSL has an explicit RGB dispersion control, so raise it // only for the active lens rather than baking excessive chroma into the rest state. - SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(1.55)); - // The authored slider body is .55 tint; pressed should reveal the backdrop at ~.10. - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.45)); + SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(2.6)); + // Kube fades the white body from 1.0 to 0.1 while active. + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.90)); SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.03)); From b0c8ff7d7c0558ca32e41169c48bf22dddb4bace Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 21:41:43 +0800 Subject: [PATCH 24/61] fix: keep switch drag state authoritative --- .../include/KubeToggleSwitchVisualModel.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp index fbf51b8c..759a647b 100644 --- a/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp +++ b/src/WinUI.LiquidGlass/include/KubeToggleSwitchVisualModel.hpp @@ -417,7 +417,10 @@ namespace winrt::WinUI::LiquidGlass::detail auto current = self->IsChecked(); bool const changed = !current || current.Value() != targetChecked; m_dragOverrideArmed = false; - m_consumeNextToggle = releaseInside && !m_nativeToggleConsumedThisGesture; + // A completed drag owns the semantic result. Any native ToggleButton + // toggle that arrives afterward belongs to the same gesture and must be + // suppressed regardless of where the captured pointer was released. + m_consumeNextToggle = !m_nativeToggleConsumedThisGesture; if (changed) { From 319b7dab07cb5dde9f0231e794c889aecba11881 Mon Sep 17 00:00:00 2001 From: hoshiizumiya Date: Fri, 18 Sep 2026 23:24:04 +0800 Subject: [PATCH 25/61] Code style [ci skip] --- src/WinUI.LiquidGlass/LiquidGlassControls.cpp | 378 +++++---- src/WinUI.LiquidGlass/LiquidGlassControls.h | 438 +++++----- .../LiquidGlassInteraction.cpp | 2 +- src/WinUI.LiquidGlass/LiquidGlassTabBar.cpp | 94 +-- .../Themes/Controls/Buttons.xaml | 137 ++- .../Themes/Controls/Compatibility.xaml | 31 +- .../Themes/Controls/Selectors.xaml | 149 +++- .../Themes/Controls/Slider.xaml | 9 +- .../Themes/Controls/Surfaces.xaml | 29 +- .../Themes/Controls/ToggleSwitch.xaml | 50 +- src/WinUI.LiquidGlass/Themes/Generic.xaml | 4 +- .../Themes/NativeInputs.xaml | 484 +++++------ .../Themes/PasswordInput.xaml | 172 ++-- src/WinUI.LiquidGlass/Themes/Specialized.xaml | 236 ++---- src/WinUI.LiquidGlass/Themes/TabBar.xaml | 64 +- .../Themes/settings.xamlstyler | 6 + tests/Cpp/MainWindow.xaml | 797 +++++++++++++++--- 17 files changed, 1823 insertions(+), 1257 deletions(-) create mode 100644 src/WinUI.LiquidGlass/Themes/settings.xamlstyler diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp index 051b0dbb..352da9e7 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "pch.h" #include "winrt_module_imports.h" #include "LiquidGlassControls.h" @@ -19,180 +19,204 @@ namespace winrt::WinUI::LiquidGlass::implementation { - namespace - { - namespace Xaml = Microsoft::UI::Xaml; - namespace Controls = Xaml::Controls; - namespace Media = Xaml::Media; - - using Brush = WinUI::Composition::Hlsl::LiquidGlassBrush; - using Preset = WinUI::LiquidGlass::LiquidGlassPreset; - - Media::Brush AsBrush(Brush const& value) - { - return value ? value.as() : Media::Brush{ nullptr }; - } - - Brush CreateBrush(Preset preset) - { - return WinUI::LiquidGlass::LiquidGlassPresets::CreateBrush(preset); - } - } - - LiquidGlassCard::LiquidGlassCard() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Panel)); - } - - LiquidGlassButton::LiquidGlassButton() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Button)); - } - - LiquidGlassToggleButton::LiquidGlassToggleButton() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Button)); - } - - LiquidGlassHyperlinkButton::LiquidGlassHyperlinkButton() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Button)); - } - - LiquidGlassCheckBox::LiquidGlassCheckBox() - { - DefaultStyleKey(box_value(xaml_typename())); - auto brush = CreateBrush(Preset::Choice); - brush.CornerRadius(5.0); - GlassBrush(brush); - } - - LiquidGlassRadioButton::LiquidGlassRadioButton() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Choice)); - } - - LiquidGlassComboBox::LiquidGlassComboBox() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Choice)); - SetValue(LiquidGlassInteraction::FocusedScaleProperty(), box_value(1.01)); - SetValue(LiquidGlassInteraction::FocusedTintBoostProperty(), box_value(.04)); - } - - LiquidGlassTextBox::LiquidGlassTextBox() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Input)); - SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.98)); - SetValue(LiquidGlassInteraction::FocusedScaleProperty(), box_value(1.0)); - SetValue(LiquidGlassInteraction::FocusedTintBoostProperty(), box_value(.15)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(140.0)); - } - - void LiquidGlassPasswordBox::ApplyGlassBrush(Brush const& value) - { - m_glassBrush = value; - if (m_passwordBox) m_passwordBox.Background(AsBrush(value)); - } - - LiquidGlassPasswordBox::LiquidGlassPasswordBox() - { - m_passwordBox = Controls::PasswordBox{}; - m_passwordBox.HorizontalAlignment(Xaml::HorizontalAlignment::Stretch); - HorizontalContentAlignment(Xaml::HorizontalAlignment::Stretch); - Content(m_passwordBox); - GlassBrush(CreateBrush(Preset::Input)); - SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.99)); - SetValue(LiquidGlassInteraction::FocusedScaleProperty(), box_value(1.0)); - SetValue(LiquidGlassInteraction::FocusedTintBoostProperty(), box_value(.04)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(140.0)); - } - - hstring LiquidGlassPasswordBox::PlaceholderText() const { return m_passwordBox ? m_passwordBox.PlaceholderText() : hstring{}; } - void LiquidGlassPasswordBox::PlaceholderText(hstring const& value) { if (m_passwordBox) m_passwordBox.PlaceholderText(value); } - hstring LiquidGlassPasswordBox::Password() const { return m_passwordBox ? m_passwordBox.Password() : hstring{}; } - void LiquidGlassPasswordBox::Password(hstring const& value) { if (m_passwordBox) m_passwordBox.Password(value); } - - LiquidGlassMagnifier::LiquidGlassMagnifier() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::Magnifier)); - SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.8)); - SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(1.0)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(105.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(180.0)); - SetValue(LiquidGlassInteraction::ElasticityProperty(), box_value(.13)); - SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(1.25)); - SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(0.0)); - SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.08)); - SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.02)); - SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.07)); - SetValue(LiquidGlassInteraction::ActiveMagnificationMultiplierProperty(), box_value(2.0)); - } - - void LiquidGlassSlider::ApplyGlassBrush(Brush const& value) - { - m_glassBrush = value; - detail::KubeSliderVisualModel::RefreshVisual(); - } - - LiquidGlassSlider::LiquidGlassSlider() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::SliderThumb)); - SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.6)); - SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(1.0)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(60.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(55.0)); - SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.12)); - SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.15)); - SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); - // Kube's slider drives the refraction scale from 0.4 at rest to 0.9 while active. - // Preserve that 2.25x relation instead of the older, much weaker 1.45x response. - SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); - SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); - // Kube's displacement map keeps strong colored/specular edges while the white - // body fades away. Our HLSL has an explicit RGB dispersion control, so raise it - // only for the active lens rather than baking excessive chroma into the rest state. - SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(2.6)); - // Kube fades the white body from 1.0 to 0.1 while active. - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.90)); - SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); - SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); - SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.03)); - } - - LiquidGlassToggleSwitch::LiquidGlassToggleSwitch() - { - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(CreateBrush(Preset::ToggleSwitchKnob)); - SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.65)); - SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(.9)); - SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(75.0)); - SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(60.0)); - SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.10)); - SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.14)); - SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); - // Kube drives the optical scale from 0.4 at rest to 0.9 while active. - SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); - SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); - SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(1.45)); - // The authored knob body is .78 tint; pressed should reveal the backdrop at ~.10. - SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.68)); - SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); - SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); - SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.05)); - } - - Windows::Foundation::IInspectable LiquidGlassToggleSwitch::Header() const { return m_header; } - void LiquidGlassToggleSwitch::Header(Windows::Foundation::IInspectable const& value) { m_header = value; Content(value); } - bool LiquidGlassToggleSwitch::IsOn() const { auto v = IsChecked(); return v && v.Value(); } - void LiquidGlassToggleSwitch::IsOn(bool value) { IsChecked(box_value(value).as>()); } + namespace + { + namespace Xaml = Microsoft::UI::Xaml; + namespace Controls = Xaml::Controls; + namespace Media = Xaml::Media; + + using Brush = WinUI::Composition::Hlsl::LiquidGlassBrush; + using Preset = WinUI::LiquidGlass::LiquidGlassPreset; + + Media::Brush AsBrush(Brush const& value) + { + return value ? value.as() : Media::Brush{ nullptr }; + } + + Brush CreateBrush(Preset preset) + { + return WinUI::LiquidGlass::LiquidGlassPresets::CreateBrush(preset); + } + } + + LiquidGlassCard::LiquidGlassCard() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Panel)); + } + + LiquidGlassButton::LiquidGlassButton() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Button)); + } + + LiquidGlassToggleButton::LiquidGlassToggleButton() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Button)); + } + + LiquidGlassHyperlinkButton::LiquidGlassHyperlinkButton() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Button)); + } + + LiquidGlassCheckBox::LiquidGlassCheckBox() + { + DefaultStyleKey(box_value(xaml_typename())); + auto brush = CreateBrush(Preset::Choice); + brush.CornerRadius(5.0); + GlassBrush(brush); + } + + LiquidGlassRadioButton::LiquidGlassRadioButton() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Choice)); + } + + LiquidGlassComboBox::LiquidGlassComboBox() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Choice)); + SetValue(LiquidGlassInteraction::FocusedScaleProperty(), box_value(1.01)); + SetValue(LiquidGlassInteraction::FocusedTintBoostProperty(), box_value(.04)); + } + + LiquidGlassTextBox::LiquidGlassTextBox() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Input)); + SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.98)); + SetValue(LiquidGlassInteraction::FocusedScaleProperty(), box_value(1.0)); + SetValue(LiquidGlassInteraction::FocusedTintBoostProperty(), box_value(.15)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(140.0)); + } + + void LiquidGlassPasswordBox::ApplyGlassBrush(Brush const& value) + { + m_glassBrush = value; + if (m_passwordBox) m_passwordBox.Background(AsBrush(value)); + } + + LiquidGlassPasswordBox::LiquidGlassPasswordBox() + { + m_passwordBox = Controls::PasswordBox{}; + m_passwordBox.HorizontalAlignment(Xaml::HorizontalAlignment::Stretch); + HorizontalContentAlignment(Xaml::HorizontalAlignment::Stretch); + Content(m_passwordBox); + GlassBrush(CreateBrush(Preset::Input)); + SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.99)); + SetValue(LiquidGlassInteraction::FocusedScaleProperty(), box_value(1.0)); + SetValue(LiquidGlassInteraction::FocusedTintBoostProperty(), box_value(.04)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(140.0)); + } + + hstring LiquidGlassPasswordBox::PlaceholderText() const + { + return m_passwordBox ? m_passwordBox.PlaceholderText() : hstring{}; + } + void LiquidGlassPasswordBox::PlaceholderText(hstring const& value) + { + if (m_passwordBox) m_passwordBox.PlaceholderText(value); + } + hstring LiquidGlassPasswordBox::Password() const + { + return m_passwordBox ? m_passwordBox.Password() : hstring{}; + } + void LiquidGlassPasswordBox::Password(hstring const& value) + { + if (m_passwordBox) m_passwordBox.Password(value); + } + + LiquidGlassMagnifier::LiquidGlassMagnifier() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::Magnifier)); + SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.8)); + SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(1.0)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(105.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(180.0)); + SetValue(LiquidGlassInteraction::ElasticityProperty(), box_value(.13)); + SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(1.25)); + SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(0.0)); + SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.08)); + SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.02)); + SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.07)); + SetValue(LiquidGlassInteraction::ActiveMagnificationMultiplierProperty(), box_value(2.0)); + } + + void LiquidGlassSlider::ApplyGlassBrush(Brush const& value) + { + m_glassBrush = value; + detail::KubeSliderVisualModel::RefreshVisual(); + } + + LiquidGlassSlider::LiquidGlassSlider() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::SliderThumb)); + SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.6)); + SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(1.0)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(60.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(55.0)); + SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.12)); + SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.15)); + SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); + // Kube's slider drives the refraction scale from 0.4 at rest to 0.9 while active. + // Preserve that 2.25x relation instead of the older, much weaker 1.45x response. + SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); + SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); + // Kube's displacement map keeps strong colored/specular edges while the white + // body fades away. Our HLSL has an explicit RGB dispersion control, so raise it + // only for the active lens rather than baking excessive chroma into the rest state. + SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(2.6)); + // Kube fades the white body from 1.0 to 0.1 while active. + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.90)); + SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); + SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); + SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.03)); + } + + LiquidGlassToggleSwitch::LiquidGlassToggleSwitch() + { + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(CreateBrush(Preset::ToggleSwitchKnob)); + SetValue(LiquidGlassInteraction::RestScaleProperty(), box_value(.65)); + SetValue(LiquidGlassInteraction::PressedScaleProperty(), box_value(.9)); + SetValue(LiquidGlassInteraction::MotionDurationProperty(), box_value(75.0)); + SetValue(LiquidGlassInteraction::OpticsTransitionDurationProperty(), box_value(60.0)); + SetValue(LiquidGlassInteraction::PointerOverRefractionMultiplierProperty(), box_value(1.10)); + SetValue(LiquidGlassInteraction::PointerOverHighlightMultiplierProperty(), box_value(1.14)); + SetValue(LiquidGlassInteraction::PointerOverTintBoostProperty(), box_value(0.0)); + // Kube drives the optical scale from 0.4 at rest to 0.9 while active. + SetValue(LiquidGlassInteraction::PressedRefractionMultiplierProperty(), box_value(2.25)); + SetValue(LiquidGlassInteraction::PressedRefractionBoostProperty(), box_value(0.0)); + SetValue(LiquidGlassInteraction::PressedDispersionMultiplierProperty(), box_value(1.45)); + // The authored knob body is .78 tint; pressed should reveal the backdrop at ~.10. + SetValue(LiquidGlassInteraction::PressedTintBoostProperty(), box_value(-.68)); + SetValue(LiquidGlassInteraction::PressedHighlightMultiplierProperty(), box_value(1.25)); + SetValue(LiquidGlassInteraction::PressedHighlightBoostProperty(), box_value(.03)); + SetValue(LiquidGlassInteraction::PressedInnerShadowBoostProperty(), box_value(.05)); + } + + Windows::Foundation::IInspectable LiquidGlassToggleSwitch::Header() const + { + return m_header; + } + void LiquidGlassToggleSwitch::Header(Windows::Foundation::IInspectable const& value) + { + m_header = value; Content(value); + } + bool LiquidGlassToggleSwitch::IsOn() const + { + auto v = IsChecked(); return v && v.Value(); + } + void LiquidGlassToggleSwitch::IsOn(bool value) + { + IsChecked(box_value(value).as>()); + } } diff --git a/src/WinUI.LiquidGlass/LiquidGlassControls.h b/src/WinUI.LiquidGlass/LiquidGlassControls.h index 367c257f..0aaebb17 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassControls.h +++ b/src/WinUI.LiquidGlass/LiquidGlassControls.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include @@ -38,234 +38,262 @@ namespace winrt::WinUI::LiquidGlass::detail { - inline constexpr wchar_t ThemeResourceUri[] = L"ms-appx:///WinUI.LiquidGlass/Themes/Generic.xaml"; + inline constexpr wchar_t ThemeResourceUri[] = L"ms-appx:///WinUI.LiquidGlass/Themes/Generic.xaml"; } namespace winrt::WinUI::LiquidGlass::implementation { - struct LiquidGlassCard : - LiquidGlassCardT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassCard(); - }; + struct LiquidGlassCard : + LiquidGlassCardT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassCard(); + }; - struct LiquidGlassButton : - LiquidGlassButtonT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::PointerMotionHelper, - detail::PressOpticsHelper, - detail::CompactControlMotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassButton(); - }; + struct LiquidGlassButton : + LiquidGlassButtonT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::PointerMotionHelper, + detail::PressOpticsHelper, + detail::CompactControlMotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassButton(); + }; - struct LiquidGlassToggleButton : - LiquidGlassToggleButtonT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::PointerMotionHelper, - detail::PressOpticsHelper, - detail::CompactControlMotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassToggleButton(); - }; + struct LiquidGlassToggleButton : + LiquidGlassToggleButtonT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::PointerMotionHelper, + detail::PressOpticsHelper, + detail::CompactControlMotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassToggleButton(); + }; - struct LiquidGlassHyperlinkButton : - LiquidGlassHyperlinkButtonT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::PointerMotionHelper, - detail::PressOpticsHelper, - detail::CompactControlMotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassHyperlinkButton(); - }; + struct LiquidGlassHyperlinkButton : + LiquidGlassHyperlinkButtonT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::PointerMotionHelper, + detail::PressOpticsHelper, + detail::CompactControlMotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassHyperlinkButton(); + }; - struct LiquidGlassMagnifier : - LiquidGlassMagnifierT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::KubeMagnifierMotionHelper, - detail::MotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassMagnifier(); - }; + struct LiquidGlassMagnifier : + LiquidGlassMagnifierT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::KubeMagnifierMotionHelper, + detail::MotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassMagnifier(); + }; - struct LiquidGlassCheckBox : - LiquidGlassCheckBoxT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::ChoiceGlyphMotionHelper, - detail::PressOpticsHelper, - detail::CompactControlMotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassCheckBox(); - }; + struct LiquidGlassCheckBox : + LiquidGlassCheckBoxT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::ChoiceGlyphMotionHelper, + detail::PressOpticsHelper, + detail::CompactControlMotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassCheckBox(); + }; - struct LiquidGlassRadioButton : - LiquidGlassRadioButtonT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::ChoiceGlyphMotionHelper, - detail::PressOpticsHelper, - detail::CompactControlMotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassRadioButton(); - }; + struct LiquidGlassRadioButton : + LiquidGlassRadioButtonT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::ChoiceGlyphMotionHelper, + detail::PressOpticsHelper, + detail::CompactControlMotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassRadioButton(); + }; - struct LiquidGlassSlider : - LiquidGlassSliderT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::KubeSliderVisualModel, - detail::MotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassSlider(); - void ApplyGlassBrush(WinUI::Composition::Hlsl::LiquidGlassBrush const& value); + struct LiquidGlassSlider : + LiquidGlassSliderT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::KubeSliderVisualModel, + detail::MotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassSlider(); + void ApplyGlassBrush(WinUI::Composition::Hlsl::LiquidGlassBrush const& value); - void OnApplyTemplate() - { - base_type::OnApplyTemplate(); - detail::KubeSliderVisualModel::RefreshVisual(); - } - }; + void OnApplyTemplate() + { + base_type::OnApplyTemplate(); + detail::KubeSliderVisualModel::RefreshVisual(); + } + }; - struct LiquidGlassTextBox : - LiquidGlassTextBoxT, - detail::GlassBrushHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::FocusOpticsHelper - { - LiquidGlassTextBox(); - }; + struct LiquidGlassTextBox : + LiquidGlassTextBoxT, + detail::GlassBrushHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::FocusOpticsHelper + { + LiquidGlassTextBox(); + }; - struct LiquidGlassPasswordBox : - LiquidGlassPasswordBoxT, - detail::GlassBrushHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::FocusOpticsHelper - { - LiquidGlassPasswordBox(); - hstring PlaceholderText() const; - void PlaceholderText(hstring const& value); - hstring Password() const; - void Password(hstring const& value); - void ApplyGlassBrush(WinUI::Composition::Hlsl::LiquidGlassBrush const& value); + struct LiquidGlassPasswordBox : + LiquidGlassPasswordBoxT, + detail::GlassBrushHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::FocusOpticsHelper + { + LiquidGlassPasswordBox(); + hstring PlaceholderText() const; + void PlaceholderText(hstring const& value); + hstring Password() const; + void Password(hstring const& value); + void ApplyGlassBrush(WinUI::Composition::Hlsl::LiquidGlassBrush const& value); - private: - Microsoft::UI::Xaml::Controls::PasswordBox m_passwordBox{ nullptr }; - }; + private: + Microsoft::UI::Xaml::Controls::PasswordBox m_passwordBox{ nullptr }; + }; - struct LiquidGlassComboBox : - LiquidGlassComboBoxT, - detail::GlassBrushHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::FocusOpticsHelper - { - LiquidGlassComboBox(); - }; + struct LiquidGlassComboBox : + LiquidGlassComboBoxT, + detail::GlassBrushHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::FocusOpticsHelper + { + LiquidGlassComboBox(); + }; - struct LiquidGlassToggleSwitch : - LiquidGlassToggleSwitchT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::KubeToggleSwitchVisualModel, - detail::SwitchElevationHelper, - detail::PressOpticsHelper, - detail::MotionDefaults - { - constexpr static auto ResourceUri = detail::ThemeResourceUri; - LiquidGlassToggleSwitch(); - Windows::Foundation::IInspectable Header() const; - void Header(Windows::Foundation::IInspectable const& value); - bool IsOn() const; - void IsOn(bool value); + struct LiquidGlassToggleSwitch : + LiquidGlassToggleSwitchT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::KubeToggleSwitchVisualModel, + detail::SwitchElevationHelper, + detail::PressOpticsHelper, + detail::MotionDefaults + { + constexpr static auto ResourceUri = detail::ThemeResourceUri; + LiquidGlassToggleSwitch(); + Windows::Foundation::IInspectable Header() const; + void Header(Windows::Foundation::IInspectable const& value); + bool IsOn() const; + void IsOn(bool value); - void OnApplyTemplate() - { - base_type::OnApplyTemplate(); - detail::KubeToggleSwitchVisualModel::RefreshVisualModel(); - detail::SwitchElevationHelper::RefreshElevationSurface(); - } + void OnApplyTemplate() + { + base_type::OnApplyTemplate(); + detail::KubeToggleSwitchVisualModel::RefreshVisualModel(); + detail::SwitchElevationHelper::RefreshElevationSurface(); + } - void OnToggle() - { - if (!detail::KubeToggleSwitchVisualModel::TryHandleToggle()) - base_type::OnToggle(); - } + void OnToggle() + { + if (!detail::KubeToggleSwitchVisualModel::TryHandleToggle()) + base_type::OnToggle(); + } - private: - Windows::Foundation::IInspectable m_header{ nullptr }; - }; + private: + Windows::Foundation::IInspectable m_header{ nullptr }; + }; - struct LiquidGlassTabBarItem : - LiquidGlassTabBarItemT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::PointerMotionHelper, - detail::PressOpticsHelper - { - LiquidGlassTabBarItem(); - }; + struct LiquidGlassTabBarItem : + LiquidGlassTabBarItemT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::PointerMotionHelper, + detail::PressOpticsHelper + { + LiquidGlassTabBarItem(); + }; - struct LiquidGlassTabBar : - LiquidGlassTabBarT, - detail::GlassBrushHelper, - detail::TemplateControlHelper, - detail::PointerLightHelper, - detail::PointerFieldHelper, - detail::CompactControlMotionDefaults - { - LiquidGlassTabBar(); - Microsoft::UI::Xaml::DependencyObject GetContainerForItemOverride(); - bool IsItemItsOwnContainerOverride(Windows::Foundation::IInspectable const& item); - }; + struct LiquidGlassTabBar : + LiquidGlassTabBarT, + detail::GlassBrushHelper, + detail::TemplateControlHelper, + detail::PointerLightHelper, + detail::PointerFieldHelper, + detail::CompactControlMotionDefaults + { + LiquidGlassTabBar(); + Microsoft::UI::Xaml::DependencyObject GetContainerForItemOverride(); + bool IsItemItsOwnContainerOverride(Windows::Foundation::IInspectable const& item); + }; } namespace winrt::WinUI::LiquidGlass::factory_implementation { - struct LiquidGlassCard : LiquidGlassCardT {}; - struct LiquidGlassMagnifier : LiquidGlassMagnifierT {}; - struct LiquidGlassButton : LiquidGlassButtonT {}; - struct LiquidGlassToggleButton : LiquidGlassToggleButtonT {}; - struct LiquidGlassHyperlinkButton : LiquidGlassHyperlinkButtonT {}; - struct LiquidGlassCheckBox : LiquidGlassCheckBoxT {}; - struct LiquidGlassRadioButton : LiquidGlassRadioButtonT {}; - struct LiquidGlassSlider : LiquidGlassSliderT {}; - struct LiquidGlassTextBox : LiquidGlassTextBoxT {}; - struct LiquidGlassPasswordBox : LiquidGlassPasswordBoxT {}; - struct LiquidGlassComboBox : LiquidGlassComboBoxT {}; - struct LiquidGlassToggleSwitch : LiquidGlassToggleSwitchT {}; - struct LiquidGlassTabBarItem : LiquidGlassTabBarItemT {}; - struct LiquidGlassTabBar : LiquidGlassTabBarT {}; + struct LiquidGlassCard : LiquidGlassCardT + { + }; + struct LiquidGlassMagnifier : LiquidGlassMagnifierT + { + }; + struct LiquidGlassButton : LiquidGlassButtonT + { + }; + struct LiquidGlassToggleButton : LiquidGlassToggleButtonT + { + }; + struct LiquidGlassHyperlinkButton : LiquidGlassHyperlinkButtonT + { + }; + struct LiquidGlassCheckBox : LiquidGlassCheckBoxT + { + }; + struct LiquidGlassRadioButton : LiquidGlassRadioButtonT + { + }; + struct LiquidGlassSlider : LiquidGlassSliderT + { + }; + struct LiquidGlassTextBox : LiquidGlassTextBoxT + { + }; + struct LiquidGlassPasswordBox : LiquidGlassPasswordBoxT + { + }; + struct LiquidGlassComboBox : LiquidGlassComboBoxT + { + }; + struct LiquidGlassToggleSwitch : LiquidGlassToggleSwitchT + { + }; + struct LiquidGlassTabBarItem : LiquidGlassTabBarItemT + { + }; + struct LiquidGlassTabBar : LiquidGlassTabBarT + { + }; } diff --git a/src/WinUI.LiquidGlass/LiquidGlassInteraction.cpp b/src/WinUI.LiquidGlass/LiquidGlassInteraction.cpp index dabcd9df..f91d62f4 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassInteraction.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassInteraction.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "pch.h" #include "winrt_module_imports.h" #include "LiquidGlassInteraction.h" diff --git a/src/WinUI.LiquidGlass/LiquidGlassTabBar.cpp b/src/WinUI.LiquidGlass/LiquidGlassTabBar.cpp index 1bd7c8d2..627471fe 100644 --- a/src/WinUI.LiquidGlass/LiquidGlassTabBar.cpp +++ b/src/WinUI.LiquidGlass/LiquidGlassTabBar.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "pch.h" #include "winrt_module_imports.h" #include "LiquidGlassControls.h" #include "include/ResourceDictionaryLoader.hpp" @@ -10,56 +10,56 @@ namespace winrt::WinUI::LiquidGlass::implementation { - namespace Xaml = Microsoft::UI::Xaml; - namespace Controls = Xaml::Controls; + namespace Xaml = Microsoft::UI::Xaml; + namespace Controls = Xaml::Controls; - namespace - { - void EnsureTabBarResources() - { - // A first construction attempt can happen before Application::Current() is - // available (for example during metadata/type activation). Cache only success; - // the shared loader also detects an already merged dictionary before appending. - static bool loaded{}; - if (!loaded) - { - loaded = detail::EnsureMergedResourceDictionary( - L"ms-appx:///WinUI.LiquidGlass/Themes/TabBar.xaml"); - } - } - } + namespace + { + void EnsureTabBarResources() + { + // A first construction attempt can happen before Application::Current() is + // available (for example during metadata/type activation). Cache only success; + // the shared loader also detects an already merged dictionary before appending. + static bool loaded{}; + if (!loaded) + { + loaded = detail::EnsureMergedResourceDictionary( + L"ms-appx:///WinUI.LiquidGlass/Themes/TabBar.xaml"); + } + } + } - LiquidGlassTabBarItem::LiquidGlassTabBarItem() - { - EnsureTabBarResources(); - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(WinUI::LiquidGlass::LiquidGlassPresets::CreateBrush( - WinUI::LiquidGlass::LiquidGlassPreset::TabBarItem)); - UseSystemFocusVisuals(true); - } + LiquidGlassTabBarItem::LiquidGlassTabBarItem() + { + EnsureTabBarResources(); + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(WinUI::LiquidGlass::LiquidGlassPresets::CreateBrush( + WinUI::LiquidGlass::LiquidGlassPreset::TabBarItem)); + UseSystemFocusVisuals(true); + } - LiquidGlassTabBar::LiquidGlassTabBar() - { - EnsureTabBarResources(); - DefaultStyleKey(box_value(xaml_typename())); - GlassBrush(WinUI::LiquidGlass::LiquidGlassPresets::CreateBrush( - WinUI::LiquidGlass::LiquidGlassPreset::TabBar)); + LiquidGlassTabBar::LiquidGlassTabBar() + { + EnsureTabBarResources(); + DefaultStyleKey(box_value(xaml_typename())); + GlassBrush(WinUI::LiquidGlass::LiquidGlassPresets::CreateBrush( + WinUI::LiquidGlass::LiquidGlassPreset::TabBar)); - SelectionMode(Controls::ListViewSelectionMode::Single); - IsMultiSelectCheckBoxEnabled(false); - SingleSelectionFollowsFocus(false); - // CompactControlMotionDefaults owns the interaction profile on this - // parent. Generated item containers resolve those attached values through the - // existing visual-tree fallback, preserving one configuration point. - } + SelectionMode(Controls::ListViewSelectionMode::Single); + IsMultiSelectCheckBoxEnabled(false); + SingleSelectionFollowsFocus(false); + // CompactControlMotionDefaults owns the interaction profile on this + // parent. Generated item containers resolve those attached values through the + // existing visual-tree fallback, preserving one configuration point. + } - Xaml::DependencyObject LiquidGlassTabBar::GetContainerForItemOverride() - { - return winrt::make(); - } + Xaml::DependencyObject LiquidGlassTabBar::GetContainerForItemOverride() + { + return winrt::make(); + } - bool LiquidGlassTabBar::IsItemItsOwnContainerOverride(Windows::Foundation::IInspectable const& item) - { - return static_cast(item.try_as()); - } + bool LiquidGlassTabBar::IsItemItsOwnContainerOverride(Windows::Foundation::IInspectable const& item) + { + return static_cast(item.try_as()); + } } diff --git a/src/WinUI.LiquidGlass/Themes/Controls/Buttons.xaml b/src/WinUI.LiquidGlass/Themes/Controls/Buttons.xaml index a386c6ad..04b3a83b 100644 --- a/src/WinUI.LiquidGlass/Themes/Controls/Buttons.xaml +++ b/src/WinUI.LiquidGlass/Themes/Controls/Buttons.xaml @@ -1,9 +1,6 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -116,80 +61,104 @@ - + TextWrapping="Wrap" Visibility="Collapsed" /> - + CornerRadius="{TemplateBinding CornerRadius}" /> - - + TextWrapping="{TemplateBinding TextWrapping}" /> -