Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

fix ofxUIDropdownList::setSingleSelected not updating selectedIndices #256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/ofxUIDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifdef TARGET_OF_IOS
#define OFX_UI_FONT_NAME "GUI/Helvetica.ttf"
#else
#define OFX_UI_FONT_NAME "sans-serif"
#define OFX_UI_FONT_NAME OF_TTF_SERIF//sans-serif"
#endif

#define OFX_UI_FONT_RESOLUTION 150
Expand Down
2 changes: 2 additions & 0 deletions src/ofxUIDropDownList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ void ofxUIDropDownList::setSingleSelected(int index){
selected.clear();
ofxUILabelToggle *lt = toggles.at(index);
selected.push_back(lt);
selectedIndeces.clear();
selectedIndeces.push_back(index);
setShowCurrentSelected(true);
}else{
ofLogWarning("index for ufxUIDropDownList::setSingleSelected is out of range");
Expand Down
40 changes: 35 additions & 5 deletions src/ofxUITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,53 @@ void ofxUITabBar::addCanvas(ofxUIScrollableCanvas *_canvas)
autoSizeToFitWidgets();
}

bool ofxUITabBar::setSelected( string name){
for(auto kv:canvases){
if( kv.second->getName() == name){
setSelected(kv.first);
return true;
}
}
return false;
}

bool ofxUITabBar::setSelected(ofxUIToggle * t){
if(active!=nullptr){
for(auto kv : canvases){
if(kv.second==active){
kv.first->setValue(false);
break;
}
}
active->disable();
}
if(!canvases.count(t)){
return false;
}
ofxUICanvas * c = canvases[t];
active = c;
t->setValue(true);
c->enable();
c->setPosition(rect->getX() + rect->getWidth() + padding*0.5, this->rect->getY());
return true;
}

void ofxUITabBar::mainUiEvent(ofxUIEventArgs &event)
{
string name = event.getName();
bool isChanging = false;
for (map<ofxUIToggle*, ofxUICanvas*>::iterator it=canvases.begin(); it!=canvases.end(); ++it)
{
if(active != NULL && active->getName() == name)
if(!isChanging && active != NULL && active->getName() == name)
{
it->first->setValue(false);
it->second->disable();
active = NULL;
}
else if(it->second->getName() == name && event.getToggle()->getValue())
{
active = it->second;
it->first->setValue(true);
it->second->enable();
it->second->setPosition(rect->getX() + rect->getWidth() + padding*0.5, this->rect->getY());

isChanging = setSelected(it->first);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/ofxUITabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class ofxUITabBar : public ofxUICanvas
bool isHit(int x, int y);
void saveSettings(string pathToSaveTo, string fileNamePrefix);
void loadSettings(string pathToLoadFrom, string fileNamePrefix);

bool setSelected(ofxUIToggle * t);
bool setSelected( string name);
protected:
map<ofxUIToggle*, ofxUICanvas*> canvases;
ofxUICanvas *active;
Expand Down