From 16db3fb2e126b5ffcb9375a68fa14a52ce5d8449 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 6 Aug 2023 21:21:50 -0400 Subject: [PATCH] Set handle widget pos in SvgSlider::setHandlePos(). Step ModuleWidget before rendering in Browser so it can set its default appearance. --- include/componentlibrary.hpp | 10 ++++------ src/app/Browser.cpp | 3 +++ src/app/SvgSlider.cpp | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index 91eebc18..40236012 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -680,11 +680,10 @@ struct BefacoTinyKnob : app::SvgKnob { struct BefacoSlidePot : app::SvgSlider { BefacoSlidePot() { - math::Vec margin = math::Vec(3.5, 3.5); - maxHandlePos = math::Vec(-1, -2).plus(margin); - minHandlePos = math::Vec(-1, 87).plus(margin); setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/BefacoSlidePot.svg"))); setHandleSvg(Svg::load(asset::system("res/ComponentLibrary/BefacoSlidePotHandle.svg"))); + math::Vec margin = math::Vec(3.5, 3.5); + setHandlePos(math::Vec(-1, 87).plus(margin), math::Vec(-1, -2).plus(margin)); background->box.pos = margin; box.size = background->box.size.plus(margin.mult(2)); } @@ -705,11 +704,10 @@ using LEDSlider = VCVSlider; struct VCVSliderHorizontal : app::SvgSlider { VCVSliderHorizontal() { horizontal = true; - // TODO Fix positions - maxHandlePos = mm2px(math::Vec(22.078, 0.738).plus(math::Vec(0, 2))); - minHandlePos = mm2px(math::Vec(0.738, 0.738).plus(math::Vec(0, 2))); // TODO Fix SVG setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/VCVSliderHorizontal.svg"))); + // TODO Fix positions + setHandlePos(mm2px(math::Vec(0.738, 0.738).plus(math::Vec(0, 2))), mm2px(math::Vec(22.078, 0.738).plus(math::Vec(0, 2)))); } }; using LEDSliderHorizontal = VCVSliderHorizontal; diff --git a/src/app/Browser.cpp b/src/app/Browser.cpp index aa917ff1..fc6687e1 100644 --- a/src/app/Browser.cpp +++ b/src/app/Browser.cpp @@ -202,6 +202,9 @@ struct ModelBox : widget::OpaqueWidget { mwc->addChild(moduleWidget); mwc->box.size = moduleWidget->box.size; + // Step ModuleWidget so it can set its default appearance. + moduleWidget->step(); + updateZoom(); } diff --git a/src/app/SvgSlider.cpp b/src/app/SvgSlider.cpp index e44bcf1c..db650966 100644 --- a/src/app/SvgSlider.cpp +++ b/src/app/SvgSlider.cpp @@ -35,7 +35,7 @@ void SvgSlider::setHandleSvg(std::shared_ptr svg) { return; handle->setSvg(svg); - handle->box.pos = minHandlePos; + handle->box.pos = maxHandlePos; fb->setDirty(); } @@ -43,6 +43,9 @@ void SvgSlider::setHandleSvg(std::shared_ptr svg) { void SvgSlider::setHandlePos(math::Vec minHandlePos, math::Vec maxHandlePos) { this->minHandlePos = minHandlePos; this->maxHandlePos = maxHandlePos; + + // Set handle pos to maximum by default + handle->box.pos = maxHandlePos; }