Skip to content

Commit

Permalink
adding public methods gui->collapse, gui->toggle and gui->expand. closes
Browse files Browse the repository at this point in the history
  • Loading branch information
braitsch committed Apr 8, 2016
1 parent 171b3d3 commit 815c8fd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
28 changes: 16 additions & 12 deletions src/components/ofxDatGuiControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ofxDatGuiFooter : public ofxDatGuiButton {

ofxDatGuiFooter() : ofxDatGuiButton("collapse controls")
{
mGuiCollapsed = false;
mGuiExpanded = true;
mLabelCollapsed = "expand controls";
mLabelExpanded = "collapse controls";
setTheme(ofxDatGuiComponent::theme.get());
Expand All @@ -116,34 +116,38 @@ class ofxDatGuiFooter : public ofxDatGuiButton {
void setLabelWhenExpanded(string label)
{
mLabelExpanded = label;
if (!mGuiCollapsed) setLabel(mLabelExpanded);
if (mGuiExpanded) setLabel(mLabelExpanded);
}

void setLabelWhenCollapsed(string label)
{
mLabelCollapsed = label;
if (mGuiCollapsed) setLabel(mLabelCollapsed);
if (!mGuiExpanded) setLabel(mLabelCollapsed);
}

void setY(int y)
// void setY(int y)
// {
// this->y = y;
// }

void setExpanded(bool expanded)
{
this->y = y;
mGuiExpanded = expanded;
if (mGuiExpanded){
setLabel(mLabelExpanded);
} else{
setLabel(mLabelCollapsed);
}
}

protected:

void onMouseRelease(ofPoint m)
{
mGuiCollapsed = !mGuiCollapsed;
ofxDatGuiComponent::onMouseRelease(m);
// dispatch event out to main application //
ofxDatGuiInternalEvent e(ofxDatGuiEventType::GUI_TOGGLED, mIndex);
internalEventCallback(e);
if (!mGuiCollapsed){
setLabel(mLabelExpanded);
} else{
setLabel(mLabelCollapsed);
}
}

// force footer label to always be centered //
Expand All @@ -153,7 +157,7 @@ class ofxDatGuiFooter : public ofxDatGuiButton {
}

private:
bool mGuiCollapsed;
bool mGuiExpanded;
string mLabelExpanded;
string mLabelCollapsed;

Expand Down
6 changes: 6 additions & 0 deletions src/components/ofxDatGuiGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class ofxDatGuiGroup : public ofxDatGuiButton {
layout();
}

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

void collapse()
{
mIsExpanded = false;
Expand Down
38 changes: 22 additions & 16 deletions src/ofxDatGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ void ofxDatGui::init()
}

/*
public getters & setters
public api
*/


void ofxDatGui::focus()
{
if (mActiveGui!= this){
Expand All @@ -98,6 +97,25 @@ void ofxDatGui::focus()
}
}

void ofxDatGui::expand()
{
mExpanded = true;
mGuiFooter->setExpanded(mExpanded);
mGuiFooter->setPosition(mPosition.x, mPosition.y + mHeight - mGuiFooter->getHeight() - mRowSpacing);
}

void ofxDatGui::collapse()
{
mExpanded = false;
mGuiFooter->setExpanded(mExpanded);
mGuiFooter->setPosition(mPosition.x, mPosition.y);
}

void ofxDatGui::toggle()
{
mExpanded ? collapse() : expand();
}

bool ofxDatGui::getVisible()
{
return mVisible;
Expand Down Expand Up @@ -666,7 +684,7 @@ void ofxDatGui::onInternalEventCallback(ofxDatGuiInternalEvent e)
if (e.type == ofxDatGuiEventType::DROPDOWN_TOGGLED){
layoutGui();
} else if (e.type == ofxDatGuiEventType::GUI_TOGGLED){
mExpanded ? collapseGui() : expandGui();
mExpanded ? collapse() : expand();
} else if (e.type == ofxDatGuiEventType::VISIBILITY_CHANGED){
layoutGui();
}
Expand Down Expand Up @@ -723,22 +741,10 @@ void ofxDatGui::layoutGui()
mHeight += items[i]->getHeight() + mRowSpacing;
}
// move the footer back to the top of the gui //
if (!mExpanded) mGuiFooter->setY(mPosition.y);
if (!mExpanded) mGuiFooter->setPosition(mPosition.x, mPosition.y);
mGuiBounds = ofRectangle(mPosition.x, mPosition.y, mWidth, mHeight);
}

void ofxDatGui::expandGui()
{
mExpanded = true;
mGuiFooter->setY(mPosition.y + mHeight - mGuiFooter->getHeight() - mRowSpacing);
}

void ofxDatGui::collapseGui()
{
mExpanded = false;
mGuiFooter->setY(mPosition.y);
}

/*
update & draw loop
*/
Expand Down
7 changes: 4 additions & 3 deletions src/ofxDatGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class ofxDatGui : public ofxDatGuiInteractiveObject
ofxDatGui(ofxDatGuiAnchor anchor = ofxDatGuiAnchor::TOP_LEFT);

void draw();
void focus();
void update();
void focus();
void expand();
void toggle();
void collapse();

void setWidth(int width, float labelWidth = 0.35f);
void setVisible(bool visible);
Expand Down Expand Up @@ -126,8 +129,6 @@ class ofxDatGui : public ofxDatGuiInteractiveObject
void init();
void layoutGui();
void anchorGui();
void expandGui();
void collapseGui();
void moveGui(ofPoint pt);
bool hitTest(ofPoint pt);
void attachItem(ofxDatGuiComponent* item);
Expand Down

0 comments on commit 815c8fd

Please sign in to comment.