-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplugins_nuklear.html
More file actions
749 lines (749 loc) · 56.2 KB
/
Copy pathplugins_nuklear.html
File metadata and controls
749 lines (749 loc) · 56.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | plugins_nuklear</title>
<meta name="description" content="SmallBASIC | One more basic">
<link rel="canonical" href="/plugins_nuklear.html">
<link rel="keywords" href="plugins_nuklear">
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<script src="/clipboard.js"></script>
</head>
<body>
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<script src="/backtotop.js"></script>
<div class="wrapAll clearfix">
<nav class="navigation">
<div class="logo">
<a href="/"><img src='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<div class="navlinks">
<a href="/pages/download.html">Download</a>
<a href="/pages/news.html">News</a>
<a href="/pages/community.html">Community</a>
<a class='active' href="/pages/articles.html">Resources</a>
<a href="/pages/reference.html">Language Reference</a>
<a href="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<div class="mainsection">
<div class="tabs clearfix">
<div class="tabsRight">
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/plugins_nuklear.markdown">Edit</a>
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/plugins_nuklear.markdown">History</a>
</div>
</div>
<div class="article">
<h1 id="nuklear---create-your-own-graphical-user-interface">Nuklear -
Create your own graphical user interface</h1>
<h2 id="about-the-smallbasic-nuklear-plugin">About the SmallBASIC
Nuklear plugin</h2>
<p>Nuklear is a graphical user interface toolkit written in C and
licensed under public domain. It was designed as a simple embeddable
user interface for application. The SmallBASIC Nuklear plugin provides
bindings to the Nuklear library. More information about Nuklear can be
found at Github <a
href="https://github.com/Immediate-Mode-UI/Nuklear">Nuklear</a></p>
<p>The Nuklear plugin is part of the release of SmallBASIC for Windows
and Linux.</p>
<h2 id="using-the-plugin">Using the plugin</h2>
<p>The Nuklear plugin can be used by importing it with
<code>import nuklear</code>. Because Nuklear creates a OpenGL window, it
is not compatible with the SDL or FTKL version of SmallBASIC. Instead it
should be started using the console version of SmallBASIC.</p>
<p>In Linux call:</p>
<p><code>sbasic NuklearTest.bas</code>.</p>
<p>or if you are using the AppImage:</p>
<p><code>SmallBASIC-Console_12.24-x86_64.AppImage NuklearTest.bas</code></p>
<p>If you are working in Windows, then start your program with:</p>
<p><code>sbasic.exe NuklearTest.bas</code></p>
<h2 id="creating-a-window">Creating a window</h2>
<p>The following code shows how to create your first “Hello World”
window.</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480 <span class="co">' Set window size</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk <span class="co">' Import Nuklear plugin</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Hello World"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span> <span class="co">' Create window</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="co">' Render GUI elements and do other useful thinks</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> nk.windowEnd() <span class="co">' Free window</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> nk.waitEvents() <span class="co">' Pause until event</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<p>With <code>nk.windowBegin()</code> a window will be created, if not
already present. Additionally the window content will be clear. After
successfully calling this function, all the GUI elements can be placed
and the responses to user input can be performed. Once
<code>nk.windowEnd()</code> is called, all the elements get rendered.
<code>nk.waitEvents()</code> is used to pause the program until an event
occurs. Without <code>nk.waitEvents()</code> the next iteration of the
while-loop would immediately start.</p>
<h2 id="placing-a-button">Placing a button</h2>
<div class="sourceCode" id="cb2"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>ClickCounter = <span class="dv">0</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Button"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.button(<span class="st">"You clicked me "</span> + ClickCounter + <span class="st">" times"</span>) <span class="kw">then</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> ClickCounter++</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a> nk.windowEnd()</span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> nk.waitEvents()</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<p>Before you can add a button, you have to define a layout which can
hold the GUI elements. This is done with
<code>nk.layoutRow("dynamic", 30, 1)</code>. In this case, a row layout
is created. The width of every row is adapted dynamically to the size of
your window, the height is 30px and one element can be placed per row.
The button is created with <code>nk.button()</code>. If the button is
clicked, the if-statement will be entered. Place all the code inside the
if-statement or call a sub-routine which deals with a pressed
button.</p>
<h2 id="displaying-two-radio-buttons">Displaying two radio buttons</h2>
<div class="sourceCode" id="cb3"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>radio = {value: <span class="st">"A"</span>}</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Radio Buttons"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">90</span>, <span class="dv">2</span>)</span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"Radio Button A"</span>, radio)</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"Radio Button B"</span>, radio)</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">if(</span>radio.value = <span class="st">"A"</span>) <span class="kw">then</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> <span class="co">' Do something useful</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a> nk.windowEnd()</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a> nk.waitEvents()</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<p>The current value of the radio buttons will be stored in
<em>radio.value</em>. The initial value of <em>radio.value</em> is “A”
setting “Radio Button A” active. The if-statement will be entered, when
“Radio Button A” is selected.</p>
<p>Because <code>nk.layoutRow("dynamic", 90, 2)</code> is this time set
to “2” two elements are placed in one row. You can try and set it to
“1”. You will see, that then one radio button per line is displayed.</p>
<h2 id="dynamic-rows-vs.-static-rows">Dynamic rows vs. static rows</h2>
<div class="sourceCode" id="cb4"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>radio = {value: <span class="st">"A"</span>}</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Radio Buttons"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"static"</span>, <span class="dv">90</span>, <span class="dv">310</span>, <span class="dv">2</span>) <span class="co">' fix sized elements</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"Radio Button A"</span>, radio)</span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"Radio Button B"</span>, radio)</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">90</span>, <span class="dv">2</span>) <span class="co">' dynamic sized elements</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"Radio Button C"</span>, radio)</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"Radio Button D"</span>, radio)</span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">if(</span>radio.value = <span class="st">"A"</span>) <span class="kw">then</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a> <span class="co">' Do something useful</span></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a> nk.windowEnd()</span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a> nk.waitEvents()</span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<p>This example is similar to the previous one. But now four radio
buttons, two in one line, are displayed. The first two buttons A and B
are arrange with the row layout “static”. The row has a height of 90px
and a fixed width of 310px. Radio button A and B will each have a fixed
width of 155px. Buttons C and D are arranged using “dynamic” row layout.
The row spans the width of the window at a height of 90px. Button C and
D have a width of 50% each.</p>
<p>If you run this example and change the size of the window with the
mouse, you can see, how the width of the two rows change.</p>
<h2 id="show-input-boxes-with-labels---more-flexible-row-layout">Show
input boxes with labels - More flexible row layout</h2>
<div class="sourceCode" id="cb5"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>FirstName = {value: <span class="st">""</span>}</span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>Surname = {value: <span class="st">""</span>}</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Input box with labels"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> nk.layoutRowBegin(<span class="st">"static"</span>, <span class="dv">25</span>, <span class="dv">2</span>) <span class="co">' Static row -> fixed width</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a> nk.LayoutRowPush(<span class="dv">92</span>) <span class="co">' Next element will have a width of 92px</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a> nk.<span class="kw">label</span>(<span class="st">"First Name:"</span>)</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a> nk.LayoutRowPush(<span class="dv">371</span>) <span class="co">' Next element will have a width of 371px</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a> nk.edit(<span class="st">"field"</span>, FirstName)</span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a> nk.layoutRowEnd()</span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a> nk.layoutRowBegin(<span class="st">"dynamic"</span>, <span class="dv">25</span>, <span class="dv">2</span>) <span class="co">' Dynamic row -> width depends on window size</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a> nk.LayoutRowPush(<span class="dv">0.15</span>) <span class="co">' Next element will have a width of 15%</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a> nk.<span class="kw">label</span>(<span class="st">"Surname:"</span>)</span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a> nk.LayoutRowPush(<span class="dv">0.60</span>) <span class="co">' Next element will have a width of 85%</span></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a> nk.edit(<span class="st">"field"</span>, Surname)</span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a> nk.layoutRowEnd()</span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a> nk.windowEnd()</span>
<span id="cb5-27"><a href="#cb5-27" aria-hidden="true" tabindex="-1"></a> nk.waitEvents()</span>
<span id="cb5-28"><a href="#cb5-28" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<p>A label is created in Nuklear with <code>nk.label("MyLabel")</code>
and a input box with the command
<code>nk.edit("field", EditFieldValue)</code>. The string of the input
box is stored in <em>EditFieldValue.value</em>.</p>
<p>In the example above the width of each element was defined in two
different ways. With <code>nk.layoutRowBegin("static", 25, 2)</code> two
elements per row will be placed. The width of each element is defined in
pixel by the command <code>nk.LayoutRowPush(pixels)</code>. With
<code>nk.layoutRowBegin("dynamic", 25, 2)</code> two elements per row
will be placed. The width of each element is defined in percent by the
command <code>nk.LayoutRowPush(percent)</code>, i.e. 0.15 means 15%.
When you run the above example and change the size of the window with
the mouse, you will see, that the width of the elements in the first
line stays always the same, and in the second line the width is adapted
to the width of the window.</p>
<p>When using <code>nk.layoutRowBegin(...)</code> the end of the
definition for a row has to be marked by
<code>nk.layoutRowEnd()</code>.</p>
<h2 id="display-a-menu">Display a menu</h2>
<p>Caution: <code>menuItem()</code> is not yet working probably. This
will be fixed with the next release.</p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Menu"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> nk.menubarBegin()</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">20</span>, <span class="dv">1</span>)</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.menuBegin(<span class="st">"Menu"</span>, <span class="dt">nil</span>, <span class="dv">100</span>, <span class="dv">80</span>) <span class="kw">then</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">20</span>, <span class="dv">1</span>)</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a> <span class="kw">if(</span>nk.menuItem(<span class="st">"Item A"</span>)) <span class="kw">then</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> <span class="co">' Menu item clicked - do something</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a> <span class="kw">if(</span>nk.menuItem(<span class="st">"Item B"</span>)) <span class="kw">then</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a> <span class="co">' Menu item clicked - do something</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">if(</span>nk.menuItem(<span class="st">"Item C"</span>)) <span class="kw">then</span></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a> <span class="co">' Menu item clicked - do something</span></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a> nk.menuEnd()</span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a> nk.menubarEnd()</span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a> nk.windowEnd()</span>
<span id="cb6-27"><a href="#cb6-27" aria-hidden="true" tabindex="-1"></a> nk.waitEvents()</span>
<span id="cb6-28"><a href="#cb6-28" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<p>The example above will display a menu with one entry called “Menu”.
When clicked, a sub menu is displayed with the entries “Item A”, “Item
B”, “Item C”. The if-statements will be executed, when the corresponding
entry was clicked by the user.</p>
<h3 id="draw-basic-shapes">Draw basic shapes</h3>
<div class="sourceCode" id="cb7"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="pp">option</span> predef grmode <span class="dv">640</span>x480</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="pp">import</span> nuklear <span class="kw">as</span> nk</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a><span class="fu">color</span> <span class="fu">rgb</span>(<span class="dv">128</span>,<span class="dv">54</span>,<span class="dv">0</span>), <span class="dv">1</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.windowBegin(<span class="st">"Draw Example"</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="st">"100%"</span>, <span class="st">"100%"</span>) <span class="kw">then</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> [x, y, w, h] = nk.windowGetBounds()</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> nk.<span class="fu">line</span>(x + <span class="dv">10</span>, y + <span class="dv">40</span>, x + <span class="dv">50</span>, y + <span class="dv">40</span>, x + <span class="dv">50</span>, y + <span class="dv">80</span>)</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> nk.curve(x + <span class="dv">50</span>, y + <span class="dv">80</span>, x + <span class="dv">80</span>, y + <span class="dv">40</span>, x + <span class="dv">100</span>, y + <span class="dv">80</span>, x + <span class="dv">80</span>, y + <span class="dv">80</span>)</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> nk.polygon(<span class="st">"line"</span>, x + <span class="dv">100</span>, y + <span class="dv">150</span>, x + <span class="dv">60</span>, y + <span class="dv">140</span>, x + <span class="dv">70</span>, y + <span class="dv">70</span>)</span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a> nk.<span class="fu">circle</span>(<span class="st">"line"</span>, x + <span class="dv">130</span>, y + <span class="dv">140</span>, <span class="dv">50</span>)</span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> nk.ellipse(<span class="st">"fill"</span>, x + <span class="dv">30</span>, y + <span class="dv">150</span>, <span class="dv">20</span>, <span class="dv">40</span>)</span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a> nk.<span class="fu">arc</span>(<span class="st">"fill"</span>, x + <span class="dv">150</span>, y + <span class="dv">80</span>, <span class="dv">40</span>, <span class="dv">3</span> * <span class="dt">PI</span> / <span class="dv">2</span>, <span class="dv">2</span> * <span class="dt">PI</span>)</span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a> nk.rectMultiColor(x + <span class="dv">95</span>, y + <span class="dv">50</span>, <span class="dv">50</span>, <span class="dv">50</span>, <span class="st">"#ff0000"</span>, <span class="st">"#00ff00"</span>, <span class="st">"#0000ff"</span>, <span class="st">"#000000"</span>)</span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a> nk.text(<span class="st">"DRAW TEXT"</span>, x + <span class="dv">15</span>, y + <span class="dv">75</span>, <span class="dv">100</span>, <span class="dv">100</span>)</span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a> nk.windowEnd()</span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a> nk.waitEvents()</span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span></code></pre></div>
<h2 id="reference-of-supported-commands">Reference of supported
commands</h2>
<h3 id="button">BUTTON</h3>
<blockquote>
<p>Button({Title | Color})</p>
</blockquote>
<p>Title (String): Title of the button<br />
Color (String): Color of the button, i.e. “#ff0000”</p>
<p>Creates a button with a title or filled with a color. Function
returns <em>True</em> or <em>False</em> depending if the button was
clicked.</p>
<h3 id="arc">ARC</h3>
<blockquote>
<p>ARC(x, y, r, start, end)</p>
</blockquote>
<p>x,y: Position of center of the arc<br />
start, end: Start and end angle of the arc</p>
<p>Draws an arc. <em>start</em> and <em>end</em> are first and last
angle in radians.</p>
<h3 id="checkbox">CHECKBOX</h3>
<blockquote>
<p>Checkbox(Name, checkboxValue)</p>
</blockquote>
<p>Name (String): Name of the checkbox<br />
checkboxValue: actual value of the checkbox</p>
<p>Creates a checkbox with the name <em>Name</em>. State of the checkbox
is stored in <em>checkboxValue</em>.</p>
<div class="sourceCode" id="cb8"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>checkA = {value: <span class="dt">false</span>}</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>nk.Checkbox(<span class="st">"Checkbox A"</span>, checkA)</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a><span class="kw">if(</span>checkA.value = <span class="dt">true</span>) <span class="kw">then</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> <span class="co">' Do something</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a><span class="kw">endif</span></span></code></pre></div>
<h3 id="circle">CIRCLE</h3>
<blockquote>
<p>Circle(x, y, r)</p>
</blockquote>
<p>x,y: Position of the circle in pixel<br />
r: radius of the circle in pixel</p>
<p>Draws a circle. See example “Draw basic shapes”.</p>
<h3 id="colorpicker">COLORPICKER</h3>
<blockquote>
<p>Colorpicker(color)</p>
</blockquote>
<p>color: color of the colorpicker</p>
<p>Creates a colorpicker. The color picked by the user is stored in
color.value as a string.</p>
<div class="sourceCode" id="cb9"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>colorPicker = {value: <span class="st">"#ff0000"</span>}</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>nk.colorPicker(colorPicker)</span></code></pre></div>
<h3 id="combobox">COMBOBOX</h3>
<blockquote>
<p>combobox(comboValue)</p>
</blockquote>
<p>comboValue (map): settings of combobox</p>
<p>Creates a combobox. The number of the selected combobox is stored in
<em>comboValue.value</em>.</p>
<div class="sourceCode" id="cb10"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>comboA = {value: <span class="dv">1</span>, items: [<span class="st">"A"</span>, <span class="st">"B"</span>, <span class="st">"C"</span>]}</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>nk.combobox(comboA)</span></code></pre></div>
<h3 id="contextualbegin">CONTEXTUALBEGIN</h3>
<blockquote>
<p>contextualBegin(sizeX, sizeY, triggerX, triggerY, triggerW,
triggerH)</p>
</blockquote>
<p>sizeX, sizeY: Size of the menu<br />
triggerX, triggerY, triggerW, triggerH: Trigger area in pixel</p>
<p>Creates an contextual menu. Right-click in the trigger area will open
a menu.</p>
<div class="sourceCode" id="cb11"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>[x, y, w, h] = nk.widgetBounds()</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="kw">if </span>nk.contextualBegin(<span class="dv">100</span>, <span class="dv">100</span>, x, y, w, h) <span class="kw">then</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> nk.contextualItem(<span class="st">"Item A"</span>)</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> nk.contextualItem(<span class="st">"Item B"</span>)</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> nk.contextualEnd()</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a><span class="kw">endif</span></span></code></pre></div>
<h3 id="contextualend">CONTEXTUALEND</h3>
<blockquote>
<p>contextualEnd()</p>
</blockquote>
<p>Ends the definition of a contextual menu. See
<code>contextualBegin()</code>.</p>
<h3 id="contextualitem">CONTEXTUALITEM</h3>
<blockquote>
<p>contextualItem(Name)</p>
</blockquote>
<p>Name (String): Name of the item</p>
<p>Adds an item to a contextual menu. See
<code>contextualBegin()</code>.</p>
<h3 id="curve">CURVE</h3>
<blockquote>
<p>curve(ax, ay, ctrl0x, ctrl0y, ctrl1x, ctrl1y, bx, by)</p>
</blockquote>
<p>Draws a curve. See “Draw basic shapes”.</p>
<h3 id="edit">EDIT</h3>
<blockquote>
<p>edit(Style, editValue)</p>
</blockquote>
<p>Style (String): “simple”, “field”, “editor”, “box”<br />
editValue: Stores the actual text</p>
<p>Creates an input box. The content of the input box is stored in
<em>editValue.value</em>.</p>
<div class="sourceCode" id="cb12"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>editA = {value: <span class="st">""</span>}</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>nk.edit(<span class="st">"field"</span>, editA)</span></code></pre></div>
<h3 id="ellipse">ELLIPSE</h3>
<blockquote>
<p>ellipse(DrawMode, x, y, rx, ry)</p>
</blockquote>
<p>DrawMode: 0 = line, 1 = solid<br />
x,y: Position in pixel<br />
rx, ry: radii in pixel</p>
<p>Draws an ellipse. See “Draw basic shapes”.</p>
<h3 id="groupbegin">GROUPBEGIN</h3>
<blockquote>
<p>groupBegin(Name, Style)</p>
</blockquote>
<p>Name (String): Name of the goup<br />
Style (String): ““,”border”</p>
<p>Groups several elements. The group can be surrounded by a border.</p>
<div class="sourceCode" id="cb13"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>nk.groupBegin(<span class="st">"Group 1"</span>, <span class="st">"border"</span>)</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> nk.<span class="kw">label</span>(<span class="st">"Radio buttons:"</span>)</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">3</span>)</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"A"</span>, radio)</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"B"</span>, radio)</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> nk.radio(<span class="st">"C"</span>, radio)</span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a> nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a> nk.selectable(<span class="st">"Selectable A"</span>, selectA)</span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a> nk.selectable(<span class="st">"Selectable B"</span>, selectB)</span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a>nk.groupEnd()</span></code></pre></div>
<h3 id="groupend">GROUPEND</h3>
<blockquote>
<p>groupEnd()</p>
</blockquote>
<p>Ends the definition of a group. See <code>groupBegin()</code>.</p>
<h3 id="label">LABEL</h3>
<blockquote>
<p>label(Name [, align, color, “wrap”])</p>
</blockquote>
<p>name (string): name of the label<br />
align (string): “centered”, “right”, “left”<br />
color (string): hex color, i.e “#ff0000”</p>
<p>Creates a label.</p>
<div class="sourceCode" id="cb14"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>nk.<span class="kw">label</span>(<span class="st">"Left label"</span>)</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>nk.<span class="kw">label</span>(<span class="st">"Centered label"</span>, <span class="st">"centered"</span>)</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>nk.<span class="kw">label</span>(<span class="st">"Right label"</span>, <span class="st">"right"</span>)</span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a>nk.<span class="kw">label</span>(<span class="st">"Colored label"</span>, <span class="st">"left"</span>, <span class="st">"#ff0000"</span>)</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a>nk.<span class="kw">label</span>(<span class="st">"A very long wrapped label - The quick brown fox jumps over the ..."</span>, <span class="st">"right"</span>, <span class="st">"wrap"</span>)</span></code></pre></div>
<h3 id="layoutrow">LAYOUTROW</h3>
<blockquote>
<p>layoutRow(“dynamic”, height, numberOfElements)</p>
</blockquote>
<blockquote>
<p>layoutRow(“static”, height, width, numberOfElements)</p>
</blockquote>
<p>height: height of the element in pixel<br />
numberOfElements: number of elements in a row<br />
width: width of an element in pixel</p>
<p>Creates a dynamic or static row. See “Dynamic rows vs. static
rows”</p>
<h3 id="layoutrowpush">LAYOUTROWPUSH</h3>
<blockquote>
<p>layoutRowPush(width)</p>
</blockquote>
<p>width: width of the element in pixel</p>
<p>Next element will have the width <em>width</em>. Use in combination
with <code>layoutRowBegin()</code>. If row layout is “static”, then
<em>width</em> is in pixel. If row layout is “dynamic” <em>width</em> is
in percent, i.e. 0.15 means 15%. See “Show input boxes with labels -
More flexible row layout”.</p>
<h3 id="layoutrowbegin">LAYOUTROWBEGIN</h3>
<blockquote>
<p>layoutRowBegin({“static” | “dynamic”}, height, numberOfElements)</p>
</blockquote>
<p>height: height of the element in pixel<br />
numberOfElements: number of elements in a row</p>
<p>Starts a layout section were several elements per row can have
different width. Use in combination with <code>layoutRowPush()</code>.
See “Show input boxes with labels - More flexible row layout”.</p>
<h3 id="layoutrowend">LAYOUTROWEND</h3>
<blockquote>
<p>layoutRowEnd()</p>
</blockquote>
<p>Ends a layout section which was started with
<code>layoutRowBegin()</code>. See “Show input boxes with labels - More
flexible row layout”.</p>
<h3 id="line">LINE</h3>
<blockquote>
<p>line(x1, y1, x2, y2 [, … , x40, y40])</p>
</blockquote>
<p>x,y: coordinate pairs of the line segments.</p>
<p>Draws a polyline. See “Draw basic shapes”.</p>
<h3 id="menubarbegin">MENUBARBEGIN</h3>
<blockquote>
<p>menuBarBegin()</p>
</blockquote>
<p>Starts the definition of a menu. See example “Display a menu”.</p>
<h3 id="menubarend">MENUBAREND</h3>
<blockquote>
<p>menuBarEnd()</p>
</blockquote>
<p>Ends the definition of a menu. See example “Display a menu”.</p>
<h3 id="menubegin">MENUBEGIN</h3>
<blockquote>
<p>clicked = menuBegin(entry, nil, height, width)</p>
</blockquote>
<p>entry (String): name of the menu-entry<br />
height: height of the submenu in pixel<br />
width: width of the submenu in pixel<br />
nil: unused at the moment, set alway to nil<br />
clicked: returns true if item was clicked, otherwise false</p>
<p>Insert a menu entry. See example “Display a menu”.</p>
<h3 id="menuend">MENUEND</h3>
<blockquote>
<p>menuEnd()</p>
</blockquote>
<p>Ends a menu entry. See example “Display a menu”.</p>
<h3 id="menuitem">MENUITEM</h3>
<blockquote>
<p>clicked = menuItem(name)</p>
</blockquote>
<p>name (String): Name of a submenu item<br />
clicked: returns true if item was clicked, otherwise false</p>
<p>Creates a submenu entry. See example “Display a menu”.</p>
<h3 id="polygon">POLYGON</h3>
<blockquote>
<p>polygon(drawMode, x, y [x2, y2, …, x40, y40])</p>
</blockquote>
<p>drawMode: 0 = line, 1 = solid<br />
x,y: coordinate pairs of the line segments</p>
<p>Draws a polygon. See example “Drawing basic shapes”</p>
<h3 id="progress">PROGRESS</h3>
<blockquote>
<p>progress(progressValue, maxValue [, modifiable])</p>
</blockquote>
<p>progressValue: the actual progress value<br />
maxValue: Maximum progress value<br />
modifiable: true or false (default: false)</p>
<p>Displays a progress bar. The length of the bar is given by
<em>progressValue.value</em>. Set <em>modifiable</em> to true, if you
want to use the progress bar as a slider to change the value.</p>
<div class="sourceCode" id="cb15"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>progress.value = <span class="dv">5</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>nk.progress(progress, <span class="dv">10</span>, <span class="dt">false</span>)</span></code></pre></div>
<h3 id="property">PROPERTY</h3>
<blockquote>
<p>property(name, minValue, propertyValue, maxValue, stepSizeByClick,
stepSizeByMoving)</p>
</blockquote>
<p>name (String): Name of the input box<br />
minValue: Minimum value<br />
propertyValue: Value for storing the actual value<br />
maxValue: Maximum value<br />
stepSizeByClick: Stepsize when clicked with the mouse<br />
stepSizeByMoving: Stepsize when click + hold + moving the mouse</p>
<p>Displays an input box for numbers. The actual value is stored in
<em>propertyValue.value</em>.</p>
<div class="sourceCode" id="cb16"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>property = {value: <span class="dv">6</span>}</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>nk.property(<span class="st">"Property"</span>, <span class="dv">1</span>, property, <span class="dv">10</span>, <span class="dv">0.25</span>, <span class="dv">0.5</span>)</span></code></pre></div>
<h3 id="radio">RADIO</h3>
<blockquote>
<p>radio(Name, radioValue)</p>
</blockquote>
<p>Name (String): Name of the radio button<br />
radioValue: actual value of the radio button</p>
<p>Displays a radio button. The value is stored in _radioValue.value.
See example “Displaying two radio buttons”</p>
<h3 id="rectmulticolor">RECTMULTICOLOR</h3>
<blockquote>
<p>rectMultiColor(x, y, width, height, color1, color2, color3,
color4)</p>
</blockquote>
<p>x,y: Position of the rectangle in pixel<br />
width, height: Width and height in pixel<br />
color1 to color4 (string): hex color of the for corners of the
rectangle</p>
<p>Displays a rectangle with smooth color blending. See example “Draw
basic shapes”</p>
<h3 id="selectable">SELECTABLE</h3>
<blockquote>
<p>selectable(Name, selectValue)</p>
</blockquote>
<p>Name (String): Name of the item<br />
selectValue: value of the item</p>
<p>Creates a list of items, which can be selected similar to a checkbox.
The actual value of the selectable is stored in
<em>selectValue.value</em></p>
<div class="sourceCode" id="cb17"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>selectA = {value: <span class="dt">false</span>}</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>selectB = {value: <span class="dt">true</span>}</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>nk.selectable(<span class="st">"Selectable A"</span>, selectA)</span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a>nk.selectable(<span class="st">"Selectable B"</span>, selectB)</span></code></pre></div>
<h3 id="slider">SLIDER</h3>
<blockquote>
<p>slider(minValue, sliderValue, maxValue, stepSize)</p>
</blockquote>
<p>minValue: minimum value of the slider<br />
sliderValue: actual value if the slider<br />
maxValue: maximum value of the slider<br />
stepSize: step size of the slider when moving with the mouse</p>
<p>Displays a slider. The slider position is given by
<em>sliderValue.value</em></p>
<div class="sourceCode" id="cb18"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>sliderValue = {value: <span class="dv">5</span>}</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>nk.slider(<span class="dv">1</span>, sliderValue, <span class="dv">10</span>, <span class="dv">.5</span>)</span></code></pre></div>
<h3 id="spacing">SPACING</h3>
<blockquote>
<p>spacing(numberOfRows)</p>
</blockquote>
<p>numberOfRows: height in rows of the element</p>
<p>Adds an empty element. Use to define spacings between elements.</p>
<h3 id="text">TEXT</h3>
<blockquote>
<p>text(text, x, y, width, height)</p>
</blockquote>
<p>text (String): text<br />
x,y: position in pixel<br />
width: width of the text element<br />
height: height of the element</p>
<p>Prints text. See example “Drawing basic shapes”</p>
<h3 id="textinput">TEXTINPUT</h3>
<p>not supported yet. Use <code>edit()</code>.</p>
<h3 id="tooltip">TOOLTIP</h3>
<blockquote>
<p>tooltip(TooltipValue)</p>
</blockquote>
<p>TooltipValue (String): Text of the tooltip</p>
<p>Prints a tooltip.</p>
<div class="sourceCode" id="cb19"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>edit = {value: <span class="st">"Edit text"</span>}</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a>nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a><span class="kw">if </span>nk.widgetIsHovered() <span class="kw">then</span></span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a> nk.tooltip(<span class="st">"Test tooltip"</span>)</span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a><span class="kw">endif</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a>k.edit(<span class="st">"box"</span>, edit)</span></code></pre></div>
<h3 id="treepop">TREEPOP</h3>
<blockquote>
<p>treePop()</p>
</blockquote>
<p>Adds an element to a tree. See command <code>treePush()</code></p>
<h3 id="treepush">TREEPUSH</h3>
<blockquote>
<p>treePush(type, name)</p>
</blockquote>
<p>type (String): type of tree element (“tab” or “node”)<br />
name (String): name of tree element</p>
<p>Creates a tree.</p>
<div class="sourceCode" id="cb20"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="kw">if </span>nk.treePush(<span class="st">"tab"</span>, <span class="st">"Tree Tab"</span>) <span class="kw">then</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.treePush(<span class="st">"node"</span>, <span class="st">"Tree Node 1"</span>) <span class="kw">then</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> nk.<span class="kw">label</span>(<span class="st">"Label 1"</span>)</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> nk.treePop()</span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>nk.treePush(<span class="st">"node"</span>, <span class="st">"Tree Node 2"</span>) <span class="kw">then</span></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a> nk.<span class="kw">label</span>(<span class="st">"Label 2"</span>)</span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a> nk.treePop()</span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a> nk.treePop()</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a><span class="kw">endif</span></span></code></pre></div>
<h3 id="windowend">WINDOWEND</h3>
<blockquote>
<p>windowEnd()</p>
</blockquote>
<p>Ends the rendering of a window.</p>
<h3 id="linewidth">LINEWIDTH</h3>
<blockquote>
<p>lineWidth(width)</p>
</blockquote>
<p>width: width of the line.</p>
<p>Sets the line width.</p>
<h3 id="pollevents">POLLEVENTS</h3>
<blockquote>
<p>pollEvents()</p>
</blockquote>
<p>Polls events.</p>
<h3 id="waitevents">WAITEVENTS</h3>
<blockquote>
<p>waitEvents([millis])</p>
</blockquote>
<p>millis (optional): wait milliseconds</p>
<p>Pause the program execution until an event occurs. If <em>millis</em>
is set, wait <em>millis</em> milliseconds.</p>
<h3 id="swapbuffers">SWAPBUFFERS</h3>
<blockquote>
<p>swapBuffers()</p>
</blockquote>
<p>Swap drawing buffers.</p>
<h3 id="widgetbounds">WIDGETBOUNDS</h3>
<blockquote>
<p>[x, y, w, h] = widgetBounds()</p>
</blockquote>
<p>x,y: position of the widget<br />
w,h: width and height of the widget</p>
<p>Returns the position and the dimensions of a widget.</p>
<div class="sourceCode" id="cb21"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>edit = {value: <span class="st">"Edit text"</span>}</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>nk.layoutRow(<span class="st">"dynamic"</span>, <span class="dv">30</span>, <span class="dv">1</span>)</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>[x, y, w, h] = nk.widgetBounds()</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>k.edit(<span class="st">"box"</span>, edit)</span></code></pre></div>
<h3 id="widgetishovered">WIDGETISHOVERED</h3>
<blockquote>
<p>result = widgetIsHovered()</p>
</blockquote>
<p>result: true or false</p>
<p>Returns true, if a widget is hovered. See command
<code>tooltip()</code>.</p>
<h3 id="windowbegin">WINDOWBEGIN</h3>
<blockquote>
<p>windowBegin(Name, x, y, w, h [,flag1, …])</p>
</blockquote>
<p>Name (String): Name of the window<br />
x, y: Position of the rendered area inside the window in pixel<br />
w, h: Dimension of the rendered area<br />
flag1 to flag8 (String): Window flags</p>
<p>Creates a window and starts rendering. w and h can be given in
different ways:</p>
<ul>
<li>“400” -> in pixel</li>
<li>“50%” -> 50% of the window</li>
<li>“100% - 10” -> 100% of the window minus 10 pixel</li>
</ul>
<p>Flags can be: “border”, “movable”, “scalable”, “closable”,
“minimizable”, “no_scrollbar”, “title”, “scroll_auto_hide”,
“background”, “scale_left”, “no_input”.</p>
<h3 id="windowgetbounds">WINDOWGETBOUNDS</h3>
<blockquote>
<p>[x, y, w, h] = windowGetBounds()</p>
</blockquote>
<p>x,y: position of the rendered area<br />
w,h: width and height of the rendered area</p>
<p>Returns the position and the dimensions of the rendered area within
the window.</p>
</div>
<div class="pagefooter">
This page was last edited on Sat, 9 Sep 2023 22:31:16 +0200
|
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>