Skip to content

Commit

Permalink
matrices can now function as radio button groups
Browse files Browse the repository at this point in the history
  • Loading branch information
braitsch committed Oct 16, 2015
1 parent 7a5be5a commit 1c6f934
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example-Matrices/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void ofApp::setup()
// instantiate a matrix with a button for each box in our grid //
matrix = new ofxDatGuiMatrix("MATRIX", numCols*numRows, true);

// matrices can also function as radio buttons (only 1 on at a time)
matrix->setRadioMode(true);

// reduce the component opacity so it's easier to see behind it //
matrix->setOpacity(.75);

Expand Down
2 changes: 1 addition & 1 deletion roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

**features**

* allow matricies to function as radio buttons (1 on / all off)
* save / load gui settings via external file
* add additional gui positioning options that allow multiple panels to "snap" together
* data-binding for all components? (need use cases)
* dynamic gui creation via external api?
* <del>allow matricies to function as radio buttons (1 on / all off)</del>
* <del>add custom labels on gui footer</del>
* <del>externalize all gui & component settings into templates</del>

Expand Down
11 changes: 11 additions & 0 deletions src/components/ofxDatGuiMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ofxDatGuiMatrix : public ofxDatGuiComponent {

ofxDatGuiMatrix(string label, int numButtons, bool showLabels=false, ofxDatGuiTemplate* tmplt=nullptr) : ofxDatGuiComponent(label, tmplt)
{
mRadioMode = false;
mNumButtons = numButtons;
mShowLabels = showLabels;
mType = ofxDatGuiType::MATRIX;
Expand Down Expand Up @@ -164,6 +165,11 @@ class ofxDatGuiMatrix : public ofxDatGuiComponent {
}
}

void setRadioMode(bool enabled)
{
mRadioMode = enabled;
}

void setWidth(int w)
{
ofxDatGuiComponent::setWidth(w);
Expand Down Expand Up @@ -237,6 +243,10 @@ class ofxDatGuiMatrix : public ofxDatGuiComponent {

void onButtonSelected(ofxDatGuiInternalEvent e)
{
if (mRadioMode) {
// deselect all buttons save the one that was selected //
for(int i=0; i<btns.size(); i++) btns[i].setSelected(e.index == i);
}
if (matrixEventCallback != nullptr) {
ofxDatGuiMatrixEvent ev(this, e.index, btns[e.index].getSelected());
matrixEventCallback(ev);
Expand All @@ -249,6 +259,7 @@ class ofxDatGuiMatrix : public ofxDatGuiComponent {

int mButtonSize;
int mNumButtons;
bool mRadioMode;
bool mShowLabels;
ofRectangle mMatrixRect;
static const int mMinPadding = 2;
Expand Down

0 comments on commit 1c6f934

Please sign in to comment.