From f1e89d3e46ae3b242d4f48879144c15d45151be7 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel Date: Mon, 2 Nov 2020 08:48:38 +0100 Subject: [PATCH] slider linewidth controls autosize, correct vertical --- src/makielayout/defaultattributes.jl | 6 ++++-- src/makielayout/lobjects/lslider.jl | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/makielayout/defaultattributes.jl b/src/makielayout/defaultattributes.jl index 09b54982a..5d55152d6 100644 --- a/src/makielayout/defaultattributes.jl +++ b/src/makielayout/defaultattributes.jl @@ -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" @@ -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." diff --git a/src/makielayout/lobjects/lslider.jl b/src/makielayout/lobjects/lslider.jl index 261013f02..b9809dba0 100644 --- a/src/makielayout/lobjects/lslider.jl +++ b/src/makielayout/lobjects/lslider.jl @@ -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 ) @@ -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 @@ -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 @@ -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 @@ -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