Merge pull request #635 from jpcima/controls-panel
Update control panel for efficient updates, preserving values
This commit is contained in:
commit
3b8858b543
2 changed files with 88 additions and 86 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
#include "utility/vstgui_before.h"
|
#include "utility/vstgui_before.h"
|
||||||
#include "vstgui/lib/cdrawcontext.h"
|
#include "vstgui/lib/cdrawcontext.h"
|
||||||
#include "vstgui/lib/cgraphicspath.h"
|
#include "vstgui/lib/cgraphicspath.h"
|
||||||
|
#include "vstgui/lib/cvstguitimer.h"
|
||||||
#include "vstgui/lib/cframe.h"
|
#include "vstgui/lib/cframe.h"
|
||||||
#include "utility/vstgui_after.h"
|
#include "utility/vstgui_after.h"
|
||||||
|
|
||||||
|
|
@ -527,18 +528,47 @@ SControlsPanel::SControlsPanel(const CRect& size)
|
||||||
setBackgroundColor(CColor(0x00, 0x00, 0x00, 0x00));
|
setBackgroundColor(CColor(0x00, 0x00, 0x00, 0x00));
|
||||||
|
|
||||||
setScrollbarWidth(10.0);
|
setScrollbarWidth(10.0);
|
||||||
|
|
||||||
|
relayoutTrigger_ = makeOwned<CVSTGUITimer>(
|
||||||
|
[this](CVSTGUITimer* timer) { timer->stop(); updateLayout(); },
|
||||||
|
1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SControlsPanel::setControlUsed(uint32_t index, bool used)
|
void SControlsPanel::setControlUsed(uint32_t index, bool used)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
ControlSlot* slot = getSlot(index);
|
||||||
|
if (!slot && !used)
|
||||||
|
return;
|
||||||
|
if (!slot)
|
||||||
|
slot = getOrCreateSlot(index);
|
||||||
|
if (used != slot->used) {
|
||||||
|
slot->used = used;
|
||||||
|
relayoutTrigger_->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SControlsPanel::getDefaultLabelText(uint32_t index)
|
||||||
|
{
|
||||||
|
return "CC " + std::to_string(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
SControlsPanel::ControlSlot* SControlsPanel::getSlot(uint32_t index)
|
||||||
|
{
|
||||||
|
ControlSlot* slot = nullptr;
|
||||||
|
if (index < slots_.size())
|
||||||
|
slot = slots_[index].get();
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
SControlsPanel::ControlSlot* SControlsPanel::getOrCreateSlot(uint32_t index)
|
||||||
|
{
|
||||||
|
ControlSlot* slot = getSlot(index);
|
||||||
|
if (slot)
|
||||||
|
return slot;
|
||||||
|
|
||||||
if (used) {
|
|
||||||
if (index + 1 > slots_.size())
|
if (index + 1 > slots_.size())
|
||||||
slots_.resize(index + 1);
|
slots_.resize(index + 1);
|
||||||
ControlSlot* slot = slots_[index].get();
|
|
||||||
changed = !slot;
|
|
||||||
if (changed) {
|
|
||||||
slot = new ControlSlot;
|
slot = new ControlSlot;
|
||||||
slots_[index].reset(slot);
|
slots_[index].reset(slot);
|
||||||
|
|
||||||
|
|
@ -570,8 +600,6 @@ void SControlsPanel::setControlUsed(uint32_t index, bool used)
|
||||||
label->setStyle(CTextLabel::kRoundRectStyle);
|
label->setStyle(CTextLabel::kRoundRectStyle);
|
||||||
label->setRoundRectRadius(5.0);
|
label->setRoundRectRadius(5.0);
|
||||||
label->setBackColor(CColor(0x2e, 0x34, 0x36));
|
label->setBackColor(CColor(0x2e, 0x34, 0x36));
|
||||||
label->setTextTruncateMode(CTextLabel::kTruncateTail);
|
|
||||||
label->setTextInset({4.0, 0.0});
|
|
||||||
label->setText(getDefaultLabelText(index));
|
label->setText(getDefaultLabelText(index));
|
||||||
knob->setActiveTrackColor(CColor(0x00, 0xb6, 0x2a));
|
knob->setActiveTrackColor(CColor(0x00, 0xb6, 0x2a));
|
||||||
knob->setInactiveTrackColor(CColor(0x30, 0x30, 0x30));
|
knob->setInactiveTrackColor(CColor(0x30, 0x30, 0x30));
|
||||||
|
|
@ -580,58 +608,28 @@ void SControlsPanel::setControlUsed(uint32_t index, bool used)
|
||||||
slot->knob = knob;
|
slot->knob = knob;
|
||||||
slot->label = label;
|
slot->label = label;
|
||||||
slot->box = box;
|
slot->box = box;
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (index < slots_.size() && slots_[index]) {
|
|
||||||
changed = true;
|
|
||||||
slots_[index].reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
return slot;
|
||||||
updateLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string SControlsPanel::getDefaultLabelText(uint32_t index)
|
|
||||||
{
|
|
||||||
return "CC " + std::to_string(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SControlsPanel::setControlValue(uint32_t index, float value)
|
void SControlsPanel::setControlValue(uint32_t index, float value)
|
||||||
{
|
{
|
||||||
if (index >= slots_.size())
|
ControlSlot* slot = getOrCreateSlot(index);
|
||||||
return;
|
CControl* knob = slot->knob;
|
||||||
|
knob->setValue(value);
|
||||||
ControlSlot* slot = slots_[index].get();
|
knob->invalid();
|
||||||
if (!slot)
|
|
||||||
return;
|
|
||||||
|
|
||||||
slot->knob->setValue(value);
|
|
||||||
slot->knob->invalid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SControlsPanel::setControlDefaultValue(uint32_t index, float value)
|
void SControlsPanel::setControlDefaultValue(uint32_t index, float value)
|
||||||
{
|
{
|
||||||
if (index >= slots_.size())
|
ControlSlot* slot = getOrCreateSlot(index);
|
||||||
return;
|
CControl* knob = slot->knob;
|
||||||
|
knob->setDefaultValue(value);
|
||||||
ControlSlot* slot = slots_[index].get();
|
|
||||||
if (!slot)
|
|
||||||
return;
|
|
||||||
|
|
||||||
slot->knob->setDefaultValue(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SControlsPanel::setControlLabelText(uint32_t index, UTF8StringPtr text)
|
void SControlsPanel::setControlLabelText(uint32_t index, UTF8StringPtr text)
|
||||||
{
|
{
|
||||||
if (index >= slots_.size())
|
ControlSlot* slot = getOrCreateSlot(index);
|
||||||
return;
|
|
||||||
|
|
||||||
ControlSlot* slot = slots_[index].get();
|
|
||||||
if (!slot)
|
|
||||||
return;
|
|
||||||
|
|
||||||
CTextLabel* label = slot->label;
|
CTextLabel* label = slot->label;
|
||||||
if (text && text[0] != '\0')
|
if (text && text[0] != '\0')
|
||||||
label->setText(text);
|
label->setText(text);
|
||||||
|
|
@ -675,7 +673,7 @@ void SControlsPanel::updateLayout()
|
||||||
uint32_t numSlots = static_cast<uint32_t>(slots_.size());
|
uint32_t numSlots = static_cast<uint32_t>(slots_.size());
|
||||||
for (uint32_t i = 0; i < numSlots; ++i) {
|
for (uint32_t i = 0; i < numSlots; ++i) {
|
||||||
ControlSlot* slot = slots_[i].get();
|
ControlSlot* slot = slots_[i].get();
|
||||||
if (!slot)
|
if (!slot || !slot->used)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CViewContainer* box = slot->box;
|
CViewContainer* box = slot->box;
|
||||||
|
|
@ -709,8 +707,6 @@ void SControlsPanel::updateLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CRect containerSize = getContainerSize();
|
|
||||||
containerSize.bottom = containerBottom;
|
|
||||||
setContainerSize(CRect(0.0, 0.0, viewBounds.getWidth(), containerBottom + verticalPadding));
|
setContainerSize(CRect(0.0, 0.0, viewBounds.getWidth(), containerBottom + verticalPadding));
|
||||||
|
|
||||||
invalid();
|
invalid();
|
||||||
|
|
|
||||||
|
|
@ -237,8 +237,13 @@ private:
|
||||||
void updateLayout();
|
void updateLayout();
|
||||||
static std::string getDefaultLabelText(uint32_t index);
|
static std::string getDefaultLabelText(uint32_t index);
|
||||||
|
|
||||||
|
struct ControlSlot;
|
||||||
|
ControlSlot* getSlot(uint32_t index);
|
||||||
|
ControlSlot* getOrCreateSlot(uint32_t index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ControlSlot {
|
struct ControlSlot {
|
||||||
|
bool used = false;
|
||||||
SharedPointer<CControl> knob;
|
SharedPointer<CControl> knob;
|
||||||
SharedPointer<CTextLabel> label;
|
SharedPointer<CTextLabel> label;
|
||||||
SharedPointer<CViewContainer> box;
|
SharedPointer<CViewContainer> box;
|
||||||
|
|
@ -257,6 +262,7 @@ private:
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ControlSlot>> slots_;
|
std::vector<std::unique_ptr<ControlSlot>> slots_;
|
||||||
std::unique_ptr<ControlSlotListener> listener_;
|
std::unique_ptr<ControlSlotListener> listener_;
|
||||||
|
SharedPointer<CVSTGUITimer> relayoutTrigger_;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue