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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63da04a080c9692caa7a4d73c64cd039cc925767c056668fdd44d1054ccec355
4
- data.tar.gz: 4f784f8a7c76dee45b23c50e020f88d06a52a928a79903bb3351bf4a0d5fcc25
3
+ metadata.gz: b44cf7d7f21d27bd3f547c892caa0f06bc69e74d1ce95b8124bfc9670010561e
4
+ data.tar.gz: f4d0ac95c666ebc40fe3110f19acd3ea27c9733e32035a5bf2cdce8b1e7b25db
5
5
  SHA512:
6
- metadata.gz: 820c45c85a73d4f0972ac2c5aa893edc001c1cccba316b1b39f6cb8d7bfd523b924b43bf4f78a734ee9ad839f4a47fe1b462ef14665f67ccad3d9390a9147a4b
7
- data.tar.gz: efc1b63c51fcd7f2126bbfc64fd9e5e07f4329a8608aa5873fbfd2733787cd1a88f4871cecb277a6bfd364cc0922d14f794d009d4401372b4e6fdde89b954054
6
+ metadata.gz: 5e4f694291ac3410341d7ce2fe77d29c3f744e108d07b55d0233d6627de0b3c35d4dc37a2036c57364934fe136397add63a5f6a1b342ff1053c5ed6221b0a8db
7
+ data.tar.gz: b3fe6690ae04f128c7a4beccb70d7547b5dc7214c998261c178a9bedb6f44eaca045fb2176117f081957e840d1b1bc0090fd41479ddf0822f4fa941411efb8ce
@@ -15,7 +15,7 @@ class MyWin < Gtk::Window
15
15
  def initialize
16
16
  super
17
17
  @click_count = 0
18
- my_layout
18
+ add my_layout()
19
19
 
20
20
  register_auto_events() # enable the auto event map
21
21
 
data/example/basic.rb CHANGED
@@ -5,7 +5,7 @@ class MyWin < Gtk::Window
5
5
  include SimpleLayout::Base
6
6
  def initialize
7
7
  super
8
- my_layout
8
+ add my_layout()
9
9
  signal_connect('destroy') do
10
10
  Gtk.main_quit
11
11
  end
@@ -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
- _box :vertical do
16
+ _vbox do
17
17
  with_attr :border_width => 3 do
18
- _box :horizontal do
18
+ _hbox do
19
19
  _entry :id => :ent_input, :layout => [true, true, 5]
20
20
  end
21
- _box :horizontal do
21
+ _hbox do
22
22
  _frame do
23
23
  _label 'M', :set_size_request => [20, 20]
24
24
  end
25
- _button_box :horizontal do
25
+ _hbutton_box do
26
26
  _button 'Backspace'
27
27
  _button 'CE'
28
28
  _button 'C'
29
29
  end
30
30
  end
31
- _box :horizontal do
32
- _button_box :vertical do
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
- _box :vertical do
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
- _box :horizontal, :layout => [true, true] do
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
@@ -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
@@ -13,7 +13,7 @@ class MyWin < Gtk::Window
13
13
 
14
14
  def initialize
15
15
  super
16
- my_layout
16
+ add my_layout()
17
17
 
18
18
  expose_components()
19
19
  # after call expose_components(), btn_a and btn_b become available
data/example/group.rb CHANGED
@@ -41,7 +41,7 @@ class MyWin < Gtk::Window
41
41
  super
42
42
  @count_a = 0
43
43
  @count_b = 0
44
- my_layout
44
+ add my_layout()
45
45
 
46
46
  register_auto_events()
47
47
 
@@ -5,7 +5,7 @@ class MyWin < Gtk::Window
5
5
  include SimpleLayout::Base
6
6
  def initialize
7
7
  super
8
- my_layout
8
+ add my_layout()
9
9
  signal_connect('destroy') do
10
10
  Gtk.main_quit
11
11
  end
data/example/menu.rb CHANGED
@@ -5,7 +5,7 @@ class MyWin < Gtk::Window
5
5
  include SimpleLayout::Base
6
6
  def initialize
7
7
  super
8
- my_layout
8
+ add my_layout()
9
9
  signal_connect('destroy') do
10
10
  Gtk.main_quit
11
11
  end
@@ -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
@@ -28,7 +28,7 @@ class MyWin < Gtk::Window
28
28
  def initialize
29
29
  super
30
30
 
31
- my_layout
31
+ add my_layout()
32
32
 
33
33
  register_auto_events()
34
34
  expose_components()
data/example/with_attr.rb CHANGED
@@ -5,7 +5,7 @@ class MyWin < Gtk::Window
5
5
  include SimpleLayout::Base
6
6
  def initialize
7
7
  super
8
- my_layout
8
+ add my_layout()
9
9
  signal_connect('destroy') do
10
10
  Gtk.main_quit
11
11
  end
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
- '_hscale' => Gtk::HScale,
46
- '_vscale' => Gtk::VScale,
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
- '_hpaned' => Gtk::HPaned,
78
- '_vpaned' => Gtk::VPaned,
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
- '_hseparator' => Gtk::HSeparator,
85
- '_vseparator' => Gtk::VSeparator,
86
- '_hscrollbar' => Gtk::HScrollbar,
87
- '_vscrollbar' => Gtk::VScrollbar,
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, :keep_top_container
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, :keep_top_container is to keep the top container
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(component_class, args, block)
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
- # alias_method :simple_layout_method_missing_alias, :method_missing
577
- # def method_missing(sym, *args, &block)
578
- # if sym.to_s =~ /^(.+)_in_(.+)$/
579
- # maps = self.class.layout_class_maps
580
- # inner, outter = $1, $2
581
- # if maps[inner] && maps[outter]
582
- # if args.last.is_a?(Hash)
583
- # options = {}
584
- # options = args.pop if args.last.is_a?(Hash)
585
- # # default args pass to inner component, execpt:
586
- # # :layout pass to outter :layout
587
- # # :inner_layout pass to inner :layout
588
- # # :outter_args pass to outter args
589
- # outter_args, outter_layout_opt, options[:layout] =
590
- # options.delete(:outter_args), options.delete(:layout), options.delete(:inner_layout)
591
- # outter_args = (outter_args ? [outter_args] : []) unless outter_args.is_a?(Array)
592
- # outter_args << {} unless outter_args.last.is_a?(Hash)
593
- # outter_args.last[:layout] ||= outter_layout_opt
594
- # args.push options # push back inner options
595
- # end
596
- # inner_proc = Proc.new do
597
- # create_component(maps[inner], args, block)
598
- # end
599
- # return create_component(maps[outter], outter_args || [], inner_proc)
600
- # end
601
- # end
602
- # simple_layout_method_missing_alias(sym, *args, &block)
603
- # end
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.0
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-08 00:00:00.000000000 Z
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