GUI component interaction: Difference between revisions

m
imported>Arakov
imported>Arakov
 
(3 intermediate revisions by 2 users not shown)
Line 896:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import forms;
import extensions;
Line 914:
self
.appendControl:(btmIncrement)
.appendControl:(btmRandom)
.appendControl:(txtNumber);
 
self.Caption := "Rosseta Code";
Line 953:
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>
 
Line 3,150 ⟶ 3,092:
end</syntaxhighlight>
[[File:GuiComponentRunBasic.png]]
 
== {{Header|Rust}} ==
{{libheader|egui}}
</Form></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);
number := number + 1});
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,634 ⟶ 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