GUI component interaction: Difference between revisions

m
imported>Arakov
 
(5 intermediate revisions by 4 users not shown)
Line 13:
{{omit from|Lotus 123}}
{{omit from|Maxima}}
{{omit from|Minimal BASIC|It does not handle GUI}}
{{omit from|Nascom BASIC|It does not handle GUI}}
{{omit from|PARI/GP}}
{{omit from|PostScript}}
{{omit from|Retro}}
{{omit from|SQL PL|It does not handle GUI}}
{{omit from|Tiny BASIC|It does not handle GUI}}
 
{{omit from|Palo Alto Tiny BASIC|It does not handle GUI}}
 
Almost every application needs to communicate with the user in some way.
Line 332 ⟶ 335:
; a timer.</syntaxhighlight>
 
=={{header|BaConBASIC}}==
==={{header|BaCon}}===
Requires BaCon version 4.0.1 or higher, using GTK3.
<syntaxhighlight lang="bacon">OPTION GUI TRUE
Line 371 ⟶ 375:
WEND</syntaxhighlight>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"WINLIB2"
Line 892 ⟶ 896:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import forms;
import extensions;
Line 898 ⟶ 902:
public class MainWindow : SDIDialog
{
Button btmIncrement;
Button btmRandom;
Edit txtNumber;
constructor new()
<= super new()
{
btmIncrement := Button.new();
btmRandom := Button.new();
txtNumber := Edit.new();
self
.appendControl:(btmIncrement)
.appendControl:(btmRandom)
.appendControl:(txtNumber);
 
self.Caption := "Rosseta Code";
self.setRegion(100, 100, 160180, 120140);
txtNumber.setRegion(720, 7, 140, 25);
txtNumber.Caption := "0";
btmIncrement.setRegion(720, 35, 140, 25);
btmIncrement.Caption := "Increment";
btmIncrement.onClick := (args){ self.onButtonIncrementClick() };
btmRandom.setRegion(720, 65, 140, 25);
btmRandom.Caption := "Random";
btmRandom.onClick := (args){ self.onButtonRandomClick() };
}
private onButtonIncrementClick()
{
var number := txtNumber.Value.toInt();
number := number + 1;
self.changeTextBoxValue(number)
}
private onButtonRandomClick()
{
if(messageDialog.showQuestion("Inf", "Really reset to random value?"))
{
self.changeTextBoxValue(randomGenerator.evalnextInt(99999999))
}
}
private changeTextBoxValue(number)
{
txtNumber.Caption := number.toString()
}
}</syntaxhighlight>
 
=== Alternative version using xforms script ===
 
form layout:
<syntaxhighlight lang="elena"><Form X="100" Y="100" Width="160" Height="120" Caption="Rosseta Code">
<Edit ID="txtNumber" X="7" Y="7" Width="140" Height="25" Caption="0">
</Edit>
<Button ID="btmIncrement" X="7" Y="35" Width="140" Height="25" Caption="Increment" onClick="onButtonIncrementClick">
</Button>
<Button ID="btmRandom" X="7" Y="65" Width="140" Height="25" Caption="Random" onClick="onButtonRandomClick">
</Button>
</Form></syntaxhighlight>
 
main code:
<syntaxhighlight lang="elena">import xforms;
import forms;
import extensions;
public class MainWindow
{
SDIForm form;
Button btmIncrement;
Button btmRandom;
Edit txtNumber;
constructor new()
{
form := xforms.executePath("main.xs", self);
btmIncrement := form.Controls.btmIncrement;
btmRandom := form.Controls.btmRandom;
txtNumber := form.Controls.txtNumber;
}
onButtonIncrementClick(sender)
{
var number := txtNumber.Value.toInt();
number := number + 1;
self.changeTextBoxValue(number)
}
onButtonRandomClick(sender)
{
if(messageDialog.showQuestion("Inf", "Really reset to random value?"))
{
self.changeTextBoxValue(randomGenerator.eval(99999999))
}
}
private changeTextBoxValue(number)
{
txtNumber.Caption := number.toString()
}
dispatch() => form;
}</syntaxhighlight>
 
 
=={{header|Euphoria}}==
Line 3,147 ⟶ 3,092:
end</syntaxhighlight>
[[File:GuiComponentRunBasic.png]]
 
== {{Header|Rust}} ==
{{libheader|egui}}
<syntaxhighlight lang="rust">
use eframe::egui;
use rand::Rng;
 
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(214.0, 100.0)),
..Default::default()
};
 
// Our application state:
let mut value = "0".to_owned();
 
eframe::run_simple_native("GUI component interaction", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
let name_label = ui.label("Value: ");
ui.text_edit_singleline(&mut value)
.labelled_by(name_label.id);
});
ui.horizontal(|ui| {
if ui.button("Increment").clicked() {
if let Ok(v) = value.parse::<usize>() {
value = (v + 1).to_string()
}
}
if ui.button("Random").clicked() {
value = (rand::thread_rng().gen_range(1..=10000)).to_string();
}
});
});
})
}</syntaxhighlight>
[[File:Rust GUI component interaction.png|none|thumb]]
 
=={{header|Scala}}==
Line 3,631 ⟶ 3,613:
{{libheader|DOME}}
{{libheader|Wren-polygon}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "input" for Mouse, Keyboard
import "dome" for Window
Anonymous user