Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setLabelFont doesn't seem to work (crashes the app) #85

Open
mayeranalytics opened this issue Apr 24, 2018 · 4 comments
Open

setLabelFont doesn't seem to work (crashes the app) #85

mayeranalytics opened this issue Apr 24, 2018 · 4 comments

Comments

@mayeranalytics
Copy link

mayeranalytics commented Apr 24, 2018

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.)

@mayeranalytics mayeranalytics changed the title setLabelFont doesn't seem to work setLabelFont doesn't seem to work (leads to a crash) Apr 24, 2018
@mayeranalytics mayeranalytics changed the title setLabelFont doesn't seem to work (leads to a crash) setLabelFont doesn't seem to work (crashes the app) Apr 24, 2018
@deech
Copy link
Owner

deech commented Apr 24, 2018

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.

@mayeranalytics
Copy link
Author

Yes indeed that is it. Thank you!

@mayeranalytics
Copy link
Author

mayeranalytics commented Apr 24, 2018

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.

@deech
Copy link
Owner

deech commented Apr 24, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants