-
Notifications
You must be signed in to change notification settings - Fork 60
fix(notification): improve combobox width calculation and styling #1449
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
base: master
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideRefines the notification panel combobox to size dynamically based on its text content, updates the dropdown indicator to a themed DciIcon, and adjusts padding for better alignment while capping maximum width. Flow diagram for dynamic combobox width calculation and indicator layoutflowchart LR
A[ComboBox_created] --> B[Compute_displayText]
B --> C[TextMetrics_uses_comboBox_font_and_displayText]
C --> D[Measure_text_width]
D --> E[Add_padding_and_icon_space]
E --> F[implicitWidth_equals_Min_200_sum]
F --> G[Apply_Layout_maximumWidth_200]
G --> H[Render_combobox_with_dynamic_width]
H --> I[Position_DciIcon_indicator]
I --> J[Indicator_x_comboBox_width_minus_icon_width_minus_rightPadding]
I --> K[Indicator_y_centered_in_availableHeight]
J --> L[Paint_indicator_with_palette_and_theme]
K --> L[Paint_indicator_with_palette_and_theme]
L --> M[User_sees_aligned_thematic_dropdown_arrow]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- The
implicitWidthcalculation uses a hard-coded28pixel constant for extra width; consider deriving this from existing style constants (e.g., icon size + margins) or at least documenting what this value represents for future maintainability. - You now constrain the width twice (
Layout.maximumWidth: 200andMath.min(200, ...)inimplicitWidth); it would be simpler and less error-prone to centralize this limit in one place. - In the custom
indicatoryou manually computexusingcomboBox.width - width - comboBox.rightPadding; switching toanchors.right/anchors.rightMarginwould be more idiomatic QML and less fragile if padding/layout changes later.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `implicitWidth` calculation uses a hard-coded `28` pixel constant for extra width; consider deriving this from existing style constants (e.g., icon size + margins) or at least documenting what this value represents for future maintainability.
- You now constrain the width twice (`Layout.maximumWidth: 200` and `Math.min(200, ...)` in `implicitWidth`); it would be simpler and less error-prone to centralize this limit in one place.
- In the custom `indicator` you manually compute `x` using `comboBox.width - width - comboBox.rightPadding`; switching to `anchors.right`/`anchors.rightMargin` would be more idiomatic QML and less fragile if padding/layout changes later.
## Individual Comments
### Comment 1
<location> `panels/notification/plugin/NotifyAction.qml:161-162` </location>
<code_context>
+
+ implicitWidth: Math.min(200, textMetrics.width + comboBox.padding + comboBox.rightPadding + 28)
+
+ indicator: DciIcon {
+ x: comboBox.width - width - comboBox.rightPadding
+ y: comboBox.topPadding + (comboBox.availableHeight - height) / 2
+ sourceSize.width: DS.Style.comboBox.iconSize
</code_context>
<issue_to_address>
**issue:** Indicator positioning may not respect layout mirroring / RTL setups.
The manual `x` calculation (`comboBox.width - width - comboBox.rightPadding`) assumes a left‑to‑right layout and will misplace the indicator in RTL/mirrored setups. Prefer anchoring to `right` (or `left`, per design) with `anchors.rightMargin` so positioning automatically adapts to layout direction and stays maintainable.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| indicator: DciIcon { | ||
| x: comboBox.width - width - comboBox.rightPadding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Indicator positioning may not respect layout mirroring / RTL setups.
The manual x calculation (comboBox.width - width - comboBox.rightPadding) assumes a left‑to‑right layout and will misplace the indicator in RTL/mirrored setups. Prefer anchoring to right (or left, per design) with anchors.rightMargin so positioning automatically adapts to layout direction and stays maintainable.
- Replace fixed width with dynamic calculation based on text content using TextMetrics - Add custom DciIcon indicator for dropdown arrow with proper theming - Adjust padding values for better visual alignment - Constrain max width to 200px to prevent excessive expansion log: improve combobox width calculation and styling bug: PMS-350643
deepin pr auto review这段代码是一个对 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议总结
优化后的代码片段示例ComboBox {
id: actionComboBox
// ... 其他属性 ...
readonly property int indicatorSpace: 28 // 图标和额外间距
TextMetrics {
id: textMetrics
font: actionComboBox.font
text: actionComboBox.displayText
}
// padding 显式设为0,宽度计算仅依赖 rightPadding
implicitWidth: Math.min(200, textMetrics.width + actionComboBox.rightPadding + indicatorSpace)
// ... 其他代码 ...
} |
| palette: DTK.makeIconPalette(comboBox.palette) | ||
| name: "arrow_ordinary_down" | ||
| mode: comboBox.D.ColorSelector.controlState | ||
| theme: comboBox.D.ColorSelector.controlTheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comboBox.D.ColorSelector.controlTheme
这里不需要“D.”,这里没有这个别名,
|
|
||
| implicitWidth: Math.min(200, textMetrics.width + comboBox.padding + comboBox.rightPadding + 28) | ||
|
|
||
| indicator: DciIcon { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dtk的样式不适用这里的么?我看bug单子上说样式不一样,主要是背景吧,这里是主要修指示器?
| TextMetrics { | ||
| id: textMetrics | ||
| font: comboBox.font | ||
| text: comboBox.displayText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextMetrics 可以设置最大显示宽度吧,
log: improve combobox width calculation and styling
bug: PMS-350643
Summary by Sourcery
Improve the notification panel combobox by dynamically sizing it to its content and updating its visual styling and dropdown indicator.
Enhancements: