Simple windowed application: Difference between revisions
Content added Content deleted
m (BaCon and BBC BASIC moved to the BASIC section.) |
mNo edit summary |
||
Line 3,782: | Line 3,782: | ||
Me.Caption = clicked & " clicks." |
Me.Caption = clicked & " clicks." |
||
End Sub |
End Sub |
||
</syntaxhighlight> |
|||
=={{header|V (Vlang)}}== |
|||
<syntaxhighlight lang="Zig"> |
|||
import ui |
|||
import gx |
|||
[heap] |
|||
struct App { |
|||
mut: |
|||
window &ui.Window = unsafe {nil} |
|||
counter string = "0" // will contain number count |
|||
} |
|||
fn main() { |
|||
mut app := &App{} |
|||
app.window = ui.window( |
|||
width: 200 |
|||
height: 40 |
|||
title: "Counter" |
|||
mode: .resizable |
|||
layout: ui.row( |
|||
spacing: 5 |
|||
margin_: 10 |
|||
widths: ui.stretch |
|||
heights: ui.stretch |
|||
children: [ |
|||
ui.label( |
|||
id: "num" |
|||
text: &app.counter //refer to struct App |
|||
), |
|||
ui.button( |
|||
text: "Count" |
|||
bg_color: gx.light_gray |
|||
radius: 5 |
|||
border_color: gx.gray |
|||
on_click: app.btn_click //refer to function below |
|||
), |
|||
] |
|||
) |
|||
) |
|||
ui.run(app.window) |
|||
} |
|||
fn (mut app App) btn_click(btn &ui.Button) { |
|||
mut lbl := app.window.get_or_panic[ui.Label]("num") //"num" is id of label |
|||
app.counter = (app.counter.int() + 1).str() //change to string for label display |
|||
lbl.set_text(app.counter) |
|||
} |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||