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

Problems with wrapping rawui.Area #37

Open
KnorrFG opened this issue Feb 24, 2021 · 1 comment
Open

Problems with wrapping rawui.Area #37

KnorrFG opened this issue Feb 24, 2021 · 1 comment

Comments

@KnorrFG
Copy link

KnorrFG commented Feb 24, 2021

Hey,
I'm trying to wrap the low level drawing stuff into a nicer API, and I'm facing some trouble. If I add the following code to the very bottom of ui.nim

type 
  Area* = ref object of Widget
    #onDraw*: proc(self: Area, p: AreaDrawParams)
    #onMouseEvent*: proc(self: Area, ev: AreaMouseEvent)
    #onMouseCrossed*: proc(self: Area, left: bool)
    #onDragBroken*: proc(self: Area)
    #onKeyEvent*: proc(self: Area, ev: AreaKeyEvent): bool
    handler: rawui.AreaHandler
    
genImplProcs(Area)

proc drawDefaultCallback(a: ptr AreaHandler, area: ptr Area,
                         p: ptr AreaDrawParams) {.cdecl.} =
  discard

proc meDefaultCallback(self: Area, ev: AreaMouseEvent) {.cdecl.} = discard
proc mcDefaultCallback(self: Area, left: bool) {.cdecl.} = discard
proc dbDefaultCallback(self: Area) {.cdecl.} = discard
proc keDefaultCallback(self: Area, ev: AreaKeyEvent): bool {.cdecl.} = false

proc newArea*(dc = drawDefaultCallback,
              mec = meDefaultCallback,
              mcc = mcDefaultCallback,
              dbc = dbDefaultCallback,
              kec = keDefaultCallback): Area =
  new result
  result.handler.draw = dc
  result.handler.mouseEvent = mec
  result.handler.mouseCrossed = mcc
  result.handler.dragBroken = dbc
  result.handler.keyEvent = kec

Ill get the error: Error: type mismatch: got <proc (a: ptr AreaHandler, area: ptr Area, p: ptr AreaDrawParams){.cdecl, noSideEffect, gcsafe, locks: 0.}> but expected 'proc (a2: ptr AreaHandler, a3: ptr Area, a4: ptr AreaDrawParams){.cdecl.}' for the line: result.handler.draw = dc. Can someone explain why that is, and how to fix it?

@neroist
Copy link

neroist commented Jan 29, 2023

Replace ptr Area with ptr rawui.Area. Nim thinks you're referring to the Area type which you defined, not the one from rawui.

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