Class: Sirens::SplitterView
Instance Method Summary
collapse
Methods inherited from WidgetView
#apply_prop, #apply_props, #main_handle
accepted_styles, #accepted_styles, #attribute_at, #background_color=, #foreground_color=, #height, #height=, #main_handle, #populate_popup_menu_block=, #remove_view, #set_attribute, #show, #show_popup_menu, #state_colors_from, view_accepted_styles, #width, #width=
Constructor Details
#initialize(orientation:) ⇒ SplitterView
6
7
8
9
10
|
# File 'lib/views/splitter_view.rb', line 6
def initialize(orientation:)
@orientation = orientation
super()
end
|
Instance Method Details
#add_view(child_view) ⇒ Object
Adds the child_component to this component.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/views/splitter_view.rb', line 25
def add_view(child_view)
@child_views << child_view
if @child_views.size <= 2
main_handle.add(child_view.main_handle)
else
paned = Gtk::Paned.new(@orientation)
last_child_handle = main_handle.children.last
main_handle.remove(last_child_handle)
paned.add(last_child_handle)
paned.add(child_view.main_handle)
main_handle.add(paned)
end
end
|
#initialize_handles ⇒ Object
12
13
14
|
# File 'lib/views/splitter_view.rb', line 12
def initialize_handles()
@main_handle = Gtk::Paned.new(@orientation)
end
|
#is_horizontal ⇒ Object
44
45
46
|
# File 'lib/views/splitter_view.rb', line 44
def is_horizontal()
@orientation === :horizontal
end
|
#on_size_allocation(width:, height:) ⇒ Object
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
85
86
87
88
89
90
91
|
# File 'lib/views/splitter_view.rb', line 48
def on_size_allocation(width:, height:)
return if @is_first_size_allocation === false
@is_first_size_allocation = false
remaining_proportion = 1.0
current_handle = main_handle
@child_views.each_with_index do |child_view, index|
return if index === @child_views.size
return if current_handle.children.empty?
proportion = child_view.attribute_at(:splitter_proportion)
remaining_proportion = remaining_proportion - proportion
children = current_handle.children
first_child = children[0]
set_proportional_size(
view_handle: first_child,
width: width,
height: height,
proportion: proportion
)
return if children.size < 2
second_child = children[1]
set_proportional_size(
view_handle: second_child,
width: width,
height: height,
proportion: remaining_proportion
)
current_handle = second_child
end
end
|
#set_proportional_size(view_handle:, width:, height:, proportion:) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/views/splitter_view.rb', line 93
def set_proportional_size(view_handle:, width:, height:, proportion:)
if is_horizontal
view_handle.set_size_request(width * proportion, height)
else
view_handle.set_size_request(width, height * proportion)
end
end
|
#subscribe_to_ui_events ⇒ Object
16
17
18
19
20
|
# File 'lib/views/splitter_view.rb', line 16
def subscribe_to_ui_events()
main_handle.signal_connect('size-allocate') { |widget, rectangle|
on_size_allocation(width: rectangle.width, height: rectangle.height)
}
end
|