Skip to content

Commit

Permalink
Labeled Grid Colspan etc... Multiswitch Bug Fix (#47)
Browse files Browse the repository at this point in the history
Labeled Grid gets colspan, col gap API changed.
Multiswitch in horizontal mode had an off-by-one error
  • Loading branch information
baconpaul authored Oct 2, 2023
1 parent 6077e1c commit ef21a07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions include/sst/jucegui/layouts/LabeledGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ template <int nCols, int nRows> struct LabeledGrid
juce::Component &comp;
};

LabeledGrid() { std::fill(colSpan.begin(), colSpan.end(), 1); }

int32_t cellWidth{-1}, cellHeight{-1};
void setControlCellSize(int cw, int ch)
{
Expand All @@ -45,9 +47,12 @@ template <int nCols, int nRows> struct LabeledGrid
}

float colGapSize{14};
std::vector<int32_t> colGapsAfter;
void addColGapAfter(int col) { colGapsAfter.push_back(col); }
void setColGapSize(float c) { colGapsAfter = c; }
std::array<int32_t, nCols> colGapsAfter{};
void addColGapAfter(int col) { addColGapAfter(col, colGapSize); }
void addColGapAfter(int col, float cgs) { colGapsAfter[col] = cgs; }

std::array<int32_t, nCols> colSpan;
void setColspanAt(int col, int span) { colSpan[col] = span; }

float labelHeight{18};
void setLabelHeight(float lh) { labelHeight = lh; }
Expand Down Expand Up @@ -113,29 +118,37 @@ template <int nCols, int nRows> struct LabeledGrid
for (const auto &g : gridComps)
{
auto xtran = g->x * ctW;
int idx{0};
for (const auto &c : colGapsAfter)
{
if (g->x > c)
xtran += colGapSize;
if (g->x > idx)
xtran += c;
idx++;
}
auto cbx = box0.translated(xtran + g->xPush, g->y * (ctH + labelHeight) + g->yPush);

if (!g->hasAssociatedLabel)
{
cbx = cbx.withHeight(cbx.getHeight() + labelHeight);
}
cbx = cbx.withWidth(cbx.getWidth() * colSpan[g->x]);

g->comp.setBounds(cbx.reduced(g->reduction));
}

for (const auto &g : gridLabels)
{
auto xtran = g->x * ctW;
int idx{0};
for (const auto &c : colGapsAfter)
{
if (g->x > c)
xtran += colGapSize;
if (g->x > idx)
xtran += c;
idx++;
}
auto cbx = boxLab0.translated(xtran, g->y * (ctH + labelHeight));
cbx = cbx.withWidth(cbx.getWidth() * colSpan[g->x]);

g->comp.setBounds(cbx);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sst/jucegui/components/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void MultiSwitch::setValueFromMouse(const juce::MouseEvent &e)
}
else
{
float nItems = data->getMax() - data->getMin();
float nItems = data->getMax() - data->getMin() + 1;
float h = std::min(getWidth() / nItems, elementSize * 1.f);
val = (int)(e.x / h);
}
Expand Down

0 comments on commit ef21a07

Please sign in to comment.