Skip to content

Commit 7b7aeb3

Browse files
committed
examples: Add IUP text box example
1 parent fe484f4 commit 7b7aeb3

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

examples/GUI/IUP/textbox.bas

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include once "IUP/iup.bi"
2+
const NULL = 0
3+
const NEWLINE = !"\n"
4+
5+
function on_click_ok cdecl(byval handler as Ihandle ptr) as long
6+
var dialog = IupGetHandle("dialog")
7+
var textbox = IupGetHandle("textbox")
8+
var label = IupGetHandle("label")
9+
10+
var text = *IupGetAttribute(textbox, IUP_VALUE)
11+
12+
print "OK clicked! content of textbox: <" + text + ">"
13+
14+
IupSetAttribute(label, IUP_TITLE, _
15+
"Thanks. You entered <" + text + ">." + NEWLINE + _
16+
"val() result: " & val(text) & ". " + NEWLINE + _
17+
"IupGetInt() result: " & IupGetInt(textbox, IUP_VALUE) & "." + NEWLINE + _
18+
"IupGetFloat() result: " & IupGetFloat(textbox, IUP_VALUE) & "." _
19+
)
20+
21+
'' Recalculate the window layout. Since we changed the label text, it
22+
'' may require more space. This may require us to even increase the
23+
'' entire dialog's size to make room for the bigger label. According to
24+
'' IUP documentation doing this requires setting the SIZE attribute of
25+
'' the dialog, then call IupRefresh() on it. I'm not 100% sure whether
26+
'' this is the right/best way to do it.
27+
IupSetAttribute(dialog, IUP_SIZE, NULL)
28+
IupRefresh(dialog)
29+
30+
function = IUP_DEFAULT
31+
end function
32+
33+
IupOpen(NULL, NULL)
34+
35+
'' Create a window with a text box, ok button, and a label
36+
var textbox = IupText(NULL)
37+
var okbutton = IupButton("OK", "on_click_ok")
38+
var label = IupLabel("Hello! Enter some text and click OK.")
39+
var vbox = IupVbox(textbox, okbutton, label, NULL)
40+
var dialog = IupDialog(vbox)
41+
42+
'' Window title
43+
IupSetAttribute(dialog, IUP_TITLE, "Text box example")
44+
45+
'' Make text box accept numbers only (instead of arbitrary text)
46+
'' According to the IUP documentation, the IupText() control accepts a FILTER
47+
'' attribute on Windows, which can have the values LOWERCASE, UPPERCASE or NUMBER.
48+
'' Thus FLOAT does not seem to be valid!?
49+
'IupSetAttribute(textbox, IUP_FILTER, "FLOAT")
50+
'' However, NUMBER does not disallow letters to be entered on Windows XP either...
51+
'IupSetAttribute(textbox, IUP_FILTER, "NUMBER")
52+
53+
'' Adjust layout a little bit
54+
IupSetAttribute(textbox, IUP_EXPAND, "YES")
55+
IupSetAttribute(okbutton, IUP_EXPAND, "YES")
56+
IupSetAttribute(label, IUP_EXPAND, "YES")
57+
IupSetAttribute(vbox, IUP_GAP, "4")
58+
IupSetAttribute(vbox, IUP_ALIGNMENT, "ACENTER")
59+
IupSetAttribute(vbox, IUP_MARGIN, "4x4")
60+
61+
'' Set callbacks and handles
62+
IupSetFunction("on_click_ok", @on_click_ok)
63+
IupSetHandle("dialog", dialog)
64+
IupSetHandle("textbox", textbox)
65+
IupSetHandle("label", label)
66+
67+
'' Show window and run main loop
68+
IupShow(dialog)
69+
IupMainLoop()
70+
IupClose()

0 commit comments

Comments
 (0)