-
Notifications
You must be signed in to change notification settings - Fork 58
ToolButton: 深色模式 hover/pressed 毛玻璃效果 + checked 状态样式重构 #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // SPDX-FileCopyrightText: 2021 - 2024 UnionTech Software Technology Co., Ltd. | ||
| // SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
|
|
@@ -10,12 +10,11 @@ import org.deepin.dtk.private 1.0 as P | |
|
|
||
| T.ToolButton { | ||
| id: control | ||
| property D.Palette textColor: { | ||
| if (D.DTK.hasAnimation) | ||
| return checked ? DS.Style.highlightedButton.text : (highlighted ? DS.Style.highlightedButton.text : DS.Style.button.text) | ||
| // The checked chip is now a dedicated ToolButton style, so the checked | ||
| // text palette stays consistent whether animations are enabled or not. | ||
| property D.Palette textColor: checked ? DS.Style.toolButton.checkedText : (highlighted ? DS.Style.highlightedButton.text : DS.Style.button.text) | ||
|
|
||
| return checked ? DS.Style.checkedButton.text : (highlighted ? DS.Style.highlightedButton.text : DS.Style.button.text) | ||
| } | ||
| property D.Palette checkedShadow: DS.Style.toolButton.checkedShadow | ||
|
|
||
| implicitWidth: DS.Style.control.implicitWidth(control) | ||
| implicitHeight: DS.Style.control.implicitHeight(control) | ||
|
|
@@ -114,22 +113,94 @@ T.ToolButton { | |
| implicitHeight: DS.Style.toolButton.height | ||
| button: control | ||
| outsideBorderColor: null | ||
| insideBorderColor: null | ||
| radius: DS.Style.toolButton.radius | ||
|
|
||
| // Non-checked tool buttons: bind color1 to the background palette | ||
| // which has transparent 'normal', tinted 'hovered' and 'pressed' | ||
| // states. The ColorSelector picks the state automatically, and | ||
| // ButtonPanel's default visibility shows the panel when hovered | ||
| // or pressed (flat buttons are hidden in normal state). | ||
| Binding on color1 { | ||
| when: D.DTK.hasAnimation | ||
| value: D.Palette { | ||
| normal { | ||
| common: Qt.rgba(0, 0, 0, 0.1) | ||
| } | ||
| } | ||
| when: !control.checked | ||
| value: DS.Style.toolButton.background | ||
| } | ||
| Binding on color2 { | ||
| when: D.DTK.hasAnimation | ||
| when: !control.checked | ||
| value: buttonPanel.color1 | ||
| } | ||
| Binding on visible { | ||
| when: D.DTK.hasAnimation | ||
| value: control.hovered && !control.checked | ||
|
|
||
| // Dark-theme hover frosted-glass chip for non-checked tool buttons: | ||
| // backdrop blur (radius 15, saturation 100%) plus a 1px white top | ||
| // inset highlight and 1px black bottom inset shadow, over the | ||
| // translucent dark tint from background (rgba(20,20,20,0.2)). | ||
| // The blur is platform-gated; the inset bevel shows regardless. | ||
| readonly property bool __darkHover: !control.checked | ||
| && D.DTK.themeType === D.ApplicationHelper.DarkType | ||
| && buttonPanel.D.ColorSelector.controlState === D.DTK.HoveredState | ||
|
|
||
| D.InWindowBlur { | ||
|
zqq-dora marked this conversation as resolved.
|
||
| id: hoverBlur | ||
| anchors.fill: parent | ||
| radius: 15 | ||
| saturation: 1.0 | ||
| offscreen: true | ||
| visible: buttonPanel.__darkHover && hoverBlur.valid | ||
| z: -1 | ||
|
|
||
| D.ItemViewport { | ||
| anchors.fill: parent | ||
| fixed: true | ||
| sourceItem: hoverBlur.content | ||
| radius: buttonPanel.radius | ||
| hideSource: false | ||
| } | ||
| } | ||
|
|
||
| // Inner shadow 1: 1px white top inset highlight. | ||
| D.BoxInsetShadow { | ||
| anchors.fill: parent | ||
| visible: buttonPanel.__darkHover | ||
| z: D.DTK.AboveOrder | ||
| cornerRadius: buttonPanel.radius | ||
| shadowColor: Qt.rgba(1, 1, 1, 0.1) | ||
| shadowOffsetX: 0 | ||
| shadowOffsetY: 1 | ||
| shadowBlur: 1 | ||
| } | ||
|
|
||
| // Inner shadow 2: 1px black bottom inset shadow. | ||
| D.BoxInsetShadow { | ||
| anchors.fill: parent | ||
| visible: buttonPanel.__darkHover | ||
| z: D.DTK.AboveOrder | ||
| cornerRadius: buttonPanel.radius | ||
| shadowColor: Qt.rgba(0, 0, 0, 0.5) | ||
| shadowOffsetX: 0 | ||
| shadowOffsetY: -1 | ||
| shadowBlur: 1 | ||
| } | ||
|
|
||
| // Checked tool buttons use a subtle overlay chip with an accent icon | ||
| // instead of the shared accent-fill checked button style. | ||
| Binding on color1 { | ||
| when: control.checked | ||
| value: DS.Style.toolButton.checkedBackground | ||
| } | ||
| Binding on color2 { | ||
| when: control.checked | ||
| value: DS.Style.toolButton.checkedBackground | ||
| } | ||
| // Inset bottom shadow for the checked chip. | ||
| D.BoxInsetShadow { | ||
| anchors.fill: parent | ||
| visible: control.checked | ||
| z: D.DTK.AboveOrder | ||
| cornerRadius: buttonPanel.radius | ||
| shadowColor: control.D.ColorSelector.checkedShadow | ||
|
zqq-dora marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): The checked-chip shadow reads Triggers: When a checked ToolButton is loaded and the binding is evaluated. Suggested fix: Use the declared |
||
| shadowOffsetX: 0 | ||
| shadowOffsetY: -1 | ||
| shadowBlur: 1 | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.