fix(slider): optimize tick label alignment to prevent text overflow#598
fix(slider): optimize tick label alignment to prevent text overflow#598add-uos wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
Add isFirst/isLast properties and effectiveHorizontalAlignment to align first/last tick labels outward (left for first, right for last), preventing text overflow at slider edges. Use negative margins to offset label padding for better visual alignment with tick marks. Add null safety checks and documentation comments. 为 SliderTipItem 添加首尾刻度标签特殊对齐逻辑,首刻度左对齐、尾刻度右对齐, 防止文本在滑块边缘溢出。使用负边距抵消标签 padding,使文字与刻度对齐。 添加空值安全检查和文档注释。 Log: 优化滑块刻度标签对齐,防止边缘文本溢出 PMS: BUG-305223 Influence: TipsSlider 的首尾刻度标签现在会自动向外对齐,提升视觉效果并防止文本溢出。
|
[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 GuideAdjusts SliderTipItem tick label alignment to align the first/last horizontal tick labels outward and uses negative margins to visually align text with tick marks while adding simple null-safe access to ticks and updating the license header years. Flow diagram for effectiveHorizontalAlignment selectionflowchart TD
A_start[Start alignment resolution] --> B_checkHorizontal{Is slider horizontal?}
B_checkHorizontal -- No --> C_useDefault[Use textHorizontalAlignment]
C_useDefault --> Z_end[Return alignment]
B_checkHorizontal -- Yes --> D_checkFirst{Is tick first?}
D_checkFirst -- Yes --> E_alignLeft[Set alignment to Text.AlignLeft]
E_alignLeft --> Z_end
D_checkFirst -- No --> F_checkLast{Is tick last?}
F_checkLast -- Yes --> G_alignRight[Set alignment to Text.AlignRight]
G_alignRight --> Z_end
F_checkLast -- No --> H_useDefault2[Use textHorizontalAlignment]
H_useDefault2 --> Z_end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- For sliders with only a single tick,
isFirstandisLastwill both be true so the label will end up right-aligned; consider explicitly handling the single-tick case (e.g., keeping it centered) if that layout is undesirable. - The
isFirst/isLastbindings recomputeticks.indexOf(control)every time they are evaluated; iftickscan be large or change frequently, consider deriving these flags from existing index information or caching to avoid repeated linear scans.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- For sliders with only a single tick, `isFirst` and `isLast` will both be true so the label will end up right-aligned; consider explicitly handling the single-tick case (e.g., keeping it centered) if that layout is undesirable.
- The `isFirst`/`isLast` bindings recompute `ticks.indexOf(control)` every time they are evaluated; if `ticks` can be large or change frequently, consider deriving these flags from existing index information or caching to avoid repeated linear scans.
## Individual Comments
### Comment 1
<location path="qt6/src/qml/SliderTipItem.qml" line_range="21-23" />
<code_context>
+ var ticks = parent.parent.ticks || []
+ return ticks.indexOf(control) === 0
+ }
+ readonly property bool isLast: {
+ var ticks = parent.parent.ticks || []
+ return ticks.indexOf(control) === ticks.length - 1
+ }
+ // Align first/last tick labels outward to prevent text overflow at slider edges
</code_context>
<issue_to_address>
**issue:** Guard against `ticks` being empty when computing `isLast`.
Because `ticks = parent.parent.ticks || []` can be `[]`, `ticks.indexOf(control)` and `ticks.length - 1` are both `-1`, so `isLast` evaluates to `true` when there are no ticks. If an empty tick list is possible, this will incorrectly treat the label as the last tick and apply the outward alignment. Consider guarding with `ticks.length > 0`, e.g. `return ticks.length > 0 && ticks.indexOf(control) === ticks.length - 1`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| readonly property bool isLast: { | ||
| var ticks = parent.parent.ticks || [] | ||
| return ticks.indexOf(control) === ticks.length - 1 |
There was a problem hiding this comment.
issue: Guard against ticks being empty when computing isLast.
Because ticks = parent.parent.ticks || [] can be [], ticks.indexOf(control) and ticks.length - 1 are both -1, so isLast evaluates to true when there are no ticks. If an empty tick list is possible, this will incorrectly treat the label as the last tick and apply the outward alignment. Consider guarding with ticks.length > 0, e.g. return ticks.length > 0 && ticks.indexOf(control) === ticks.length - 1.
d98cb14 to
0d767ca
Compare
|
TAG Bot New tag: 6.7.39 |
Add isFirst/isLast properties and effectiveHorizontalAlignment to align first/last tick labels outward (left for first, right for last), preventing text overflow at slider edges. Use negative margins to offset label padding for better visual alignment with tick marks. Add null safety checks and documentation comments.
为 SliderTipItem 添加首尾刻度标签特殊对齐逻辑,首刻度左对齐、尾刻度右对齐,
防止文本在滑块边缘溢出。使用负边距抵消标签 padding,使文字与刻度对齐。
添加空值安全检查和文档注释。
Log: 优化滑块刻度标签对齐,防止边缘文本溢出
PMS: https://pms.uniontech.com/bug-view-305223.html
Influence: TipsSlider 的首尾刻度标签现在会自动向外对齐,提升视觉效果并防止文本溢出。
Summary by Sourcery
Optimize slider tick label alignment to improve appearance and prevent text overflow at the track edges.
Enhancements: