GUI enabling/disabling of controls: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(7 intermediate revisions by 3 users not shown)
Line 269:
; Ensures the script ends when the GUI is closed.</syntaxhighlight>
 
=={{header|BaConBASIC}}==
==={{header|BaCon}}===
This code requires BaCon 4.0.1 or higher.
<syntaxhighlight lang="bacon">OPTION GUI TRUE
Line 306 ⟶ 307:
WEND</syntaxhighlight>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"WINLIB2"
Line 790 ⟶ 791:
End
</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_inputFld
_incBtn
_decBtn
end enum
 
void local fn BuildWindow
window _window, @"GUI enabling/disabling of controls", (0,0,350,150), NSWindowStyleMaskTitled
textfield _inputFld,, @"0", (160,78,30,21)
ControlSetAlignment( _inputFld, NSTextAlignmentCenter )
button _incBtn,,, @"Increment", (75,43,101,32)
button _decBtn, NO,, @"Decrement", (174,43,101,32)
end fn
 
void local fn InputAction
long value = fn ControlIntegerValue( _inputFld )
if ( value < 0 or value > 10 ) then value = 0
textfield _inputFld,, str(value)
select ( value )
case 0
TextFieldSetEditable( _inputFld, YES )
button _incBtn, YES
button _decBtn, NO
case 10
TextFieldSetEditable( _inputFld, NO )
WindowMakeFirstResponder( _window, 0 )
button _incBtn, NO
button _decBtn, YES
case else
TextFieldSetEditable( _inputFld, NO )
WindowMakeFirstResponder( _window, 0 )
button _incBtn, YES
button _decBtn, YES
end select
end fn
 
void local fn IncrementAction
long value = fn ControlIntegerValue( _inputFld ) + 1
textfield _inputFld,, str(value)
TextFieldSetEditable( _inputFld, NO )
WindowMakeFirstResponder( _window, 0 )
if ( value >= 10 ) then button _incBtn, NO
if ( value > 0 ) then button _decBtn, YES
end fn
 
void local fn DecrementAction
long value = fn ControlIntegerValue( _inputFld ) - 1
textfield _inputFld,, str(value)
if ( value < 10 ) then button _incBtn, YES
if ( value == 0 )
button _decBtn, NO
TextFieldSetEditable( _inputFld, YES )
end if
end fn
 
void local fn DoDialog( ev as long, tag as long )
select ( ev )
case _btnClick
select ( tag )
case _inputFld : fn InputAction
case _incBtn : fn IncrementAction
case _decBtn : fn DecrementAction
end select
end select
end fn
 
fn BuildWindow
 
on dialog fn DoDialog
 
HandleEvents
</syntaxhighlight>
[[File:GUIEnableDisableControls350FB.png]]
 
=={{header|Gambas}}==
Line 2,906 ⟶ 2,995:
End Select
End Sub</syntaxhighlight>
 
=={{header|V (Vlang)}}==
Graphical
 
Notes:
 
1) "v install ui" to get, also to locally check source and examples.
 
2) For alternative UI toolkits, check github.com/vlang/awesome-v (Awesome V).
 
<syntaxhighlight lang="Zig">
import ui
import gx
 
const (
win_width = 400
win_height = 40
)
 
[heap]
struct App {
mut:
window &ui.Window = unsafe {nil}
counter string = "0"
}
 
fn main() {
mut app := &App{}
app.window = ui.window(
width: win_width
height: win_height
title: "Counter"
mode: .resizable
layout: ui.row(
spacing: 5
margin_: 10
widths: ui.stretch
heights: ui.stretch
children: [
ui.textbox(
max_len: 20
read_only: false
is_numeric: true
text: &app.counter
),
ui.button(
text: "increment"
bg_color: gx.light_gray
radius: 5
border_color: gx.gray
on_click: app.btn_click_inc
),
ui.button(
text: "decrement"
bg_color: gx.light_gray
radius: 5
border_color: gx.gray
on_click: app.btn_click_dec
),
]
)
)
ui.run(app.window)
}
 
fn (mut app App) btn_click_inc(mut btn ui.Button) {
if app.counter.int() > 10 {
btn.disabled = true
return
}
app.counter = (app.counter.int() + 1).str()
}
 
fn (mut app App) btn_click_dec(mut btn ui.Button) {
if app.counter.int() < 0 {
btn.disabled = true
return
}
app.counter = (app.counter.int() - 1).str()
}
</syntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-polygon}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "input" for Mouse, Keyboard
import "dome" for Window
9,482

edits