Let PanelSlider draw macOS-style notches
Optional tickCount cuts evenly-spaced marks into the track for stepped sliders. Defaults to 0, so existing sliders are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
25fb9cf916
commit
c681396a47
@@ -18,6 +18,13 @@ Item {
|
|||||||
property real knobSize: Math.max(14, Math.round(Style.spacing.controlHeight * 0.38))
|
property real knobSize: Math.max(14, Math.round(Style.spacing.controlHeight * 0.38))
|
||||||
property real liveValue: value
|
property real liveValue: value
|
||||||
|
|
||||||
|
// macOS-style notches. When > 1, that many evenly-spaced tick marks are cut
|
||||||
|
// into the track (drawn in the panel background color, so only the part
|
||||||
|
// crossing the track shows). Purely visual — snapping is the caller's job via
|
||||||
|
// `integer`/`step` or an index-based value. Default 0 leaves the track plain.
|
||||||
|
property int tickCount: 0
|
||||||
|
property color tickColor: bar ? bar.background : Color.background
|
||||||
|
|
||||||
onValueChanged: if (!dragging) liveValue = value
|
onValueChanged: if (!dragging) liveValue = value
|
||||||
|
|
||||||
signal moved(real value)
|
signal moved(real value)
|
||||||
@@ -55,6 +62,20 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: root.tickCount > 1 ? root.tickCount : 0
|
||||||
|
Rectangle {
|
||||||
|
required property int index
|
||||||
|
width: Math.max(1, Style.space(2))
|
||||||
|
height: root.trackHeight + Style.space(4)
|
||||||
|
radius: 1
|
||||||
|
color: root.tickColor
|
||||||
|
anchors.verticalCenter: track.verticalCenter
|
||||||
|
x: Math.max(0, Math.min(track.width - width,
|
||||||
|
track.width * (index / (root.tickCount - 1)) - width / 2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BorderSurface {
|
BorderSurface {
|
||||||
id: knob
|
id: knob
|
||||||
width: root.knobSize
|
width: root.knobSize
|
||||||
|
|||||||
Reference in New Issue
Block a user