Superscript / subscript text in button?

110 views
Skip to first unread message

Everto Rex

unread,
Mar 19, 2015, 5:51:31 PM3/19/15
to fltkg...@googlegroups.com
Hello people, can I attach text in superscript or subscript to a button? I'm working in a little project and I need put several chemical products names like  Fe<sub>3</sub>(SO4)<sub>3</sub> or KNO<sub>3</sub>

Well, is posible do that or I need write a new class based in Fl_Button.*? Any suggestions are welcome. Thanks !!

Ian MacArthur

unread,
Mar 19, 2015, 5:57:36 PM3/19/15
to fltkg...@googlegroups.com
On Thu Mar 19 2015 21:49:13, Everto Rex wrote:
> Hello people, can I attach text in superscript or subscript to a button? I'm working in a little project and I need put several chemical products names like Fe<sub>3</sub>(SO4)<sub>3</sub> or KNO<sub>3</sub>
>
> Well, is posible do that or I need write a new class based in Fl_Button.*? Any suggestions are welcome. Thanks !!

Fltk doesn’t have any complex text layout engine, so formatting text for super/sub-script, etc., is not handled by fltk.
You can of course generate all the necessary symbols and glyphs, but you will probably need to do the actual layout yourself...

I think creating your own label class might be the way to go, then call that from your button to render the requisite label as needed.




Greg Ercolano

unread,
Mar 19, 2015, 8:03:46 PM3/19/15
to fltkg...@googlegroups.com
I must say I don't think I've ever seen super/subscript inside FLTK
during utf8 tests, but haven't actually tried the Unicode super/subscript modes
described here: http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts


Edzard Egberts

unread,
Mar 20, 2015, 3:19:54 AM3/20/15
to 'ed' via fltk.general
Everto Rex wrote:
> Hello people, can I attach text in superscript or subscript to a button?
> I'm working in a little project and I need put several chemical products
> names like Fe<sub>3</sub>(SO4)<sub>3</sub> or KNO<sub>3</sub>
>
> Well, is posible do that or I need write a new class based in
> Fl_Button.*?

I wrote this kind of class for a Fl_Box. You only need to derive it from
Fl_Button instead of Fl_Box. It's not a nice piece of software and just
was developed to the point it barely works, but it works. When you find
some improvements I would be glad to get some code back. ;o)



Fl_Scientific_Box.h
Fl_Scientific_Box.cpp

dori...@gmail.com

unread,
Mar 20, 2015, 1:45:17 PM3/20/15
to fltkg...@googlegroups.com
You could create images of button labels with some other software (such as Photoshop), and put those images on the buttons.
Message has been deleted

Everto Rex

unread,
Mar 20, 2015, 3:23:43 PM3/20/15
to fltkg...@googlegroups.com


On Thursday, March 19, 2015 at 6:51:31 PM UTC-3, Everto Rex wrote:
Hello people, can I attach text in superscript or subscript to a button? I'm working in a little project and I need put several chemical products names like  Fe<sub>3</sub>(SO4)<sub>3</sub> or KNO<sub>3</sub>

Well, is posible do that or I need write a new class based in Fl_Button.*? Any suggestions are welcome. Thanks !!

 Well, thanks for answering my question. As Ian says, I must develop a class for the superscript / subscript text, and this work has been done by ed_09. Following the suggestion of Greg and ed_09's class, I made a demo
dori, I can not use images because text changes dynamically.
compile.sh
Fl_Scientific_Button.h
Fl_Scientific_Button.cpp
test.cpp

Greg Ercolano

unread,
Mar 20, 2015, 4:13:49 PM3/20/15
to fltkg...@googlegroups.com
On 03/20/15 12:23, Everto Rex wrote:
> Well, thanks for answering my question. As Ian says, I must develop a class
> for the superscript / subscript text, and this work has been done by ed_09.
> Following the suggestion of Greg and ed_09's class, I made a demo

Seems to compile and run pretty well here on linux; looks good!
Screenshot of the resulting app attached.. very cool.
foo.png

crocher...@gmail.com

unread,
Mar 20, 2015, 7:32:32 PM3/20/15
to fltkg...@googlegroups.com
Just jumping in the discussion for a quick suggestion: your Scientific _Button looks really good, why not using a more standard syntax, Latex like, for this:  _ for subscript and ^ for superscript ? "Fe~t3~.(SO~t4~.) (PO~t4~.)~h-3~." would became "Fe_3 (SO_4) (PO_4)^{-3}" or "Fe_{3} (SO_{4}) (PO_{4})^{-3}" depending how the parsing is done.

Ian MacArthur

unread,
Mar 21, 2015, 6:31:26 PM3/21/15
to fltkg...@googlegroups.com
On Fri Mar 20 2015 23:32:32, crocher...@gmail.com wrote:
> Just jumping in the discussion for a quick suggestion: your Scientific _Button looks really good, why not using a more standard syntax, Latex like, for this: _ for subscript and ^ for superscript ? "Fe~t3~.(SO~t4~.) (PO~t4~.)~h-3~." would became "Fe_3 (SO_4) (PO_4)^{-3}" or "Fe_{3} (SO_{4}) (PO_{4})^{-3}" depending how the parsing is done.


I had wondered if some html-inspired syntax might be more useful; but the “Latex style" does look more readable.

That said, I’ve never been that keen on Latex...




Daniel Rubén Ome

unread,
Mar 23, 2015, 1:07:39 AM3/23/15
to fltkg...@googlegroups.com


El viernes, 20 de marzo de 2015, 20:32:32 (UTC-3), crocher...@gmail.com escribió:
Just jumping in the discussion for a quick suggestion: your Scientific _Button looks really good, why not using a more standard syntax, Latex like, for this:  _ for subscript and ^ for superscript ? "Fe~t3~.(SO~t4~.) (PO~t4~.)~h-3~." would became "Fe_3 (SO_4) (PO_4)^{-3}" or "Fe_{3} (SO_{4}) (PO_{4})^{-3}" depending how the parsing is done.



I made a few changes to code for use the Latex style.
Fl_Scientific_Button.cpp
test.cpp

crocher...@gmail.com

unread,
Mar 23, 2015, 6:48:11 PM3/23/15
to fltkg...@googlegroups.com
Looks really nice ! At least to me but I certainly have a biased in favour of this syntax since I'm a Latex user, but if I'm correct that's the same syntax used by MS Office or Open/Libre Office equations editors so I feel it's more "standard".

Anyway, I need to find a project in which I need that widgets !

bat

unread,
Mar 25, 2015, 12:37:06 PM3/25/15
to fltkg...@googlegroups.com
Those buttons do look lovely but the frustrated chemist in me says shouldn't they be 3- rather than -3 ;-?

Greg Ercolano

unread,
Mar 25, 2015, 1:30:15 PM3/25/15
to fltkg...@googlegroups.com
On 03/25/15 09:37, bat wrote:
> Those buttons do look lovely but the frustrated chemist in me says shouldn't they be 3- rather than -3 ;-?

Marking this off topic, and I'm not the OP,
but I'm thinking you're right.

What's the rule on that exactly? I'm thinking the sign on superscripts
appear: as a suffix for negative ions, and a prefix for positive ions?

I've definitely seen in the same book:

SO_4^+2
SO_4^2-

(using the ^ and _ notation for super- and sub-scripts respectively)

Oddly, my AP chem book from the 70's doesn't seem to cover these
nuances, and I've been away from this stuff far too long to remember..

bat

unread,
Mar 25, 2015, 3:20:30 PM3/25/15
to fltkg...@googlegroups.com
I have only ever seen the number before the sign for both + and - charges of ions. I think it helps to avoid confusion with + and - powers e.g. kg m^-3 being kg per cubic metre, etc,... no doubt preaching to the converted again.


On Thursday, 19 March 2015 21:51:31 UTC, Everto Rex wrote:
Reply all
Reply to author
Forward
0 new messages