Comments (8)
Dialog is visual control and container (displays window and it can contain one control or container)
If you meant to have button with IP, you can add it directly to dialog:
Dialog(Button("x.x.x.x"))
Common usage is to put another container into Dialog, one that can contain multiple controls, e.g. Vbox, Hbox, etc.
let btn = Button( "x.x.x.x")
let dlg = Dialog(
Vbox(
btn))
Or if it is input use Text(), and Label("some text") if you are displaying static text.
let btn = Button( "Exit")
let txt = Text()
txt.value = "x.x.x.x"
let dlg = Dialog(
Vbox(
txt,
btn))
Take look at niup/text.nim
from nim-iup-examples.
Its not a static IP though.
I created an hbox import niup
import std/[httpclient, strutils, strformat]
# Create an exit button proc
proc button_exit_callback(ih: PIhandle):cint {.cdecl} =
# exists the main loop
return IUP_CLOSE
const src = "https://icanhazip.com"
proc Ip*(): string =
var client = newHttpClient()
try:
let response = client.getContent(src)
result = response.strip()
except:
result = ""
finally:
client.close()
echo Ip()
proc button_show_ip(ih: PIhandle): cstring {.cdecl.} =
echo Ip()
# create main proc and open UIP application
proc mainProc =
Open()
# create 3 variables (label, button, vbox)
# var
# label = Label("Hello, IUP from nim.")
# button = Button("Hit me to close")
# vbox = Vbox(label, button) # add button and label to vertical box
# # add attributes to variables
# vbox.alignment = IUP_ACENTER
# vbox.gap(10)
# vbox.margin(30, 60)
var
label_h = Label("IP address")
button_h = Button("Show Ip Address")
#label_h_output = Label(Ip)
hbox = Hbox(label_h, button_h)
# add dialog box to show title of UIP application
hbox.alignment = IUP_ACENTER
hbox.gap(20)
hbox.margin(20, 70)
var dlg = Dialog(vbox) # add vbox to Dialog
dlg.title = "Hello, World Title"
var dlg_h = Dialog(hbox)
dlg_h.title = "Hello horizonal window"
#button_h.action = button_show_ip
opacity(dlg_h, 115) # horizonal box now has opacity
# call backs
button.action = button_exit_callback
button.action = button_show_ip
# 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()
from nim-iup-examples.
Here is slightly modified file
test.zip
Added missing niup import
Changed Label to read-only Text, so value can be changed through callback
Made it global so it is accessible from callback function
There can be only one callback in button action, later one is used. There are other callbacks for button if needed
import std/[httpclient, strutils, strformat]
import niup
var textLabel: Text_T # global, so it can be accessed from callbacksi, init later, after IUP Open()
# Create an exit button proc
proc button_exit_callback(ih: PIhandle):cint {.cdecl} =
# exists the main loop
return IUP_CLOSE
const src = "https://icanhazip.com"
proc Ip*(): string =
var client = newHttpClient()
try:
let response = client.getContent(src)
result = response.strip()
except:
let
e = getCurrentException()
msg = getCurrentExceptionMsg()
echo "Got exception ", repr(e), " with message ", msg
result = ""
finally:
client.close()
return result # there was recursive call to Ip()
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 3 variables (label, button, vbox)
# var
# label = Label("Hello, IUP from nim.")
# button = Button("Hit me to close")
# vbox = Vbox(label, button) # add button and label to vertical box
# # add attributes to variables
# vbox.alignment = IUP_ACENTER
# vbox.gap(10)
# vbox.margin(30, 60)
textLabel = Text("IP address") # declared globally so it can be accessed from callback
textLabel.readonly = true
var
button_h = Button("Show Ip Address")
#textLabel_output = Label(Ip)
hbox = Hbox(textLabel, button_h)
# add dialog box to show title of UIP application
hbox.alignment = IUP_ACENTER
hbox.gap(20)
hbox.margin(20, 70)
var dlg_h = Dialog(hbox)
dlg_h.title = "Hello horizonal window"
#button_h.action = button_show_ip
opacity(dlg_h, 115) # horizonal box now has opacity
# call backs
button_h.action = button_exit_callback
button_h.action = button_show_ip
# 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()
I recommend to go through IUP tutorial (left side navigator: Tutorial)
https://webserver2.tecgraf.puc-rio.br/iup/
To learn IUP basics, philosophy behind it.
Parts of tutorial are in niupc/example*.nim
from nim-iup-examples.
So I went through UIP tutorial and more and started to drill into NUIP , playing around with a lot of the attributes.
Do you know how to get rid of the textbox lines though? I thought if I could match the border color but I don't see a proc for that for Text.
import std/[httpclient, strutils, strformat]
import niup
var textLabel: Text_t # global, so it can be accessed from callbacksi, init later, after IUP Open()
# Create an exit button proc
#proc button_exit_callback(ih: PIhandle):cint {.cdecl} =
# exists the main loop
#return IUP_CLOSE
const src = "https://icanhazip.com"
proc Ip*(): string =
var client = newHttpClient()
try:
let response = client.getContent(src)
result = response.strip()
except:
let
e = getCurrentException()
msg = getCurrentExceptionMsg()
echo "Got exception ", repr(e), " with message ", msg
result = ""
finally:
client.close()
return result # there was recursive call to Ip()
#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 3 variables (label, button, vbox)
# var
# label = Label("Hello, IUP from nim.")
# button = Button("Hit me to close")
# vbox = Vbox(label, button) # add button and label to vertical box
# # add attributes to variables
# vbox.alignment = IUP_ACENTER
# vbox.gap(10)
# vbox.margin(30, 60)
textLabel = Text("IP address") # declared globally so it can be accessed from callback
textLabel.readonly = true
textLabel.border = "no"
textLabel.size = "70x5"
textLabel.bgcolor = "#7f11e0"
textLabel.font = "Arial, 24"
textLabel.alignment = IUP_ACENTER
textLabel.value = Ip()
var
#button_h = Button("Show IP Address")
#textLabel_output = Label(Ip)
#hbox = Hbox(button_h, textLabel)
hbox = Hbox(textLabel)
#hbox.alignment = IUP_ACENTER
hbox.gap(20)
hbox.margin(0, 20)
# add dialog box to show title of UIP application
var dlg_h = Dialog(hbox)
dlg_h.title = "Show Current IP Address"
dlg_h.bgcolor = "#7f11e0"
#button_h.action = button_show_ip
opacity(dlg_h, 190) # horizonal box now has opacity
# call backs
#button_h.action = button_exit_callback
#button_h.action = button_show_ip
# 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()
from nim-iup-examples.
Don't have experience with design, try:
BORDER (creation only): Shows a border around the text. Default: "YES".
In theory dynamic destroy/create of Label control could work, but I haven't tested it or seen examples of it.
from nim-iup-examples.
Its weird , if you put border = "yes" , you can really see it , but if you put to "no" then its just faded but still can see it.
from nim-iup-examples.
For IUP details best bet is to ask on mailing list.
subscribe to mailing list:
https://sourceforge.net/projects/iup/lists/iup-users
or browse mailing list archive:
https://sourceforge.net/p/iup/mailman/iup-users/
https://webserver2.tecgraf.puc-rio.br/iup/en/prod.html#suporte
from nim-iup-examples.
Unable to find a way to remove the border from a textbox , moving on.
from nim-iup-examples.
Related Issues (11)
- How to compile HOT 10
- Try re-creating temp convert using nuip HOT 1
- Example TempConvert.c HOT 1
- GetParam: SIGSEGV: Illegal storage access. (Attempt to read from nil?) HOT 1
- Could not load: iupcontrols.dll HOT 7
- OSX Run Issue: could not load: libiup.dylib HOT 3
- Could you please sync all examples with the latest version of niup? HOT 1
- Error on niupc examples HOT 2
- Error compiling plot.nim HOT 1
- Error compiling example4_2.nim (Illegal access storage) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nim-iup-examples.