Navigation Menu

Skip to content

Commit

Permalink
fix for groups not positioning & resizing correctly when using bottom…
Browse files Browse the repository at this point in the history
… anchors. closes #122
  • Loading branch information
braitsch committed Dec 17, 2018
1 parent ddc4ec3 commit dd5474a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion example-AllComponentsGui/src/ofApp.cpp
Expand Up @@ -107,7 +107,7 @@ void ofApp::onToggleEvent(ofxDatGuiToggleEvent e)

void ofApp::onSliderEvent(ofxDatGuiSliderEvent e)
{
cout << "onSliderEvent: " << e.target->getLabel() << " "; e.target->printValue();
cout << "onSliderEvent: " << e.target->getLabel() << " " << e.target->getValue() << endl;
if (e.target->is("datgui opacity")) gui->setOpacity(e.scale);
}

Expand Down
19 changes: 13 additions & 6 deletions src/components/ofxDatGuiGroups.h
Expand Up @@ -58,18 +58,21 @@ class ofxDatGuiGroup : public ofxDatGuiButton {
{
mIsExpanded = true;
layout();
onGroupToggled();
}

void toggle()
{
mIsExpanded = !mIsExpanded;
layout();
onGroupToggled();
}

void collapse()
{
mIsExpanded = false;
layout();
onGroupToggled();
}

int getHeight()
Expand Down Expand Up @@ -134,14 +137,18 @@ class ofxDatGuiGroup : public ofxDatGuiButton {
ofxDatGuiComponent::onFocusLost();
ofxDatGuiComponent::onMouseRelease(m);
mIsExpanded ? collapse() : expand();
// dispatch an event out to the gui panel to adjust its children //
if (internalEventCallback != nullptr){
ofxDatGuiInternalEvent e(ofxDatGuiEventType::DROPDOWN_TOGGLED, mIndex);
internalEventCallback(e);
}
}
}

void onGroupToggled()
{
// dispatch an event out to the gui panel to adjust its children //
if (internalEventCallback != nullptr){
ofxDatGuiInternalEvent e(ofxDatGuiEventType::GROUP_TOGGLED, mIndex);
internalEventCallback(e);
}
}

void dispatchInternalEvent(ofxDatGuiInternalEvent e)
{
if (e.type == ofxDatGuiEventType::VISIBILITY_CHANGED) layout();
Expand Down Expand Up @@ -513,7 +520,7 @@ class ofxDatGuiDropdown : public ofxDatGuiGroup {
{
for(int i=0; i<children.size(); i++) if (e.target == children[i]) mOption = i;
setLabel(children[mOption]->getLabel());
collapse();
collapse();
dispatchEvent();
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/ofxDatGuiEvents.h
Expand Up @@ -42,7 +42,7 @@ enum ofxDatGuiEventType
COLOR_CHANGED,
SLIDER_CHANGED,
OPTION_SELECTED,
DROPDOWN_TOGGLED,
GROUP_TOGGLED,
VISIBILITY_CHANGED,
MATRIX_BUTTON_TOGGLED
};
Expand Down
37 changes: 21 additions & 16 deletions src/ofxDatGui.cpp
Expand Up @@ -37,7 +37,6 @@ ofxDatGui::ofxDatGui(ofxDatGuiAnchor anchor)
{
init();
mAnchor = anchor;
anchorGui();
}

ofxDatGui::~ofxDatGui()
Expand Down Expand Up @@ -139,7 +138,7 @@ void ofxDatGui::setWidth(int width, float labelWidth)
mWidth = width;
mLabelWidth = labelWidth;
mWidthChanged = true;
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) anchorGui();
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) positionGui();
}

void ofxDatGui::setTheme(ofxDatGuiTheme* t, bool applyImmediately)
Expand Down Expand Up @@ -170,7 +169,7 @@ void ofxDatGui::setPosition(int x, int y)
void ofxDatGui::setPosition(ofxDatGuiAnchor anchor)
{
mAnchor = anchor;
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) anchorGui();
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) positionGui();
}

void ofxDatGui::setVisible(bool visible)
Expand Down Expand Up @@ -747,7 +746,7 @@ void ofxDatGui::onMatrixEventCallback(ofxDatGuiMatrixEvent e)
void ofxDatGui::onInternalEventCallback(ofxDatGuiInternalEvent e)
{
// these events are not dispatched out to the main application //
if (e.type == ofxDatGuiEventType::DROPDOWN_TOGGLED){
if (e.type == ofxDatGuiEventType::GROUP_TOGGLED){
layoutGui();
} else if (e.type == ofxDatGuiEventType::GUI_TOGGLED){
mExpanded ? collapse() : expand();
Expand All @@ -774,10 +773,22 @@ void ofxDatGui::moveGui(ofPoint pt)
mPosition.x = pt.x;
mPosition.y = pt.y;
mAnchor = ofxDatGuiAnchor::NO_ANCHOR;
layoutGui();
positionGui();
}

void ofxDatGui::layoutGui()
{
mHeight = 0;
for (int i=0; i<items.size(); i++) {
items[i]->setIndex(i);
// skip over any components that are currently invisible //
if (items[i]->getVisible() == false) continue;
mHeight += items[i]->getHeight() + mRowSpacing;
}
positionGui();
}

void ofxDatGui::anchorGui()
void ofxDatGui::positionGui()
{
/*
ofGetWidth/ofGetHeight returns incorrect values after retina windows are resized in version 0.9.1 & 0.9.2
Expand All @@ -800,18 +811,12 @@ void ofxDatGui::anchorGui()
mPosition.x = (ofGetWidth() / multiplier) - mWidth;
mPosition.y = (ofGetHeight() / multiplier) - mHeight;
}
layoutGui();
}

void ofxDatGui::layoutGui()
{
mHeight = 0;
int h = 0;
for (int i=0; i<items.size(); i++) {
items[i]->setIndex(i);
// skip over any components that are currently invisible //
if (items[i]->getVisible() == false) continue;
items[i]->setPosition(mPosition.x, mPosition.y + mHeight);
mHeight += items[i]->getHeight() + mRowSpacing;
items[i]->setPosition(mPosition.x, mPosition.y + h);
h += items[i]->getHeight() + mRowSpacing;
}
// move the footer back to the top of the gui //
if (!mExpanded) mGuiFooter->setPosition(mPosition.x, mPosition.y);
Expand Down Expand Up @@ -931,7 +936,7 @@ void ofxDatGui::onUpdate(ofEventArgs &e)

void ofxDatGui::onWindowResized(ofResizeEventArgs &e)
{
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) anchorGui();
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) positionGui();
}


2 changes: 1 addition & 1 deletion src/ofxDatGui.h
Expand Up @@ -132,7 +132,7 @@ class ofxDatGui : public ofxDatGuiInteractiveObject

void init();
void layoutGui();
void anchorGui();
void positionGui();
void moveGui(ofPoint pt);
bool hitTest(ofPoint pt);
void attachItem(ofxDatGuiComponent* item);
Expand Down

0 comments on commit dd5474a

Please sign in to comment.