GtkSimpleLayout 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/example/auto_event_map.rb +1 -1
- data/example/basic.rb +1 -1
- data/example/calculator.rb +9 -9
- data/example/composit.rb +28 -0
- data/example/expose_components.rb +1 -1
- data/example/group.rb +1 -1
- data/example/hello_world.rb +1 -1
- data/example/menu.rb +1 -1
- data/example/multiple_layouts.rb +59 -0
- data/example/serial_port_setup.rb +1 -1
- data/example/with_attr.rb +1 -1
- data/lib/simple_layout.rb +54 -42
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b44cf7d7f21d27bd3f547c892caa0f06bc69e74d1ce95b8124bfc9670010561e
|
4
|
+
data.tar.gz: f4d0ac95c666ebc40fe3110f19acd3ea27c9733e32035a5bf2cdce8b1e7b25db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e4f694291ac3410341d7ce2fe77d29c3f744e108d07b55d0233d6627de0b3c35d4dc37a2036c57364934fe136397add63a5f6a1b342ff1053c5ed6221b0a8db
|
7
|
+
data.tar.gz: b3fe6690ae04f128c7a4beccb70d7547b5dc7214c998261c178a9bedb6f44eaca045fb2176117f081957e840d1b1bc0090fd41479ddf0822f4fa941411efb8ce
|
data/example/auto_event_map.rb
CHANGED
data/example/basic.rb
CHANGED
data/example/calculator.rb
CHANGED
@@ -6,30 +6,30 @@ class MyWin < Gtk::Window
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
super
|
9
|
-
my_layout
|
9
|
+
add my_layout()
|
10
10
|
signal_connect('destroy') do
|
11
11
|
Gtk.main_quit
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def my_layout
|
16
|
-
|
16
|
+
_vbox do
|
17
17
|
with_attr :border_width => 3 do
|
18
|
-
|
18
|
+
_hbox do
|
19
19
|
_entry :id => :ent_input, :layout => [true, true, 5]
|
20
20
|
end
|
21
|
-
|
21
|
+
_hbox do
|
22
22
|
_frame do
|
23
23
|
_label 'M', :set_size_request => [20, 20]
|
24
24
|
end
|
25
|
-
|
25
|
+
_hbutton_box do
|
26
26
|
_button 'Backspace'
|
27
27
|
_button 'CE'
|
28
28
|
_button 'C'
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
|
31
|
+
_hbox do
|
32
|
+
_vbutton_box do
|
33
33
|
_button 'MC'
|
34
34
|
_button 'MR'
|
35
35
|
_button 'MS'
|
@@ -44,12 +44,12 @@ class MyWin < Gtk::Window
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def number_and_operators_layout
|
47
|
-
|
47
|
+
_vbox do
|
48
48
|
[ ['7', '8', '9', '/', 'sqt'],
|
49
49
|
['4', '5', '6', '*', '%'],
|
50
50
|
['1', '2', '3', '-', '1/x'],
|
51
51
|
['0', '+/-', '.', '+', '=']].each do |cols|
|
52
|
-
|
52
|
+
_hbox :layout => [true, true] do
|
53
53
|
cols.each do |txt|
|
54
54
|
_button txt, :id => txt.to_sym, :set_size_request => [30, 30], :layout => [true, true]
|
55
55
|
end
|
data/example/composit.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'gtk3'
|
2
|
+
require 'simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
add my_layout()
|
9
|
+
signal_connect('destroy') do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_layout
|
15
|
+
_vbox_in_hbox inner_layout: [padding: 10] do
|
16
|
+
with_attr :border_width => 5 do
|
17
|
+
_frame layout: [padding: 10] do
|
18
|
+
_label_in_vbox 'Label 1', inner_layout: [padding: 10]
|
19
|
+
end
|
20
|
+
_button 'Button 1'
|
21
|
+
_entry_in_vbox :id => :ent_input
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
MyWin.new.show_all
|
28
|
+
Gtk.main
|
data/example/group.rb
CHANGED
data/example/hello_world.rb
CHANGED
data/example/menu.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'gtk3'
|
2
|
+
require 'simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
vbox = Gtk::Box.new(:vertical, 5)
|
9
|
+
vbox.pack_start(Gtk::Label.new('Multiple Layouts'), expand: false, fill: false, padding: 10)
|
10
|
+
vbox.pack_start(my_layout1(), expand: true, fill: true, padding: 0)
|
11
|
+
vbox.pack_start(my_layout2(), expand: true, fill: true, padding: 0)
|
12
|
+
add vbox
|
13
|
+
|
14
|
+
register_auto_events() # enable the auto event map
|
15
|
+
expose_components() # expose the components to the methods access
|
16
|
+
|
17
|
+
signal_connect('destroy') do
|
18
|
+
Gtk.main_quit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def btn_a1_on_clicked(w)
|
23
|
+
@btn_a1_click_count ||= 0
|
24
|
+
@btn_a1_click_count += 1
|
25
|
+
lbl_a.text = "Button A1 clicked #{@btn_a1_click_count}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def btn_b2_on_clicked(w)
|
29
|
+
@btn_b2_click_count ||= 0
|
30
|
+
@btn_b2_click_count += 1
|
31
|
+
lbl_b.text = "Button B2 clicked #{@btn_b2_click_count}"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def my_layout1
|
36
|
+
_frame 'layout 1', border_width: 5 do
|
37
|
+
_box :horizontal do
|
38
|
+
_label 'Label A', id: :lbl_a
|
39
|
+
_button 'Button A, fixed'
|
40
|
+
_button "Button A1, I'm flexiable", layout: [padding: 15], id: :btn_a1
|
41
|
+
_button 'Button A2, fixed, at the end', layout: [:end, false, false]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def my_layout2
|
47
|
+
_frame 'layout 2', border_width: 5 do
|
48
|
+
_box :vertical do
|
49
|
+
_label 'Label B', id: :lbl_b
|
50
|
+
_button 'Button B, fixed'
|
51
|
+
_button "Button B1, I'm flexiable", layout: [padding: 15]
|
52
|
+
_button 'Button B2, fixed, at the end', layout: [:end, false, false], id: :btn_b2
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
MyWin.new.show_all
|
59
|
+
Gtk.main
|
data/example/with_attr.rb
CHANGED
data/lib/simple_layout.rb
CHANGED
@@ -42,8 +42,9 @@ module SimpleLayout
|
|
42
42
|
'_toggle_button' => Gtk::ToggleButton,
|
43
43
|
'_link_button' => Gtk::LinkButton,
|
44
44
|
'_entry' => Gtk::Entry,
|
45
|
-
'
|
46
|
-
'
|
45
|
+
'_scale' => Gtk::Scale,
|
46
|
+
'_hscale' => [Gtk::Scale, :horizontal],
|
47
|
+
'_vscale' => [Gtk::Scale, :vertical],
|
47
48
|
'_spin_button' => Gtk::SpinButton,
|
48
49
|
'_text_view' => Gtk::TextView,
|
49
50
|
'_tree_view' => Gtk::TreeView,
|
@@ -73,18 +74,25 @@ module SimpleLayout
|
|
73
74
|
'_alignment' => Gtk::Alignment,
|
74
75
|
'_aspect_frame' => Gtk::AspectFrame,
|
75
76
|
'_box' => Gtk::Box,
|
77
|
+
'_vbox' => [Gtk::Box, :vertical],
|
78
|
+
'_hbox' => [Gtk::Box, :horizontal],
|
76
79
|
'_button_box' => Gtk::ButtonBox,
|
77
|
-
'
|
78
|
-
'
|
80
|
+
'_vbutton_box' => [Gtk::ButtonBox, :vertical],
|
81
|
+
'_hbutton_box' => [Gtk::ButtonBox, :horizontal],
|
82
|
+
'_paned' => Gtk::Paned,
|
83
|
+
'_hpaned' => [Gtk::Paned, :horizontal],
|
84
|
+
'_vpaned' => [Gtk::Paned, :vertical],
|
79
85
|
'_layout' => Gtk::Layout,
|
80
86
|
'_notebook' => Gtk::Notebook,
|
81
87
|
'_table' => Gtk::Table,
|
82
88
|
'_expander' => Gtk::Expander,
|
83
89
|
'_frame' => Gtk::Frame,
|
84
|
-
'
|
85
|
-
'
|
86
|
-
'
|
87
|
-
'
|
90
|
+
'_separator' => Gtk::Separator,
|
91
|
+
'_hseparator' => [Gtk::Separator, :horizontal],
|
92
|
+
'_vseparator' => [Gtk::Separator, :vertical],
|
93
|
+
'_scrollbar' => Gtk::Scrollbar,
|
94
|
+
'_hscrollbar' => [Gtk::Scrollbar, :horizontal],
|
95
|
+
'_vscrollbar' => [Gtk::Scrollbar, :vertical],
|
88
96
|
'_scrolled_window' => Gtk::ScrolledWindow,
|
89
97
|
'_arrow' => Gtk::Arrow,
|
90
98
|
'_calendar' => Gtk::Calendar,
|
@@ -339,13 +347,12 @@ module SimpleLayout
|
|
339
347
|
|
340
348
|
add_singleton_event_map(w) # so that you can use: w.on_clicked{|*args| ... }
|
341
349
|
|
342
|
-
# there are some special options: :id, :gid, :layout
|
350
|
+
# there are some special options: :id, :gid, :layout
|
343
351
|
# :id is the name of the component, :gid is the group name of the component, if :gid is not given, use :id as group name
|
344
|
-
# :layout is the layout options for the component
|
352
|
+
# :layout is the layout options for the component
|
345
353
|
name = options.delete(:id)
|
346
354
|
group_name = options.delete(:gid) || name
|
347
355
|
layout_opt = options.delete(:layout)
|
348
|
-
keep_top_cnt = options.delete(:keep_top_container)
|
349
356
|
accel_group = options.delete(:accel_group)
|
350
357
|
accel = options.delete(:accel)
|
351
358
|
|
@@ -406,10 +413,9 @@ module SimpleLayout
|
|
406
413
|
if @containers.size > 0
|
407
414
|
add_component(insp_evb || w, parent, layout_opt) # add myself to parent
|
408
415
|
else
|
409
|
-
add_component(insp_evb || w, self, layout_opt) unless keep_top_cnt # add top container to host
|
410
416
|
@components[:self] = self # add host as ':self'
|
411
417
|
end
|
412
|
-
w
|
418
|
+
insp_evb || w
|
413
419
|
end
|
414
420
|
|
415
421
|
private
|
@@ -540,9 +546,15 @@ module SimpleLayout
|
|
540
546
|
end
|
541
547
|
|
542
548
|
# create a new UI component (container or widget)
|
543
|
-
def create_component(
|
549
|
+
def create_component(class_desc, args, block)
|
544
550
|
@common_attribute ||= []
|
545
551
|
options = {}
|
552
|
+
if class_desc.is_a?(Array) # for virtual widget that use existing widget with specific args, e.g [Gtk::Box, :vertical]
|
553
|
+
component_class = class_desc[0]
|
554
|
+
args = class_desc[1..-1] + args
|
555
|
+
else
|
556
|
+
component_class = class_desc
|
557
|
+
end
|
546
558
|
options = args.pop if args.last.is_a?(Hash)
|
547
559
|
options.merge! @common_attribute.last if @common_attribute.last
|
548
560
|
|
@@ -573,34 +585,34 @@ module SimpleLayout
|
|
573
585
|
end
|
574
586
|
end
|
575
587
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
588
|
+
alias_method :simple_layout_method_missing_alias, :method_missing
|
589
|
+
def method_missing(sym, *args, &block)
|
590
|
+
if sym.to_s =~ /^(.+)_in(_.+)$/
|
591
|
+
maps = self.class.layout_class_maps
|
592
|
+
inner, outter = $1, $2
|
593
|
+
if maps[inner] && maps[outter]
|
594
|
+
if args.last.is_a?(Hash)
|
595
|
+
options = {}
|
596
|
+
options = args.pop if args.last.is_a?(Hash)
|
597
|
+
# default args pass to inner component, execpt:
|
598
|
+
# :layout pass to outter :layout
|
599
|
+
# :inner_layout pass to inner :layout
|
600
|
+
# :outter_args pass to outter args
|
601
|
+
outter_args, outter_layout_opt, options[:layout] =
|
602
|
+
options.delete(:outter_args), options.delete(:layout), options.delete(:inner_layout)
|
603
|
+
outter_args = (outter_args ? [outter_args] : []) unless outter_args.is_a?(Array)
|
604
|
+
outter_args << {} unless outter_args.last.is_a?(Hash)
|
605
|
+
outter_args.last[:layout] ||= outter_layout_opt
|
606
|
+
args.push options # push back inner options
|
607
|
+
end
|
608
|
+
inner_proc = Proc.new do
|
609
|
+
create_component(maps[inner], args, block)
|
610
|
+
end
|
611
|
+
return create_component(maps[outter], outter_args || [], inner_proc)
|
612
|
+
end
|
613
|
+
end
|
614
|
+
simple_layout_method_missing_alias(sym, *args, &block)
|
615
|
+
end
|
604
616
|
|
605
617
|
end
|
606
618
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: GtkSimpleLayout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricky Zheng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple builder style layout helper for Ruby GTK3, it helps you to build
|
14
14
|
ruby GTK3 UI codes in a much more readable way. It also includes a UI inspector
|
@@ -26,10 +26,12 @@ files:
|
|
26
26
|
- example/auto_event_map.rb
|
27
27
|
- example/basic.rb
|
28
28
|
- example/calculator.rb
|
29
|
+
- example/composit.rb
|
29
30
|
- example/expose_components.rb
|
30
31
|
- example/group.rb
|
31
32
|
- example/hello_world.rb
|
32
33
|
- example/menu.rb
|
34
|
+
- example/multiple_layouts.rb
|
33
35
|
- example/serial_port_setup.rb
|
34
36
|
- example/with_attr.rb
|
35
37
|
- lib/simple_layout.rb
|