frauzufall / ofxGuiExtended

ofParameter based GUI addon for openFrameworks; derived from the core OF ofxGui addon and ofxDOM.
MIT License
113 stars 30 forks source link

guiMatrix setup with ofParametersGroup breaks on runtime #23

Closed nanu-c closed 8 years ago

nanu-c commented 9 years ago

in the example it is with

    vector<ofParameter<bool>> matrix_buffer;
    matrix_buffer.push_back(ofParameter<bool>("0",false));
    matrix_buffer.push_back(ofParameter<bool>("1",false));
    matrix_buffer.push_back(ofParameter<bool>("2",false));
    matrix_buffer.push_back(ofParameter<bool>("3",false));
    matrixBuffer.setup("c Buffer Slot",4);
    for(unsigned int i = 0; i < matrix_buffer.size(); i++) {
        matrixBuffer.add(new ofxMinimalToggle(matrix_buffer.at(i)));
    }
    matrixBuffer.setBorderColor(ofColor::blue);
    matrixBuffer.setElementHeight(26);
    matrixBuffer.allowMultipleActiveToggles(false);
    guiCameraPanel2.add(&matrixBuffer);

But i need an ofParamaterGroup for an ofAddListener() so i tried it with

    ofParameterGroup cameraMatrixParameters;
    ofParameter<bool> cam0;
    ofParameter<bool> cam2;
    ofParameter<bool> cam3;
    ofParameter<bool> cam1;

    cameraMatrixParameters.add(cam0.set("cam0",false));
    cameraMatrixParameters.add(cam1.set("cam1",false));
    cameraMatrixParameters.add(cam2.set("cam2",false));
    cameraMatrixParameters.add(cam3.set("cam3",false));

    matrixCam.setup(cameraMatrixParameters,4);
    matrixCam.allowMultipleActiveToggles(false);
    guiCameraPanel.add(&matrixCam);

an that's what I get:

Speicherzugriffsfehler (Speicherabzug geschrieben)
segmentation fault (core dumped)

This would be enhanced with radio-Buttons, what is actually a subfunction of a matrix with only one active toggle

frauzufall commented 9 years ago

Thanks for reporting this issue! I can't find a simple way to fix the matrix issue but it does at least work if you use ofxGuiGroupExtended instead of ofxGuiMatrix (it has the same feature with only one active toggle):

ofParameterGroup cameraMatrixParameters;
ofParameter<bool> cam0, cam1, cam2, cam3;
ofxGuiGroupExtended matrixCam;

cameraMatrixParameters.add(cam0.set("cam0",false));
cameraMatrixParameters.add(cam1.set("cam1",false));
cameraMatrixParameters.add(cam2.set("cam2",false));
cameraMatrixParameters.add(cam3.set("cam3",false));

matrixCam.setup(cameraMatrixParameters);
matrixCam.setShowHeader(false);
matrixCam.setAlignHorizontal();
matrixCam.allowMultipleActiveToggles(false);
guiCameraPanel.add(&matrixCam);

Problem with this is that there seems to be no easy way to change the panel width.. I added this to exampleControls, you can see the result there.

Further I can only recommend that you wait until the new version of ofxGui / ofxGuiExtended is part of OF or in the meantime use the OF fork with the new ofxGui in it: https://github.com/frauzufall/openFrameworks/tree/refactor-gui-extended In this branch you can set a fixed item width when using ofxGuiGroup:

ofParameterGroup cameraMatrixParameters;
ofParameter<bool> cam0, cam1, cam2, cam3;

cameraMatrixParameters.setName("cameras");
cameraMatrixParameters.add(cam0.set("cam0",false));
cameraMatrixParameters.add(cam1.set("cam1",false));
cameraMatrixParameters.add(cam2.set("cam2",false));
cameraMatrixParameters.add(cam3.set("cam3",false));

ofxGuiGroup::Config toggle_group_config;
toggle_group_config.layout = ofxBaseGui::Horizontal;
toggle_group_config.exclusiveToggles = true;
ofxBaseGui::Config toggle_item_config;
toggle_item_config.shape.width = 60;
panel5.add(cameraMatrixParameters, toggle_group_config, toggle_item_config);

.. or you can use ofxGuiMatrix:

ofxGuiGroup matrixCam;
ofParameterGroup cameraMatrixParameters;
ofParameter<bool> cam0, cam1, cam2, cam3;

cameraMatrixParameters.setName("cameras");
cameraMatrixParameters.add(cam0.set("cam0",false));
cameraMatrixParameters.add(cam1.set("cam1",false));
cameraMatrixParameters.add(cam2.set("cam2",false));
cameraMatrixParameters.add(cam3.set("cam3",false));

matrixCam.setup(cameraMatrixParameters, 4);
matrixCam.setExclusiveToggles(true);
panel5.add(matrixCam);

..optionally with a fixed container width:

ofxGuiMatrix::Config matrix_config;
matrix_config.columnCount = 4;
matrix_config.shape.width = 400;
matrixCam.setup(cameraMatrixParameters, matrix_config);
matrixCam.setExclusiveToggles(true);
panel5.add(matrixCam);

I also added the last example code to the advancedControlExample in this fork.