Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/components/ofxDatGuiButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,19 @@ class ofxDatGuiToggle : public ofxDatGuiButton {

void draw()
{
ofxDatGuiButton::drawBkgd();
ofxDatGuiComponent::drawLabel();
ofxDatGuiComponent::drawStripe();
ofPushStyle();
if (mVisible) {
ofxDatGuiButton::drawBkgd();
ofxDatGuiComponent::drawLabel();
ofxDatGuiComponent::drawStripe();
ofPushStyle();
ofSetColor(mTemplate->row.color.label);
if (mEnabled == true){
radioOn.draw(x+mIcon.x, y+mIcon.y, mIcon.size, mIcon.size);
} else{
radioOff.draw(x+mIcon.x, y+mIcon.y, mIcon.size, mIcon.size);
if (mEnabled) {
radioOn.draw(x + mIcon.x, y + mIcon.y, mIcon.size, mIcon.size);
} else {
radioOff.draw(x + mIcon.x, y + mIcon.y, mIcon.size, mIcon.size);
}
ofPopStyle();
ofPopStyle();
}
}

void onMouseRelease(ofPoint m)
Expand Down
48 changes: 44 additions & 4 deletions src/components/ofxDatGuiGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,56 @@ class ofxDatGuiDropdown : public ofxDatGuiGroup {
mOption = 0;
mType = ofxDatGuiType::DROPDOWN;
mStripeColor = mTemplate->dropdown.color.stripe;
setOptions(options);
}

~ofxDatGuiDropdown() {
clearOptions();
}

static ofxDatGuiDropdown* getInstance()
{
return new ofxDatGuiDropdown("X");
}

void setOptions(const vector<string>& options) {
clearOptions();
for(int i=0; i<options.size(); i++){
ofxDatGuiDropdownOption* opt = new ofxDatGuiDropdownOption(options[i], mTemplate);
opt->setIndex(children.size());
opt->onButtonEvent(this, &ofxDatGuiDropdown::onOptionSelected);
children.push_back(opt);
}
}

static ofxDatGuiDropdown* getInstance()
{
return new ofxDatGuiDropdown("X");

void clearOptions() {
if (children.size() > 0) {
for (int i=0; i<children.size(); i++) {
delete children[i];
}
children.clear();
}
mOption = 0;
}

void selectOption(const string& option) {
if (children.size() > 0) {
int optionIndex = -1;
for (int i = 0; i < children.size(); i++) {
if (getChildAt(i)->getName().compare(option) == 0) {
optionIndex = i;
break;
}
}
if (optionIndex != -1) {
select(optionIndex);
} else {
select(mOption);
}
} else {
mOption = 0;
setLabel(mName);
}
}

void setTemplate(ofxDatGuiTemplate* tmplt)
Expand All @@ -418,6 +457,7 @@ class ofxDatGuiDropdown : public ofxDatGuiGroup {
ofLogError() << "ofxDatGuiDropdown->select("<<cIndex<<") is out of range";
} else{
setLabel(children[cIndex]->getLabel());
mOption = cIndex;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/ofxDatGuiComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ofxDatGuiComponent::setTemplate(ofxDatGuiTemplate* tmplt)
void ofxDatGuiComponent::setWidth(int w)
{
mRow.width = w;
mRow.lWidth=mRow.width*.35;
mRow.lWidth=mRow.width * mTemplate->row.label.lWidthRatio;
if (mRow.lWidth > mTemplate->row.label.maxAreaWidth) mRow.lWidth = mTemplate->row.label.maxAreaWidth;
mRow.inputX=mRow.lWidth;
mRow.rWidth=mRow.width-mRow.inputX;
Expand Down
73 changes: 50 additions & 23 deletions src/ofxDatGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,16 @@ void ofxDatGui::update()
if (mAlignmentChanged) setGuiAlignment();

// first check for gui focus change //
if (ofGetMousePressed() && mActiveGui->isMoving() == false){
if (!mActiveGui->isMoving()){
ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
for (int i=mGuis.size()-1; i>-1; i--){
for (auto gui = mGuis.rbegin(); gui != mGuis.rend(); gui++){
// ignore guis that are invisible //
if (mGuis[i]->getVisible() && mGuis[i]->hitTest(mouse)){
if (mGuis[i] != mActiveGui) mGuis[i]->focus();
if ((*gui)->getVisible() && (*gui)->hitTest(mouse)) {
if ((*gui) != mActiveGui) {
// let the previous gui process loss of focus
mActiveGui->onFocusLost();
(*gui)->focus();
}
break;
}
}
Expand All @@ -757,30 +761,33 @@ void ofxDatGui::update()
} else {
mMoving = false;
// this gui has focus so let's see if any of its components were interacted with //
if (mExpanded == false){
if (!mExpanded){
mGuiFooter->update();
} else{
} else {
int activeItemIndex = -1;
for (int i=0; i<items.size(); i++) {
items[i]->update();
if (items[i]->getFocused()) {
activeItemIndex = i;
if (mGuiHeader != nullptr && mGuiHeader->getDraggable() && mGuiHeader->getPressed()){
// track that we're moving to force preserve focus //
mMoving = true;
ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
moveGui(mouse - mGuiHeader->dragOffset);
}
break;
} else if (items[i]->getIsExpanded()){
// check if one of its children has focus //
for (int j=0; j<items[i]->children.size(); j++) {
if (items[i]->children[j]->getFocused()){
activeItemIndex = i;
break;
// only update if the item is visible
if (items[i]->getVisible()) {
items[i]->update();
if (items[i]->getFocused()) {
activeItemIndex = i;
if (mGuiHeader != nullptr && mGuiHeader->getDraggable() && mGuiHeader->getPressed()) {
// track that we're moving to force preserve focus //
mMoving = true;
ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY());
moveGui(mouse - mGuiHeader->dragOffset);
}
break;
} else if (items[i]->getIsExpanded()) {
// check if one of its children has focus //
for (int j = 0; j < items[i]->children.size(); j++) {
if (items[i]->children[j]->getFocused()) {
activeItemIndex = i;
break;
}
}
if (activeItemIndex != -1) break;
}
if (activeItemIndex != -1) break;
}
}
// update the remaining components //
Expand All @@ -799,6 +806,26 @@ void ofxDatGui::update()
trash.clear();
}

void ofxDatGui::onFocusLost() {
// losing focus is essentially the mouse leaving even if the mouse is actually in the unfocused gui
// so manually update the the components as if the mouse left
if (mGuiHeader != nullptr) {
mGuiHeader->onMouseLeave(ofPoint(0,0));
}
if (mGuiFooter != nullptr) {
mGuiFooter->onMouseLeave(ofPoint(0,0));
mGuiFooter->onFocusLost();
}
for (auto* item : items) {
for (auto* child : item->children) {
child->onMouseLeave(ofPoint(0,0));
child->onFocusLost();
}
item->onMouseLeave(ofPoint(0,0));
item->onFocusLost();
}
}

void ofxDatGui::draw()
{
if (mVisible == false) return;
Expand Down
1 change: 1 addition & 0 deletions src/ofxDatGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ofxDatGui : public ofxDatGuiInteractiveObject
void draw();
void focus();
void update();
void onFocusLost();

bool isMoving();
void setWidth(int width);
Expand Down
1 change: 1 addition & 0 deletions src/templates/ofxDatGuiTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ofxDatGuiTemplate{
float stripeWidth = 2.0f;
struct {
float maxAreaWidth = 240.0f;
float lWidthRatio = 0.35f;
bool forceUpperCase = true;
} label;
struct {
Expand Down