Skip to content

fix(slider): adjust path calculation for handle alignment#616

Closed
52cyb wants to merge 1 commit intolinuxdeepin:masterfrom
52cyb:master
Closed

fix(slider): adjust path calculation for handle alignment#616
52cyb wants to merge 1 commit intolinuxdeepin:masterfrom
52cyb:master

Conversation

@52cyb
Copy link
Copy Markdown
Contributor

@52cyb 52cyb commented May 7, 2026

When handleType is less than 0 and x-value more than 0, the x-coordinate calculation now includes the handle width offset to correct the visual alignment of the slider path.

Log: adjust path calculation for handle alignment
PMS: BUG-358623
Influence: 检查输入设备的反馈音量显示是否正确,同时关注静音场景(PMS:350837)

Summary by Sourcery

Bug Fixes:

  • Fix misalignment between the slider handle and the rendered path when using negative handle types with positive x-coordinates.

When handleType is less than 0 and x-value more than 0, the x-coordinate calculation now includes the handle width offset to correct the visual alignment of the slider path.

Log: adjust path calculation for handle alignment
PMS: BUG-358623
Influence: 检查输入设备的反馈音量显示是否正确,同时关注静音场景(PMS:350837)
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

Hi @52cyb. Thanks for your PR. 😃

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the slider path's x-coordinate calculation so that, for horizontal sliders with a negative handleType and a positive handle x-position, the path end aligns with the visible handle edge by including the handle width offset.

Flow diagram for slider path x coordinate calculation

flowchart LR
    A[control.horizontal?] -->|no| B[Use sliderGroove.width / 2 as x]
    A -->|yes| C[Check control.handleType < 0]
    C -->|no| D[Use control.handle.x as x]
    C -->|yes| E[Check control.handle.x > 0]
    E -->|no| D[Use control.handle.x as x]
    E -->|yes| F[Use control.handle.x + control.handle.width as x]
Loading

File-Level Changes

Change Details Files
Fix horizontal slider path end-point alignment with the handle when handleType is negative and the handle is positioned to the right.
  • Update PathLine x-expression to conditionally add handle.width to handle.x when handleType < 0 and handle.x > 0 for horizontal sliders
  • Preserve existing x-coordinate behavior for non-horizontal sliders and for cases where the conditional does not apply
qt6/src/qml/Slider.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

Hi @52cyb. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a 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 nested ternary expression for the horizontal x-coordinate is getting hard to read; consider extracting the handle offset calculation into a small helper property or function so the condition on handleType and handle.x is clearer.
  • The new condition control.handleType < 0 && control.handle.x > 0 appears to handle a specific alignment case; it would help future maintainers to clarify why handleType < 0 and handle.x > 0 are the correct thresholds (e.g., by naming constants or using an enum instead of a raw comparison).
  • Please confirm whether this path adjustment should also apply in non-left-to-right or mirrored layouts; if so, you may need to account for layout direction rather than relying solely on handle.x > 0.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The nested ternary expression for the horizontal x-coordinate is getting hard to read; consider extracting the handle offset calculation into a small helper property or function so the condition on handleType and handle.x is clearer.
- The new condition `control.handleType < 0 && control.handle.x > 0` appears to handle a specific alignment case; it would help future maintainers to clarify why `handleType < 0` and `handle.x > 0` are the correct thresholds (e.g., by naming constants or using an enum instead of a raw comparison).
- Please confirm whether this path adjustment should also apply in non-left-to-right or mirrored layouts; if so, you may need to account for layout direction rather than relying solely on `handle.x > 0`.

## Individual Comments

### Comment 1
<location path="qt6/src/qml/Slider.qml" line_range="103" />
<code_context>
                         startY: control.horizontal ? sliderGroove.height / 2 : sliderGroove.height
                         PathLine {
-                            x: control.horizontal ? control.handle.x : sliderGroove.width / 2
+                            x: control.horizontal ? ((control.handleType < 0 && control.handle.x > 0) ? control.handle.x + control.handle.width : control.handle.x) : sliderGroove.width / 2
                             y: control.horizontal ? sliderGroove.height / 2 : control.handle.y + control.handle.height / 2
                         }
</code_context>
<issue_to_address>
**issue (bug_risk):** Consider clarifying the `handleType < 0 && handle.x > 0` condition to avoid possible off-by-one/branching issues at x=0.

This logic creates a discontinuity: for `control.handleType < 0`, `x > 0` uses `handle.x + handle.width` while `x <= 0` uses `handle.x`. If the goal is to re-anchor from center to right edge for certain handle types, tying that change to `x > 0` may cause a jump when crossing zero. Consider basing this purely on `handleType` (or an explicit state) or making the threshold (`>= 0`, etc.) explicit so behavior is consistent around the origin.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread qt6/src/qml/Slider.qml
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment thread qt6/src/qml/Slider.qml
startY: control.horizontal ? sliderGroove.height / 2 : sliderGroove.height
PathLine {
x: control.horizontal ? control.handle.x : sliderGroove.width / 2
x: control.horizontal ? ((control.handleType < 0 && control.handle.x > 0) ? control.handle.x + control.handle.width : control.handle.x) : sliderGroove.width / 2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

control.handleType < 0 这个不会成立吧,它是个枚举,

@52cyb 52cyb closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants