can I change the default attributes so I can set "global attributes"

57 views
Skip to first unread message

roger tunnicliffe

unread,
Sep 29, 2022, 10:27:44 PM9/29/22
to fltk.general
I have searched for a while for this but haven't come up with an answer. (I'm guessing it's obvious).
Fltk  has defaults for eg. Colour, Font Size etc and I would like to set my own so I don't have to code them on each individual widget. Can someone tell me how to do this.

Cheers
Roger

Manolo

unread,
Sep 30, 2022, 7:32:18 AM9/30/22
to fltk.general
Hi Roger,


FLTK uses these colors for these tasks :
    FL_BACKGROUND_COLOR - the default background color
    FL_BACKGROUND2_COLOR - the default background color for
        text, list, and valuator widgets
    FL_FOREGROUND_COLOR - the default foreground color (0) used
       for labels and text
    FL_INACTIVE_COLOR - the inactive foreground color
    FL_SELECTION_COLOR - the default selection/highlight color

You can change their values by calling
   void Fl::set_color(Fl_Color i, unsigned c)
with i set to, say, FL_BACKGROUND_COLOR and c to a predefined color name,
say, FL_YELLOW;
or by calling
   void Fl::set_color(Fl_Color i, uchar r, uchar g, uchar b)
with i as above and r,g,b set to an RGB value (r, g and b should be in the range [0..255])

All widgets use this font size for their text
Fl_Fontsize FL_NORMAL_SIZE = 14;
you can change the value of this public global variable.

Widgets use FL_HELVETICA as default font. You can change the font associated
to this numerical value by calling
Fl::set_font(FL_HELVETICA, "name-of-a-font-as-given-by-test-program-fonts");
but caution that font names tend to be platform-specific.

roger tunnicliffe

unread,
Sep 30, 2022, 9:12:05 AM9/30/22
to fltk.general
Great, thanks very much
Cheers

Philip Rose

unread,
Sep 30, 2022, 11:22:57 AM9/30/22
to fltkg...@googlegroups.com

From: roger tunnicliffe
Sent: 30 September 2022 14:17
To: fltk.general
Subject: [fltk.general] Re: can I change the default attributes so I can set"global attributes"

--

 

Thanks, I have been wondering how to do this as well. It’s a pity that you have to change the meaning of FL_HELVETICA as that distracts from its real meaning.

Phil.

Albrecht Schlosser

unread,
Sep 30, 2022, 11:49:27 AM9/30/22
to fltkg...@googlegroups.com
On 9/30/22 17:22 'Philip Rose' via fltk.general wrote:

From: roger tunnicliffe
Sent: 30 September 2022 14:17
To: fltk.general
Subject: [fltk.general] Re: can I change the default attributes so I can set"global attributes"

 

Great, thanks very much

Cheers

[...]

Thanks, I have been wondering how to do this as well. It’s a pity that you have to change the meaning of FL_HELVETICA as that distracts from its real meaning.


Yes, indeed.

It would maybe have been better to use a functional name for this font in the first place, something like FL_SYSTEM_TEXT_FONT, but that's really old history. I guess this name was chosen in the very beginning of FLTK development or it was even predefined by Xforms which was the library FLTK was intended to replace. But that's only a guess.

Message has been deleted

roger tunnicliffe

unread,
Sep 30, 2022, 8:45:54 PM9/30/22
to fltk.general

roger tunnicliffe
8:25 AM (2 hours ago) 
to fltk.general
Still not quite sure here.
I checked the documentation (Color & Font functions) and could only find fl_font which seemed to be part of an fl_draw package.
I expected calls for things like         
         win2_flag1->textsize(11);    ... but globally 
        win2_flag1->labelsize(11); .......but globally
etc...

Do they exist ?

Manolo

unread,
Oct 1, 2022, 6:14:33 AM10/1/22
to fltk.general
Le samedi 1 octobre 2022 à 02:45:54 UTC+2, roger a écrit :

roger tunnicliffe
8:25 AM (2 hours ago) 

to fltk.general
Still not quite sure here.
I checked the documentation (Color & Font functions) and could only find fl_font which seemed to be part of an fl_draw package.
I expected calls for things like         
         win2_flag1->textsize(11);    ... but globally 
        win2_flag1->labelsize(11); .......but globally
etc...

Do they exist ?

I don't know what would be win2_flag1 in your mind.

Among possible things, there are :
For any given pointer to n Fl_Widget (e.g., Fl_Button *) widget
widget->labelsize(size);  // sets the widget's label size
widget->labelfont(fontnumber);  // sets the widget's label font
widget->labelcolor(color);  // sets the widget's label color
widget->label(text);  // sets the widget's label text

But this applies to the given widget only.

Functions with effects on all widgets were described in my previous post.
A key thing is these functions must be used before widgets are created.
A simple way to achieve that is to begin your main() with
fl_open_display(); // needs #include <FL/platform.H>
and then use the global-effect function calls or change the value of public global variables.

Ian MacArthur

unread,
Oct 1, 2022, 6:38:25 AM10/1/22
to Fltk General
On 1 Oct 2022, at 11:14, Manolo wrote:
>
> Le samedi 1 octobre 2022 à 02:45:54 UTC+2, roger a écrit :
>
> roger tunnicliffe
> 8:25 AM (2 hours ago)
>
> to fltk.general
> Still not quite sure here.
> I checked the documentation (Color & Font functions) and could only find fl_font which seemed to be part of an fl_draw package.
> I expected calls for things like
> win2_flag1->textsize(11); ... but globally
> win2_flag1->labelsize(11); .......but globally
> etc...
>
> Do they exist ?
>
> I don't know what would be win2_flag1 in your mind.


Hi Manolo, (and Roger)

No, me neither. I *think* what the OP is looking for is a way to set a font face, size, etc, on a per-window basis, i.e. to set all the widgets in a given window to a specific face. But that’s a guess.

The fltk state globals would affect all windows, not just a specific window, of course.

I suppose it wouldn’t be that tricky to write a loop that would take a window pointer, loop through all it’s children and set the face / size for each?



Albrecht Schlosser

unread,
Oct 1, 2022, 8:07:38 AM10/1/22
to fltkg...@googlegroups.com
On 10/1/22 12:38 Ian MacArthur wrote:
> I suppose it wouldn’t be that tricky to write a loop that would take a
> window pointer, loop through all it’s children and set the face / size
> for each?

Probably not possible w/o RTTI since not all widgets support all
text/font related settings in the same way. The basics like textsize()
and labelsize() would certainly work (i.e. all methods that are defined
in Fl_Widget) but I doubt that this would be enough.

Ian MacArthur

unread,
Oct 1, 2022, 8:12:27 AM10/1/22
to Fltk General
Yeah, fair enough.
I was really only thinking about the properties inherited from Fl_Widget, but there may well be others you’d want to set “globally” per-window and that could get complicated really fast...
The basics, like font settings, might still be “trivial” though.

roger tunnicliffe

unread,
Oct 1, 2022, 8:29:42 AM10/1/22
to fltk.general
My apologies, I am new to Fltk.
What I meant was....
I have a project/system/executable (whatever you want to call it) and it might comprise of 2 or windows and lots of widgets. 
Instead of having to set - say the fontsize (or color or any other attribute) - individually I want to be able to say "make all font sizes 11".
I know that they seem to default to 14 (correct me if i am wrong) so there must be some way to do it.
Does that make it any clearer. ?

Thanks in advance.
Cheers
Roger

Albrecht Schlosser

unread,
Oct 1, 2022, 8:57:28 AM10/1/22
to fltkg...@googlegroups.com
On 10/1/22 14:29 roger tunnicliffe wrote:
> My apologies, I am new to Fltk.
> What I meant was....
> I have a project/system/executable (whatever you want to call it) and
> it might comprise of 2 or windows and lots of widgets.
> Instead of having to set - say the fontsize (or color or any other
> attribute) - individually I want to be able to say "make all font
> sizes 11".
> I know that they seem to default to 14 (correct me if i am wrong) so
> there must be some way to do it.
> Does that make it any clearer. ?

Yes, Roger, it does. But this (setting the widget font sizes globally)
has been explained by Manolo in his reply from Sep 30 together with a
lot of other global initializations:

"All widgets use this font size for their text
Fl_Fontsize FL_NORMAL_SIZE = 14;
you can change the value of this public global variable."

In short: you just need to assign
  `FL_NORMAL_SIZE = 11;`
at the beginning of your program, i.e. before all widgets are created.

Note: despite the capital letters this is not a macro, it's a global
variable.

roger tunnicliffe

unread,
Oct 1, 2022, 6:12:18 PM10/1/22
to fltk.general
FL_NORMAL_SIZE = 11;
FL_NORMAL_SIZE’ does not name a type

Fl_Fontsize FL_NORMAL_SIZE = 11;
/usr/lib/x86_64-linux-gnu/libfltk.a(Fl_Widget.o):(.data+0x0): multiple definition of `FL_NORMAL_SIZE'; /tmp/ccdB
GgUp.o:(.data+0x0): first defined here

Maybe I should explain myself to give some background to what I am trying to do.

I am assembler programmer and have written a programming language called languageONE (my 1st language).
It is built on a set of macro's in order to mimic a 3rd generation language. You may visit the site at www.languageONE.com.au 
if you have any interest in doing so. 

Having said that I have been trying to incorporate fltk as a GUI for the language. I believe it is going well but I found C++ to
be a very strange abstraction. I am hoping that you are able to bear with me while  I deal with it's idiosyncrasies. 

I do "goggle" a great deal beforehand but sadly I cannot at the moment tell what is an fltk issue or a C++ issue. I am in fact very
close to completing the task so I should not be bothering anyone too much more. Again, I trust you are able to bear with me. 

Thanking you in advance for your patience.
Cheers
Roger

Greg Ercolano

unread,
Oct 1, 2022, 7:01:02 PM10/1/22
to fltkg...@googlegroups.com


On 10/1/22 15:12, roger tunnicliffe wrote:
FL_NORMAL_SIZE = 11;
FL_NORMAL_SIZE’ does not name a type

    Make sure you've got:

        #include <FL/Fl.H>

    ..at the top of your program.


Fl_Fontsize FL_NORMAL_SIZE = 11;

    Yea, no, don't do that. That just tries to /create/ another global variable of the
    same name as the one in FLTK, and fails at link time with the conflict.

    Here's a complete program showing where you should put what:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv) {
  FL_NORMAL_SIZE = 20;
  Fl_Window *window = new Fl_Window(340, 180);
  new Fl_Button(20, 40,  300, 50, "Hello World!");
  new Fl_Box(   20, 100, 300, 50, "Some text.");
  window->end();
  window->show();
  return Fl::run();
}

    If you change the value for FL_NORMAL_SIZE to something else, that should affect
    the size of all fonts.

lifeatt...@gmail.com

unread,
Oct 1, 2022, 7:03:03 PM10/1/22
to fltk.general

FL_NORMAL_SIZE = 11;
FL_NORMAL_SIZE’ does not name a type

This is the sort of error to expect when the C++ compiler doesn't know what the definition is.
The appropriate include file has to be used before you reference the variable.

In this case, FL_NORMAL_SIZE is defined in Enumerations.H. That header is normally already included as part of
other FLTK headers. I can only guess you're trying to access that variable without a bunch of header files.

When in doubt, use Fl.H:

#include <FL/Fl.H>
int main(int argc, ...)
{
FL_NORMAL_SIZE = 11; 
}

Fl_Fontsize FL_NORMAL_SIZE = 11;
/usr/lib/x86_64-linux-gnu/libfltk.a(Fl_Widget.o):(.data+0x0): multiple definition of `FL_NORMAL_SIZE'; /tmp/ccdB
GgUp.o:(.data+0x0): first defined here

Here you've defined a conflicting copy of FL_NORMAL_SIZE. This might have worked if you had used this instead:

extern Fl_Fontsize FL_NORMAL_SIZE = 11;

The "extern" part tells the compiler/linker to look for the definition elsewhere, i.e. in the FLTK library, not in your code.

roger tunnicliffe

unread,
Oct 1, 2022, 9:32:57 PM10/1/22
to fltk.general
Thanks everybody...

the difference in the code is I had:-

#include <FL/Fl.H>
FL_NORMAL_SIZE = 11;
int main(int argc, ...)
{
}


and it seems to need:-

#include <FL/Fl.H>
int main(int argc, ...)
{
FL_NORMAL_SIZE = 11; 

 I had the impression that if you wanted something global in C++ you had to code it before the functions.
That's not the 1st time I'll be wrong about C++ (lol)

Thanks again everybody
 


roger tunnicliffe

unread,
Oct 1, 2022, 11:42:32 PM10/1/22
to fltk.general
I have been thru Enumerations and I can't find the variable so how to do I set all box types to FL_THIN_UP_BOX globally
Thx

Manolo

unread,
Oct 2, 2022, 2:35:02 AM10/2/22
to fltk.general
Le dimanche 2 octobre 2022 à 05:42:32 UTC+2, roger a écrit :
I have been thru Enumerations and I can't find the variable so how to do I set all box types to FL_THIN_UP_BOX globally
Thx

One solution is to derive a class from a widget sort frequently used in your GUI and to set the box type of
this class to FL_THIN_UP_BOX. Then, all widgets of this class wil have the desired thin up box.
If you use frequently several widgets sorts (e.g., Fl_Light_Button, Fl_Radio_Button), you would define one
derived class for each of them.

//
// Hello, World! program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2021 by Bill Spitzak and others.

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

class myThinBox : public Fl_Box {
public:
  myThinBox(int x, int y, int w, int h, const char *label) : Fl_Box(x, y, w, h, label) {
    box(FL_THIN_UP_BOX);
  }
};


int main(int argc, char **argv) {
  Fl_Window *window = new Fl_Window(340, 180);
  myThinBox *box = new myThinBox(20, 40, 300, 100, "Hello, World!");
  // you can create hundreds of myThinBox objects, they will all
  // inherit the FL_THIN_UP_BOX property
  box->labelfont(FL_BOLD + FL_ITALIC);
  box->labelsize(36);
  box->labeltype(FL_SHADOW_LABEL);
  window->end();
  window->show(argc, argv);
  return Fl::run();
}

Albrecht Schlosser

unread,
Oct 2, 2022, 9:22:41 AM10/2/22
to fltkg...@googlegroups.com
On 10/2/22 05:42 roger tunnicliffe wrote:
> I have been thru Enumerations and I can't find the variable so how to
> do I set all box types to FL_THIN_UP_BOX globally
> Thx

That's not possible because most of the FLTK widgets *assign* a boxtype
in their constructors or inherit that assignment from their base classes.

Manolo explained a way to derive your own classes with some special
assignments. This is standard C++ class inheritance applied to FLTK widgets.

If you're going to include FLTK in your language you'll probably need to
do more of such "manipulations" of FLTK classes to fit your needs. A
thorough understanding of FLTK widgets and their hierarchies caused by
C++ inheritance (which is an important topic in itself) is really
recommended.


roger tunnicliffe

unread,
Oct 2, 2022, 4:43:31 PM10/2/22
to fltk.general
Thx Manolo, I'll give that a try later this afternoon.

Albrecht. It's probably a bit premature but I did want to ask what sort of acknowledgement your project should be given when I document how fltk could be used in languageONE.
There has been no special "feature" built into languageONE to support fltk, I will just use an example program to demonstrate how it can be done. I have linked the static library up until
now and believe that it's ok to distribute but I make no such distributions and have no clients etc. (languageONE is just a pet project that's keeps dimentia away.)
The choice to use fltk in developing a languageONE project would be left to any individual who cared to do so, in the same way as I have provided a http interface up until now.

 Albrecht.. I really like fltk. It is something that I have been looking for for a while now and it fits almost seamlessly into a languageONE project. I would be interested to learn the status
of the project and how "alive" it is at the moment. As someone who has come to it without the required base knowledge (C++) it is reasonable easy to pick up and put into practice.
(I think you would be horrified if your saw how I coded it (lol). 

Congratulations to all there who work on it.

cheers
Roger Tunnicliffe

Albrecht Schlosser

unread,
Oct 7, 2022, 8:45:40 AM10/7/22
to fltkg...@googlegroups.com
On 10/2/22 22:43 roger tunnicliffe wrote:
Albrecht. It's probably a bit premature but I did want to ask what sort of acknowledgement your project should be given when I document how fltk could be used in languageONE.

Sorry for the late reply to this message, I had been distracted by other things...

Please don't address your messages in this forum to specific people like me. Ask your questions, and someone will (hopefully) reply.

To your question about acknowledgement: you can find the relevant information in our license file, linked from the main page (https://www.fltk.org) in the "Quick Info" box in the top left corner: "FLTK is provided under the terms of the GNU Library Public License, Version 2 with exceptions that allow for static linking." (explicit link: https://www.fltk.org/COPYING.php).

Particularly in point 4 at top of that page you can see all you need, but please read the rest of the license as well.


There has been no special "feature" built into languageONE to support fltk, I will just use an example program to demonstrate how it can be done. I have linked the static library up until
now and believe that it's ok to distribute but I make no such distributions and have no clients etc. (languageONE is just a pet project that's keeps dimentia away.)

It's okay to link your program the static library and if you want to distribute binaries linking statically is probably the best choice. However, if your code is open source, it is recommended not to distribute binary copies of the FLTK library for best compatibility. Users should be able to download and build FLTK themselves.


The choice to use fltk in developing a languageONE project would be left to any individual who cared to do so, in the same way as I have provided a http interface up until now.

Yep, this is another reason not to distribute FLTK in any form.


I really like fltk. It is something that I have been looking for for a while now and it fits almost seamlessly into a languageONE project.

That's good to hear and that's something we really strive to achieve. FLTK should be a *F*ast and *L*ight *T*ool*K*it. Thanks for your feedback, this is very much appreciated.


I would be interested to learn the status of the project and how "alive" it is at the moment. As someone who has come to it without the required base knowledge (C++) it is reasonable easy to pick up and put into practice.

It is nevertheless recommended (or even required) to know the basics of C++ for a better understanding of the FLTK internals, particularly widget inheritance and for instance parameter conventions, such as knowing what a C++ "string" object is as opposed to a "C string" (as you asked recently, IIRC).


Congratulations to all there who work on it.

Welcome.


cheers
Roger Tunnicliffe


On Monday, October 3, 2022 at 12:22:41 AM UTC+11 Albrecht Schlosser wrote:

[...]

Roger, please try not to top-post in this forum. It's hard to keep the context in a longer thread. Posting like I did above (citing only essential text and intertwining citations and your reply) is the style we like here and how we can help you best. Thanks in advance.
https://en.wikipedia.org/wiki/Posting_style#Top-posting

lifeatt...@gmail.com

unread,
Oct 16, 2022, 1:01:32 PM10/16/22
to fltk.general
Roger -
Thank you for asking this question. I don't feel it was "obvious" : I've been using FLTK for some time now, could have used the answer, and didn't know it!

Kevin
Reply all
Reply to author
Forward
0 new messages