Skip to content

Commit

Permalink
adding gui anchors bottom_left & bottom_right. closes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
braitsch committed Apr 8, 2016
1 parent 34d9ce1 commit eefc6bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
7 changes: 1 addition & 6 deletions example-AllComponentsGui/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void ofApp::setup()
tIndex = 0;

// launch the app //
// mFullscreen = true;
mFullscreen = true;
refreshWindow();
}

Expand Down Expand Up @@ -137,11 +137,6 @@ void ofApp::update() { }

void ofApp::keyPressed(int key)
{
if (key == 'n') {
gui->getSlider("position y")->setPrecision(3, true);
gui->getSlider("position y")->setValue(-1.123756789);
gui->getSlider("position y")->printValue();
}
if (key == 'f') {
toggleFullscreen();
} else if (key == 32){
Expand Down
4 changes: 3 additions & 1 deletion src/core/ofxDatGuiConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ enum class ofxDatGuiAnchor
{
NO_ANCHOR = 0,
TOP_LEFT = 1,
TOP_RIGHT = 2
TOP_RIGHT = 2,
BOTTOM_LEFT = 3,
BOTTOM_RIGHT = 4
};

enum class ofxDatGuiGraph
Expand Down
33 changes: 23 additions & 10 deletions src/ofxDatGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ void ofxDatGui::setPosition(int x, int y)
moveGui(ofPoint(x, y));
}

void ofxDatGui::setPosition(ofxDatGuiAnchor anchor)
{
mAnchor = anchor;
if (mAnchor != ofxDatGuiAnchor::NO_ANCHOR) anchorGui();
}

void ofxDatGui::setVisible(bool visible)
{
mVisible = visible;
Expand Down Expand Up @@ -717,19 +723,26 @@ void ofxDatGui::moveGui(ofPoint pt)

void ofxDatGui::anchorGui()
{
mPosition.y = 0;
/*
ofGetWidth/ofGetHeight returns incorrect values after retina windows are resized in version 0.9.1 & 0.9.2
https://github.com/openframeworks/openFrameworks/pull/4858
*/
int multiplier = 1;
if (ofxDatGuiIsRetina() && ofGetVersionMajor() == 0 && ofGetVersionMinor() == 9 && (ofGetVersionPatch() == 1 || ofGetVersionPatch() == 2)){
multiplier = 2;
}
if (mAnchor == ofxDatGuiAnchor::TOP_LEFT){
mPosition.y = 0;
mPosition.x = 0;
} else if (mAnchor == ofxDatGuiAnchor::TOP_RIGHT){
mPosition.x = ofGetWidth() - mWidth;
/*
ofGetWidth returns an incorrect value after retina windows are resized in version 0.9.1 & 0.9.2
https://github.com/openframeworks/openFrameworks/issues/4746
https://github.com/openframeworks/openFrameworks/pull/4858
*/
if (ofxDatGuiIsRetina() && ofGetVersionMajor() == 0 && ofGetVersionMinor() == 9 && (ofGetVersionPatch() == 1 || ofGetVersionPatch() == 2)){
mPosition.x = (ofGetWidth() / 2) - mWidth;
}
mPosition.y = 0;
mPosition.x = (ofGetWidth() / multiplier) - mWidth;
} else if (mAnchor == ofxDatGuiAnchor::BOTTOM_LEFT){
mPosition.x = 0;
mPosition.y = (ofGetHeight() / multiplier) - mHeight;
} else if (mAnchor == ofxDatGuiAnchor::BOTTOM_RIGHT){
mPosition.x = (ofGetWidth() / multiplier) - mWidth;
mPosition.y = (ofGetHeight() / multiplier) - mHeight;
}
layoutGui();
}
Expand Down
1 change: 1 addition & 0 deletions src/ofxDatGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ofxDatGui : public ofxDatGuiInteractiveObject
void setEnabled(bool enabled);
void setOpacity(float opacity);
void setPosition(int x, int y);
void setPosition(ofxDatGuiAnchor anchor);
void setTheme(ofxDatGuiTheme* t);
void setAutoDraw(bool autodraw, int priority = 0);
void setLabelAlignment(ofxDatGuiAlignment align);
Expand Down

0 comments on commit eefc6bd

Please sign in to comment.