-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path04-marked-scale.raku
executable file
·84 lines (68 loc) · 2.84 KB
/
04-marked-scale.raku
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
#!/usr/bin/env perl6
use v6;
use lib 'lib';
use GTK::Simple;
use GTK::Simple::App;
my GTK::Simple::App $app .=new( :title( 'More widgets') );
=comment
We introduce the MarkUpLabel and Scale widgets
my %texts = <blue red> Z=>
'<span foreground="blue" size="x-large">Blue text</span> is <i>cool</i>!',
'<span foreground="red" size="x-large">Red text</span> is <b>hot</b>!'
;
my $mx = 30;
my $mn = 2.5;
$app.set-content(
GTK::Simple::VBox.new(
GTK::Simple::HBox.new(
my $inner = GTK::Simple::VBox.new(
my $normal-label = GTK::Simple::Label.new(:text("Normal label: %texts<blue>" ) ),
=comment
a vanilla label shows up the mark up text as text
my $marked-label = GTK::Simple::MarkUpLabel.new(:text("Label with markup: %texts<blue>") ),
=comment
a MarkUpLabel is almost the same as a vanilla Label, but it renders the Pango markup.
See https://developer.gnome.org/pango/unstable/PangoMarkupFormat.html for more information
my $bR = GTK::Simple::CheckButton.new(:label('Make Red')),
my $bB = GTK::Simple::ToggleButton.new(:label('Make Blue')),
my $bSyn = GTK::Simple::ToggleButton.new(:label('Synchronise')),
my $label-for-vertical = GTK::Simple::MarkUpLabel.new(:text('Vertical scale value is:')),
my $label-for-horizontal = GTK::Simple::MarkUpLabel.new(:text('Horizontal scale value is:')),
),
my $scale-vertical = GTK::Simple::Scale.new(:orientation<vertical>, :max($mx), :min($mn), :step(0.5), :value(21) ),
=comment
A scale widget is used to provide a numerical value
Here is the vertical form. The maximum value is at the top.
),
my $scale-horizontal = GTK::Simple::Scale.new()
=comment
The default GTK::Simple::Scale behavior is horizontal orientation, with :min(0) :max(1) :step(0.1) :value(0.5)
)
);
sub make-blue($b) {
$normal-label.text = "Normal label: %texts<blue>";
$marked-label.text = "Label with markup: %texts<blue>";
}
sub make-red($b) {
$normal-label.text = "Normal label: %texts<red>";
$marked-label.text = "Label with markup: %texts<red>";
}
sub vertical-changes($b) {
$label-for-vertical.text = 'Number is <span foreground="green" size="large">' ~ $scale-vertical.value ~'</span>';
}
sub horizontal-changes($b) {
$label-for-horizontal.text = 'Number is <span foreground="green" size="large">' ~ $scale-horizontal.value ~'</span>';
}
sub sync($b) {
$scale-vertical.adjust: $mn + $scale-horizontal.value * ($mx-$mn)
}
$bB.toggled.tap: &make-blue;
$bR.toggled.tap: &make-red;
$bSyn.toggled.tap: &sync;
$scale-vertical.value-changed.tap: &vertical-changes;
=comment
Note the call-back name is value-changed, not changed for a text entry
$scale-horizontal.value-changed.tap: &horizontal-changes;
$inner.border-width = 20;
$app.border-width = 20;
$app.run;