Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
slider linewidth controls autosize, correct vertical
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel committed Nov 2, 2020
1 parent 1863b0d commit f1e89d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/makielayout/defaultattributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ function default_attributes(::Type{LSlider}, scene)
"The vertical alignment of the slider in its suggested bounding box."
valign = :center
"The width setting of the slider."
width = nothing
width = Auto()
"The height setting of the slider."
height = 15
height = Auto()
"The range of values that the slider can pick from."
range = 0:10
"Controls if the parent layout can adjust to this element's width"
Expand All @@ -517,6 +517,8 @@ function default_attributes(::Type{LSlider}, scene)
startvalue = 0
"The current value of the slider."
value = 0
"The width of the slider line"
linewidth = 15
"The color of the slider when the mouse hovers over it."
color_active_dimmed = COLOR_ACCENT_DIMMED[]
"The color of the slider when the mouse clicks and drags the slider."
Expand Down
20 changes: 12 additions & 8 deletions src/makielayout/lobjects/lslider.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function LSlider(parent::Scene; bbox = nothing, kwargs...)
decorations = Dict{Symbol, Any}()

@extract attrs (
halign, valign, horizontal,
halign, valign, horizontal, linewidth,
startvalue, value, color_active, color_active_dimmed, color_inactive
)

Expand All @@ -17,6 +17,14 @@ function LSlider(parent::Scene; bbox = nothing, kwargs...)
layoutobservables = LayoutObservables{LSlider}(attrs.width, attrs.height, attrs.tellwidth, attrs.tellheight,
halign, valign, attrs.alignmode; suggestedbbox = bbox, protrusions = protrusions)

onany(linewidth, horizontal) do lw, horizontal
if horizontal
layoutobservables.autosize[] = (nothing, Float32(lw))
else
layoutobservables.autosize[] = (Float32(lw), nothing)
end
end

sliderbox = lift(identity, layoutobservables.computedbbox)

endpoints = lift(sliderbox, horizontal) do bb, horizontal
Expand All @@ -31,7 +39,7 @@ function LSlider(parent::Scene; bbox = nothing, kwargs...)
else
x = left(bb) + w / 2
[Point2f0(x, bottom(bb) + w/2),
Point2f0(x, top(bb) + h/2)]
Point2f0(x, top(bb) - w/2)]
end
end

Expand Down Expand Up @@ -80,10 +88,6 @@ function LSlider(parent::Scene; bbox = nothing, kwargs...)
[ca, ci]
end

linewidth = lift(horizontal, sliderbox) do hori, sbox
hori ? height(sbox) : width(sbox)
end

endbuttons = scatter!(parent, endpoints, color = linecolors, markersize = linewidth, strokewidth = 0, raw = true)[end]
decorations[:endbuttons] = endbuttons

Expand Down Expand Up @@ -146,8 +150,8 @@ function LSlider(parent::Scene; bbox = nothing, kwargs...)
linecolors[] = [color_active_dimmed[], color_inactive[]]
end

# trigger bbox
layoutobservables.suggestedbbox[] = layoutobservables.suggestedbbox[]
# trigger autosize through linewidth for first layout
linewidth[] = linewidth[]

LSlider(parent, layoutobservables, attrs, decorations)
end
Expand Down

0 comments on commit f1e89d3

Please sign in to comment.