Giter VIP home page Giter VIP logo

Comments (7)

deech avatar deech commented on May 29, 2024

Ah, this is my mistake not yours.

The reason you are getting the segfault is that Widget has no default draw function. defaultCustomWidgetFuncs just creates a null pointer because there is nothing else it can do. When the Window tries to draw the widget it hits the null pointer and segfaults.

When you use Output, a widget with a default drawing routine you don't see this.

I think I'm going to change the widget constructor to take a drawing function so the user has to provide one.

What do you think?

Also you're using docs for an unsupported version of FLTK. Here is the version supported by this lib: http://www.fltk.org/doc-1.3/basics.html

from fltkhs.

jdreaver avatar jdreaver commented on May 29, 2024

Ah, I understand now.

I think I'm going to change the widget constructor to take a drawing function so the user has to provide one.

That sounds like a great solution. IMO, if a drawing function is required, the types should reflect that. No null pointers in Haskell! 😄

What drawing function is the FLTK example program using? Does a "default drawing function" exist for widgets? It looks like the default Widget in FLTK is like a label. That seems kind of weird to me. (Sorry if my terminology is a little off, I'm still learning.)

from fltkhs.

deech avatar deech commented on May 29, 2024

No prob.

The supported example program I linked uses the Fl_Box widget which has it's own drawing routine.

I've recreated the example from the supported version and I can confirm it works:

module Main where

import qualified Graphics.UI.FLTK.LowLevel.FL as FL
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Graphics.UI.FLTK.LowLevel.FLTKHS

main :: IO ()
main = do
  w1 <- windowNew (Size (Width 300) (Height 180)) Nothing (Just "Hello!")
  begin w1
  let labelRect = Rectangle (Position (X 20) (Y 40)) (Size (Width 260) (Height 100))
  label <- boxNew labelRect (Just "Bob") Nothing
  setBox label UpBox
  setLabelfont label helveticaBoldItalic
  setLabelsize label (FontSize 36)
  setLabeltype label ShadowLabel
  end w1
  showWidget w1
  _ <- FL.run
  return ()

from fltkhs.

jdreaver avatar jdreaver commented on May 29, 2024

For some reason I didn't see your last part about me using the docs from and unsupported version of FLTK. I understand perfectly why my program doesn't work now. I can confirm that your example works. Thanks for your help!

You can close this issue if you want, or leave it open to remind you of the change to Widget you wanted to make.

from fltkhs.

deech avatar deech commented on May 29, 2024

Uploaded a fixed version to Hackage http://hackage.haskell.org/package/fltkhs.

from fltkhs.

deech avatar deech commented on May 29, 2024

I have made some changes that make working with custom widgets a little easier. This includes some breaking API changes. In your example:

label <- boxNew labelRect (Just "Bob") Nothing

is now:

label <- boxNew labelRect (Just "Bob")

The new version (0.3.0.0) is now up on Hackage. Thanks for bringing this issue to light. It's good to make these changes while the library is still young. :)

from fltkhs.

jdreaver avatar jdreaver commented on May 29, 2024

Yeah, that is a lot cleaner for the probably most common case of non-custom widgets. Thanks!

from fltkhs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.