Wojciech Jaczewski wrote:
> I tried to display custom text on top of an image. My first attempt was to
> use InvisibleBox as below:
>
> int main(int argc, char ** argv) {
> fltk::register_images();
> fltk::Window * window = new fltk::Window(0, 0, 480, 640, "Test");
> window->begin();
>
> window->image(new fltk::TiledImage(fltk::SharedImage::get("test.png")));
> fltk::InvisibleBox * b = new fltk::InvisibleBox(60, 120, 340, 80,
> "Sample text.");
> b->labelfont(fltk::COURIER_BOLD);
> b->labelsize(28);
>
> window->end();
> window->show(argc, argv);
>
> return fltk::run();
> }
>
> but in this example even "Sample text." is not visible. I can't find any
> predefined box type, that allows to display text on top of other widget
> (image on my example) with no background and no border.
> I created custom class by some mindless copy-paste from src/UpBox.cxx:
>
> struct BoxNoBackground : public fltk::Box {
> void _draw(const fltk::Rectangle & r) const {}
> BoxNoBackground() : fltk::Box("xyz") { set_inset(1); }
> };
> static BoxNoBackground bnb;
> static fltk::Box * const BOX_NO_BACKGROUND = &bnb;
>
> and further use:
> b->box(BOX_NO_BACKGROUND);
>
> but it would be strange if there isn't solution without creating custom class.
> What is the preferred way to display text on top of other widget?
I'm no expert on fltk2, but I added one line ("<-- ADDED THIS")
to make your code work:
#include <fltk/Window.h>
#include <fltk/TiledImage.h>
#include <fltk/SharedImage.h>
#include <fltk/InvisibleBox.h>
#include <fltk/Widget.h>
#include <fltk/run.h>
int main(int argc, char ** argv) {
fltk::register_images();
fltk::Window * window = new fltk::Window(0, 0, 480, 640, "Test");
window->begin();
window->image(new fltk::TiledImage(fltk::SharedImage::get("test.png")));
fltk::InvisibleBox * b = new fltk::InvisibleBox(60, 120, 340, 80, "Sample
text.");
b->labelfont(fltk::COURIER_BOLD);
b->labelsize(28);
b->align(fltk::ALIGN_CENTER); // <-- ADDED THIS
window->end();
window->show(argc, argv);
return fltk::run();
}
I'm not sure exactly why the align() is needed, but if you
comment it out, the text disappears with the default alignments.
I found I can also set it to ALIGN_INSIDE and it will work as well.
I guess ask the core devs if this is intentional behavior.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk