ofxButton: distinguish button from Toggle visually with circle vs square#8144
ofxButton: distinguish button from Toggle visually with circle vs square#8144ofTheo merged 2 commits intoopenframeworks:masterfrom
Conversation
|
I agree. This seems like a good idea. Although I think it is a good idea to optimize its drawing by caching the geometries instead of having to generate each time. I can guess that this would be beneficial for low power systems such as a raspberrypi. And the button does not change its size, only where it gets drawn, so it is quite easy to generate once and then just draw. |
|
i agree with the caching but this code is a simply copy-paste from the ofxToggle with 3 changes lines (the method is otherwise inherited as-is from ofxToggle) -- the principle you describe should be implemented within ofxToggle (and perhaps others, for instance the text region of all elements?). but that is a much deeper dive and seems risky/out-of-scope versus a simple tweak of what is currently in place? |
There is already caching for the text, and some of the geometries. I digged into it a while ago, so I can't tell from the top of my head. I can check how to optimize this |
|
ah but i just verified and this openFrameworks/addons/ofxGui/src/ofxBaseGui.cpp Lines 152 to 160 in 2bd8b45 |
|
I was actually recalling what goes on here which is used in ofxSlider but not in ofxToggle (which I guess it should, as it currently uses an ofPath). Drawing an ofPath is more expensive than drawing an ofMesh, as the ofPath will teselate, generate a mesh, and then draw. Drawing a circle is more expensive than drawing a square. But, maybe I am getting to picky. |
|
openFrameworks/libs/openFrameworks/graphics/ofPath.cpp Lines 642 to 652 in 2bd8b45 so unless the user drags ofxPanel around, the mesh is is not refreshed. |
It is a bit confusing that the visual representation of an ofxButton is the same as the ofxToggle, as it is not possible to pre-determine that the widget will behave differently without clicking it. Even once clicked, it looks like an active toggle so you only know if if it's going to "stick" or not upon release.
This changes the representation of the Button to a rounded rectangle, completely filled when clicked (much like buttons do, in most environments). it is close enough to the original square to not disturb the visual ambiance of a populated ofxPanel, but still conveys it's operational status clearly.
It does not affect usage or API, nor adds methods or memory requirements as it simply implement it's own
generateDrawover the one inherited by ofxToggle, by copying theofxToggle::generatedDrawintegrally and changing a few draw calls -- no changes in code logic).ex.mov