dariolah / nim-iup-examples

Nim GUI examples using IUP
20 stars 3 forks source link

Try re-creating temp convert using nuip #10

Closed nixfreak closed 2 years ago

nixfreak commented 2 years ago

I'm sure this is pretty messed up but , I am not understanding the callbacks I guess. Also setting the attributes is probably wrong. It compiles just fine but no callbacks work.

import std/[httpclient, strutils, strformat]
import niup
#import TempFormula

var
  label_c: Label_t
  label_f: Label_t
  textLabel_c: Text_t
  textLabel_f: Text_t

proc txt_celcius_cb(ih: PIhandle):cint {.cdecl.} =
  var fahrenheit = GetDialogChild("Fahrenheit")
  var value = float(value * (1.8) + 32)
   return IUP_DEFAULT

proc txt_fahrenheit_cb(ih: PIhandle):cint {.cdecl.} =
  var celcius = GetDialogChild("Celcius")

   return IUP_DEFAULT

#proc button_show_ip(ih: PIhandle): cint {.cdecl.} = # every callback has cint as return value
#textLabel.value = Ip()
  #return IUP_DEFAULT

# create main proc and open UIP application
proc mainProc =
  Open()

# create 2 labels and 2 textLabels
  textLabel_f.value =
  label_c = Label("Celcius  " & " = ")
  SetAttribute(textLabel_c, "VALUE", "")
  SetAttribute(textLabel_c, "NAME", "Celcius")
  textLabel_c = Text("")
  textLabel_c.alignment = IUP_ACENTER

  label_f  = Label("Fahrenheit")
  SetAttribute(textLabel_f, "VALUE", "")
  SetAttribute(textLabel_f, "NAME", "Fahrenheit")
  textLabel_f = Text("")
  textLabel_f.alignment = IUP_ACENTER

  var
     hbox = Hbox(textLabel_c, label_c, "=" ,textLabel_f, label_f)

  hbox.alignment = IUP_ACENTER
  hbox.gap(20)
  hbox.margin(20, 20)
# add dialog box to show title of UIP application

  var dlg_h = Dialog(hbox)
  dlg_h.title = "Convert Temperature"
  dlg_h.bgcolor = "#7f11e0"

# call backs
  SetCallback(textLabel_c, "VALUECHANGED_CB",  (ICallback(txt_celcius_cb)))
  SetCallback(textLabel_f, "VALUECHANGED_CB",  (ICallback(txt_fahrenheit_cb)))
# show UIP application
  #ShowXY(dlg, IUP_CENTER, IUP_CENTER)
  ShowXY(dlg_h , IUP_CENTER, IUP_CENTER)

  MainLoop()
  Close()

if isMainModule: # if main module than call mainProc()
  mainProc()
nixfreak commented 2 years ago

Issue closed