simonkrauter / NiGui

Cross-platform desktop GUI toolkit written in Nim
MIT License
724 stars 49 forks source link

Changing Colour of Button results in `cannot dispatch; dispatcher is nil` #152

Open theAkito opened 2 years ago

theAkito commented 2 years ago
  button_switchMode.onClick = proc(event: ClickEvent) = bMode = if bMode == ENCODE:
      button_switchMode.canvas.areaColor = rgb(255, 0, 0)
      button_switchMode.text = $DECODE
      DECODE
    else:
      button_switchMode.canvas.areaColor = rgb(0, 255, 0)
      button_switchMode.text = $ENCODE
      ENCODE

When this onClick event gets triggered, my app is getting the following error.

Error: unhandled exception: cannot dispatch; dispatcher is nil

When trying to research this issue, there were hints pointing at it being a problem with incorrect method implementations or at least related to objects.

simonkrauter commented 2 years ago

Currently buttons don't support a custom background color or custom drawing through a canvas. As far as I know there is no easy way to implement this.

theAkito commented 2 years ago

Currently buttons don't support a custom background color or custom drawing through a canvas. As far as I know there is no easy way to implement this.

What about this?

https://github.com/simonkrauter/NiGui/blob/03f7db26317fdc84a0f7b2ff92d7d8a50cb045a2/examples/example_30_custom_button.nim#L12

simonkrauter commented 2 years ago

Oh right. What I said above only applies for a native button. You can use your own button based on the type Button. Then your code is responsible for drawing the widget.