setLabelFont doesn't seem to work (crashes the app)
While making a little port of the 'Hello World' example on fltk.org
// http://www.fltk.org/doc-1.3/basics.html
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(340,180);
Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");
box->box(FL_UP_BOX);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
I noticed that the setLabelFont doesn't seem to work. The program compiles fine, but crashes.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Graphics.UI.FLTK.LowLevel.FL as FL
import qualified Graphics.UI.FLTK.LowLevel.Fl_Enumerations as FL
import qualified Graphics.UI.FLTK.LowLevel.Fl_Types as FL
import Graphics.UI.FLTK.LowLevel.FLTKHS
import qualified Graphics.UI.FLTK.LowLevel.Hierarchy as FL hiding (flush)
ui :: IO ()
ui = do
window <- windowNew (Size (Width 340) (Height 180)) Nothing (Just "First Program")
begin window
let
boxPos = (Position (X 20) (Y 40))
boxSize = Size (Width 300) (Height 100)
box <- boxNewWithBoxtype FL.UpBox (Rectangle boxPos boxSize) "Hello World"
FL.setLabeltype box (FL.ShadowLabel)
FL.setLabelfont box (FL.Font 12) -- remove this line to avoid crash
end window
showWidget window
return ()
main :: IO ()
main = do
ui >> FL.run >> FL.flush
I think this needs to be looked at.
I noticed that the types of the C++ and the Haskell do not quite match. In C++ there's labelfont and labelsize, which take a font type enum and a size int. In Haskell setLabelFont takes a Font type. (My guess is that setLabelFont corresponds to the C++ labelfont member function.)
Hi,
Thanks for the report! Unfortunately I am unable to reproduce the crash on my Debian box, but what I do see is a window with a blank box. The reason is that the line FL.setLabelfont box (FL.Font 12) does not map to box->labelfont(FL_BOLD+FL_ITALIC). This is why I get a blank box because FL.Font 12 maps to the symbol font which is not present on my machine. The fix is FL.setLabelfont box FL.helveticaBoldItalic.
Yes indeed that is it. Thank you!
May I ask one more thing?
How do you find out (in a systematic way, i.e. not by looking at examples), what the argument to the set/get functions is, e.g. for setLabelsize? I know it is something like FontSize 36 and I got that by looking at fltkhs-fluidtohs output. From the docs or error messages I'm not able deduce that, though.
Yes there is a way. In this case you could start with the docs for Box and click the link for Widget in the hierarchy diagram and widget functions will show that setLabelsize takes a FontSize. As to what number to use you can then consult the FLTK docs.
I wish it were less awkward but it's the best I can do.