Skip to content

Commit 034204f

Browse files
authored
ofxButton: distinguish button from Toggle visually with circle vs square (#8144)
1 parent 14eb7d7 commit 034204f

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

addons/ofxGui/src/ofxButton.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,44 @@ ofxButton* ofxButton::setup(const std::string& toggleName, float width, float he
4646
return this;
4747
}
4848

49+
void ofxButton::generateDraw(){
50+
bg.clear();
51+
bg.setFillColor(thisBackgroundColor);
52+
bg.rectangle(b);
53+
54+
fg.clear();
55+
fg.setFilled(false);
56+
fg.setStrokeWidth(1);
57+
fg.setStrokeColor(thisFillColor);
58+
fg.rectRounded(b.getPosition()+checkboxRect.getTopLeft()+glm::vec2{1,1},checkboxRect.width-2,checkboxRect.height-2, 5);
59+
60+
cross.clear();
61+
cross.setStrokeColor(thisTextColor);
62+
cross.setFillColor(thisFillColor);
63+
cross.setStrokeWidth(2);
64+
cross.setFilled(true);
65+
cross.rectRounded(b.getPosition()+checkboxRect.getTopLeft()+glm::vec2{1,1},checkboxRect.width-2,checkboxRect.height-2, 5);
66+
67+
std::string name;
68+
auto textX = b.x + textPadding + checkboxRect.width;
69+
if(getTextBoundingBox(getName(), textX, 0).getMaxX() > b.getMaxX() - textPadding){
70+
for(auto c: ofUTF8Iterator(getName())){
71+
auto next = name;
72+
ofUTF8Append(next, c);
73+
if(getTextBoundingBox(next,textX,0).getMaxX() > b.getMaxX() - textPadding){
74+
break;
75+
}else{
76+
name = next;
77+
}
78+
}
79+
}else{
80+
name = getName();
81+
}
82+
83+
textMesh = getTextMesh(name, textX, getTextVCenteredInRect(b));
84+
}
85+
86+
4987
bool ofxButton::mouseReleased(ofMouseEventArgs & args){
5088
bool attended = setValue(args.x, args.y, false);
5189
bGuiActive = false;

addons/ofxGui/src/ofxButton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ofxButton : public ofxToggle{
1212
~ofxButton();
1313
ofxButton* setup(ofParameter<void> _bVal, float width = defaultWidth, float height = defaultHeight);
1414
ofxButton* setup(const std::string& toggleName, float width = defaultWidth, float height = defaultHeight);
15+
void generateDraw();
1516

1617
virtual bool mouseReleased(ofMouseEventArgs & args);
1718
virtual bool mouseMoved(ofMouseEventArgs & args);

0 commit comments

Comments
 (0)