fidgit 0.0.6alpha → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -2
- data/config/default_schema.yml +13 -3
- data/examples/align_example.rb +5 -5
- data/examples/button_and_toggle_button_example.rb +3 -3
- data/examples/color_picker_example.rb +1 -1
- data/examples/color_well_example.rb +2 -2
- data/examples/combo_box_example.rb +1 -1
- data/examples/file_dialog_example.rb +1 -1
- data/examples/grid_packer_example.rb +3 -3
- data/examples/label_example.rb +2 -2
- data/examples/list_example.rb +1 -1
- data/examples/menu_pane_example.rb +4 -4
- data/examples/message_dialog_example.rb +1 -1
- data/examples/radio_button_example.rb +2 -2
- data/examples/readme_example.rb +1 -1
- data/examples/scroll_window_example.rb +7 -7
- data/examples/slider_example.rb +3 -3
- data/examples/splash_example.rb +3 -3
- data/examples/text_area_example.rb +4 -4
- data/lib/fidgit/elements/button.rb +43 -0
- data/lib/fidgit/elements/color_picker.rb +1 -1
- data/lib/fidgit/elements/container.rb +4 -20
- data/lib/fidgit/elements/element.rb +8 -1
- data/lib/fidgit/elements/file_browser.rb +3 -3
- data/lib/fidgit/elements/{grid_packer.rb → grid.rb} +23 -19
- data/lib/fidgit/elements/group.rb +2 -2
- data/lib/fidgit/elements/{horizontal_packer.rb → horizontal.rb} +1 -1
- data/lib/fidgit/elements/label.rb +2 -0
- data/lib/fidgit/elements/list.rb +1 -1
- data/lib/fidgit/elements/main_packer.rb +26 -0
- data/lib/fidgit/elements/menu_pane.rb +8 -9
- data/lib/fidgit/elements/scroll_area.rb +2 -2
- data/lib/fidgit/elements/scroll_window.rb +1 -1
- data/lib/fidgit/elements/toggle_button.rb +2 -2
- data/lib/fidgit/elements/{vertical_packer.rb → vertical.rb} +1 -1
- data/lib/fidgit/gosu_ext/color.rb +7 -0
- data/lib/fidgit/gosu_ext/gosu_module.rb +25 -0
- data/lib/fidgit/states/file_dialog.rb +1 -1
- data/lib/fidgit/states/gui_state.rb +9 -4
- data/lib/fidgit/states/message_dialog.rb +2 -2
- data/lib/fidgit/version.rb +1 -1
- metadata +18 -16
data/README.textile
CHANGED
@@ -49,7 +49,7 @@ class MyGuiState < Fidgit::GuiState
|
|
49
49
|
super
|
50
50
|
|
51
51
|
# Create a vertically packed section, centred in the window.
|
52
|
-
|
52
|
+
vertical align: :center do
|
53
53
|
# Create a label with a dark green background.
|
54
54
|
my_label = label "Hello world!", background_color: Gosu::Color.rgb(0, 100, 0)
|
55
55
|
|
@@ -71,7 +71,7 @@ As well as a cursor and tool-tips that are managed by the GuiState for you, ther
|
|
71
71
|
|
72
72
|
Elements are best added by using simple methods (listed below). Most of these method accept a block, some offering access to public methods of the element and others being default event handlers.
|
73
73
|
|
74
|
-
The GuiState itself only accepts #
|
74
|
+
The GuiState itself only accepts #vertical/#horizontal/#grid, but any packer or group accepts any other element method.
|
75
75
|
|
76
76
|
h3. GuiState methods
|
77
77
|
|
data/config/default_schema.yml
CHANGED
@@ -32,6 +32,7 @@
|
|
32
32
|
:background_color: ?dark_gray
|
33
33
|
:border_color: ?light_gray
|
34
34
|
:border_thickness: 2
|
35
|
+
:shortcut_color: ?red
|
35
36
|
|
36
37
|
:disabled:
|
37
38
|
:background_color: ?very_dark_gray
|
@@ -83,7 +84,7 @@
|
|
83
84
|
:pattern: "*.*"
|
84
85
|
:show_extension: true
|
85
86
|
|
86
|
-
:
|
87
|
+
:Grid: # < Packer
|
87
88
|
:cell_background_color: ?none
|
88
89
|
:cell_border_color: ?none
|
89
90
|
:cell_border_thickness: 0
|
@@ -94,7 +95,7 @@
|
|
94
95
|
:padding_bottom: 0
|
95
96
|
:padding_left: 0
|
96
97
|
|
97
|
-
:
|
98
|
+
:Horizontal: # < Grid
|
98
99
|
:nothing: nil
|
99
100
|
|
100
101
|
:HorizontalScrollBar: # < ScrollBar
|
@@ -112,6 +113,15 @@
|
|
112
113
|
:List::Item:
|
113
114
|
:border_thickness: 0
|
114
115
|
|
116
|
+
:MainPacker: # < Packer
|
117
|
+
:border_thickness: 0
|
118
|
+
:padding_top: 0
|
119
|
+
:padding_right: 0
|
120
|
+
:padding_bottom: 0
|
121
|
+
:padding_left: 0
|
122
|
+
:spacing_h: 0
|
123
|
+
:spacing_v: 0
|
124
|
+
|
115
125
|
:MenuPane:
|
116
126
|
:background_color: ?very_dark_gray
|
117
127
|
|
@@ -174,7 +184,7 @@
|
|
174
184
|
:background_color: ?very_dark_gray
|
175
185
|
:border_color: ?white
|
176
186
|
|
177
|
-
:
|
187
|
+
:Vertical: # < Grid
|
178
188
|
:nothing: nil
|
179
189
|
|
180
190
|
:VerticalScrollBar: # < ScrollBar
|
data/examples/align_example.rb
CHANGED
@@ -11,17 +11,17 @@ class ExampleState < Fidgit::GuiState
|
|
11
11
|
def initialize
|
12
12
|
super
|
13
13
|
|
14
|
-
|
14
|
+
vertical align: :center, background_color: OUTER_BACKGROUND do
|
15
15
|
label "h => align_h, v => align_v", align_h: :center
|
16
16
|
|
17
|
-
|
17
|
+
grid num_columns: 4, align: :center, cell_background_color: CELL_BACKGROUND, background_color: ROW_BACKGROUND do
|
18
18
|
label "xxx"
|
19
19
|
label "h fill", align_h: :fill
|
20
20
|
label "h right", align_h: :right
|
21
21
|
label "h center", align_h: :center
|
22
22
|
|
23
23
|
|
24
|
-
|
24
|
+
vertical do
|
25
25
|
label "xxx"
|
26
26
|
label "xxx"
|
27
27
|
end
|
@@ -29,7 +29,7 @@ class ExampleState < Fidgit::GuiState
|
|
29
29
|
label "v center", align_v: :center
|
30
30
|
label "v bottom", align_v: :bottom
|
31
31
|
|
32
|
-
|
32
|
+
vertical align_h: :center do
|
33
33
|
label "h center"
|
34
34
|
label "h center"
|
35
35
|
end
|
@@ -40,7 +40,7 @@ class ExampleState < Fidgit::GuiState
|
|
40
40
|
label ""
|
41
41
|
label "bottom right", align_h: :right, align_v: :bottom
|
42
42
|
label "bottom center", align_h: :center, align_v: :bottom
|
43
|
-
|
43
|
+
vertical align_h: :right do
|
44
44
|
label "h right"
|
45
45
|
label "h right"
|
46
46
|
end
|
@@ -5,14 +5,14 @@ class ExampleState < Fidgit::GuiState
|
|
5
5
|
def initialize
|
6
6
|
super
|
7
7
|
|
8
|
-
|
8
|
+
vertical do
|
9
9
|
my_label = label "Label", tip: "I'm a label"
|
10
10
|
|
11
|
-
my_button = button("Button", tip: "I'm a button; press me!") do
|
11
|
+
my_button = button("Button", tip: "I'm a button; press me!", shortcut: :auto) do
|
12
12
|
my_label.text = "Pressed the button!"
|
13
13
|
end
|
14
14
|
|
15
|
-
my_toggle_button = toggle_button("ToggleButton", tip: "I'm a button that toggles") do |sender, value|
|
15
|
+
my_toggle_button = toggle_button("ToggleButton", tip: "I'm a button that toggles", shortcut: :o) do |sender, value|
|
16
16
|
my_label.text = "Turned the toggle button #{value ? "on" : "off"}!"
|
17
17
|
end
|
18
18
|
|
@@ -4,11 +4,11 @@ class ExampleState < Fidgit::GuiState
|
|
4
4
|
def initialize
|
5
5
|
super
|
6
6
|
|
7
|
-
|
7
|
+
vertical do
|
8
8
|
my_label = label "No color selected."
|
9
9
|
|
10
10
|
group do
|
11
|
-
|
11
|
+
grid num_columns: 15, padding: 0, spacing: 4 do
|
12
12
|
150.times do
|
13
13
|
color_well(color: Gosu::Color.rgb(rand(255), rand(255), rand(255)))
|
14
14
|
end
|
@@ -8,7 +8,7 @@ class ExampleState < Fidgit::GuiState
|
|
8
8
|
super
|
9
9
|
|
10
10
|
container.background_color = Gosu::Color.rgb(50, 50, 50)
|
11
|
-
|
11
|
+
vertical align: :center do
|
12
12
|
full_base_directory = ''
|
13
13
|
restricted_base_directory = File.expand_path(File.join(__FILE__, '..', '..'))
|
14
14
|
directory = File.join(restricted_base_directory, 'media', 'images')
|
@@ -8,16 +8,16 @@ class ExampleState < Fidgit::GuiState
|
|
8
8
|
def initialize
|
9
9
|
super
|
10
10
|
|
11
|
-
|
11
|
+
vertical do
|
12
12
|
label "Grid with #{FIXED_NUM} columns"
|
13
|
-
|
13
|
+
grid num_columns: FIXED_NUM, border_color: BORDER_COLOR, cell_border_color: Gosu::Color.rgba(0, 255, 0, 255), cell_border_thickness: 1 do
|
14
14
|
NUM_CELLS.times do |i|
|
15
15
|
label "Cell #{i}", font_size: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
label "Grid with #{FIXED_NUM} rows"
|
20
|
-
|
20
|
+
grid num_rows: FIXED_NUM, border_color: BORDER_COLOR, cell_background_color: Gosu::Color.rgba(0, 100, 100, 255) do
|
21
21
|
NUM_CELLS.times do |i|
|
22
22
|
label "Cell #{i}", font_size: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
|
23
23
|
end
|
data/examples/label_example.rb
CHANGED
@@ -5,14 +5,14 @@ class ExampleState < Fidgit::GuiState
|
|
5
5
|
def initialize
|
6
6
|
super
|
7
7
|
|
8
|
-
|
8
|
+
vertical background_color: Gosu::Color.rgb(255, 0, 0) do
|
9
9
|
label "Hello!", tip: 'A label with text'
|
10
10
|
label "Hello!", icon: Gosu::Image["head_icon.png"], tip: 'A label with text & icon'
|
11
11
|
label '', icon: Gosu::Image["head_icon.png"], tip: 'A label with just icon'
|
12
12
|
label '', background_color: Gosu::Color.rgb(0, 255, 0), tip: 'No text or icon'
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
vertical do
|
16
16
|
label ":left justification", width: 400, background_color: Gosu::Color.rgb(0, 100, 0), justify: :left, tip: 'A label with text'
|
17
17
|
label ":right justification", width: 400, background_color: Gosu::Color.rgb(0, 100, 0), justify: :right, tip: 'A label with text'
|
18
18
|
label ":center justification", width: 400, background_color: Gosu::Color.rgb(0, 100, 0), justify: :center, tip: 'A label with text'
|
data/examples/list_example.rb
CHANGED
@@ -5,15 +5,15 @@ class ExampleState < Fidgit::GuiState
|
|
5
5
|
def initialize
|
6
6
|
super
|
7
7
|
|
8
|
-
|
8
|
+
vertical do
|
9
9
|
my_label = label "Right click to open context menu"
|
10
10
|
|
11
11
|
my_label.subscribe :released_right_mouse_button do
|
12
12
|
menu do
|
13
|
-
item "Chunky bacon", :CHUNKY_BACON,
|
13
|
+
item "Chunky bacon", :CHUNKY_BACON, shortcut_text: "Ctrl-^-*"
|
14
14
|
separator
|
15
|
-
item "Lentils", :LENTILS,
|
16
|
-
item "Tepid gruel", :GRUEL,
|
15
|
+
item "Lentils", :LENTILS, shortcut_text: "Alt-F15"
|
16
|
+
item "Tepid gruel", :GRUEL, shortcut_text: "CenterMeta"
|
17
17
|
|
18
18
|
subscribe :selected do |sender, value|
|
19
19
|
my_label.text = "I like #{value} more than anything. Mmmm!"
|
@@ -4,7 +4,7 @@ class ExampleState < Fidgit::GuiState
|
|
4
4
|
def initialize
|
5
5
|
super
|
6
6
|
|
7
|
-
|
7
|
+
vertical do
|
8
8
|
my_label = label "No button selected"
|
9
9
|
|
10
10
|
button("Deselect") do
|
@@ -16,7 +16,7 @@ class ExampleState < Fidgit::GuiState
|
|
16
16
|
end
|
17
17
|
|
18
18
|
@group = group do
|
19
|
-
|
19
|
+
grid num_columns: 5, padding: 0 do
|
20
20
|
15.times do |i|
|
21
21
|
radio_button "##{i}", i, width: 60
|
22
22
|
end
|
data/examples/readme_example.rb
CHANGED
@@ -17,7 +17,7 @@ class MyGuiState < Fidgit::GuiState
|
|
17
17
|
super
|
18
18
|
|
19
19
|
# Create a vertically packed section, centred on the window.
|
20
|
-
|
20
|
+
vertical align: :center do
|
21
21
|
# Create a label with a dark green background.
|
22
22
|
my_label = label "Hello world!", background_color: Gosu::Color.rgb(0, 100, 0)
|
23
23
|
|
@@ -7,17 +7,17 @@ class ExampleState < Fidgit::GuiState
|
|
7
7
|
def initialize
|
8
8
|
super
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
vertical do
|
11
|
+
horizontal do
|
12
12
|
[
|
13
13
|
[20, "All cheer the ascendancy of number "], # Should have both scrollers
|
14
14
|
[20, "#"], # Only has v-scroller.
|
15
15
|
[4, "#"], # No scrollers.
|
16
16
|
[4, "All cheer the ascendancy of number "], # Only has h-scroller
|
17
17
|
].each do |num_labels, text|
|
18
|
-
|
18
|
+
vertical do
|
19
19
|
scroll_window(width: WIDTH, height: HEIGHT, background_color: Gosu::Color.rgb(0, 100, 0)) do
|
20
|
-
|
20
|
+
vertical do
|
21
21
|
(1..num_labels).each do |i|
|
22
22
|
label "#{text}#{i}!"
|
23
23
|
end
|
@@ -27,14 +27,14 @@ class ExampleState < Fidgit::GuiState
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
horizontal padding: 0 do
|
31
|
+
vertical do
|
32
32
|
scroll_window(width: 300, height: 150) do
|
33
33
|
text_area(text: "Hello world! " * 19, width: 284)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
vertical do
|
38
38
|
scroll_window(width: 300, height: 150) do
|
39
39
|
%w[One Two Three Four Five Six].each do |name|
|
40
40
|
toggle_button(name)
|
data/examples/slider_example.rb
CHANGED
@@ -4,8 +4,8 @@ class ExampleState < Fidgit::GuiState
|
|
4
4
|
def initialize
|
5
5
|
super
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
vertical do
|
8
|
+
horizontal do
|
9
9
|
# Discrete values (0..100)
|
10
10
|
slider = slider(width: 100, range: 0..5, value: 3) do |sender, value|
|
11
11
|
@discrete_label.text = "Discrete slider is at #{value}"
|
@@ -14,7 +14,7 @@ class ExampleState < Fidgit::GuiState
|
|
14
14
|
@discrete_label = label "Discrete slider is at #{slider.value}"
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
horizontal do
|
18
18
|
# Continuous values (0.0..1.0)
|
19
19
|
|
20
20
|
slider = slider(width: 100, range: 0.0..100.0, value: 77.2) do |sender, value|
|
data/examples/splash_example.rb
CHANGED
@@ -4,8 +4,8 @@ require_relative 'helpers/example_window'
|
|
4
4
|
class ExampleState < Fidgit::GuiState
|
5
5
|
def initialize
|
6
6
|
super
|
7
|
-
|
8
|
-
|
7
|
+
vertical do
|
8
|
+
horizontal do
|
9
9
|
text = label "Width:"
|
10
10
|
|
11
11
|
@width_combo = combo_box(value: [640, 480]) do
|
@@ -33,7 +33,7 @@ class ExampleAfterState < GuiState
|
|
33
33
|
|
34
34
|
on_input(:esc, :exit)
|
35
35
|
|
36
|
-
|
36
|
+
vertical do
|
37
37
|
label "Game loaded!", icon: Gosu::Image["head_icon.png"], border_color: Gosu::Color.rgb(255, 255, 255)
|
38
38
|
end
|
39
39
|
end
|
@@ -4,20 +4,20 @@ class ExampleState < Fidgit::GuiState
|
|
4
4
|
def initialize
|
5
5
|
super
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
horizontal do
|
8
|
+
vertical do
|
9
9
|
label 'editable'
|
10
10
|
text_area(width: 200)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
vertical do
|
14
14
|
label 'mirrors to right'
|
15
15
|
text_area(width: 200, text: "Hello, my name in brian the snail!") do |sender, text|
|
16
16
|
@mirror.text = text
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
vertical do
|
21
21
|
label 'not editable'
|
22
22
|
@mirror = text_area(width: 200, enabled: false)
|
23
23
|
end
|
@@ -4,18 +4,54 @@ module Fidgit
|
|
4
4
|
class Button < Label
|
5
5
|
# @param (see Label#initialize)
|
6
6
|
# @option (see Label#initialize)
|
7
|
+
# @option options [Symbol] :shortcut (nil) Adds a shortcut key for this element, that activates it. :auto takes the first letter of the text.
|
7
8
|
def initialize(text, options = {}, &block)
|
8
9
|
options = {
|
9
10
|
color: default(:color),
|
10
11
|
background_color: default(:background_color),
|
11
12
|
border_color: default(:border_color),
|
13
|
+
shortcut_color: default(:shortcut_color),
|
14
|
+
shortcut: nil,
|
12
15
|
}.merge! options
|
13
16
|
|
17
|
+
@shortcut_color = options[:shortcut_color].dup
|
18
|
+
|
19
|
+
@shortcut = if options[:shortcut] == :auto
|
20
|
+
raise ArgumentError.new("Can't use :auto for :shortcut without text") if text.empty?
|
21
|
+
text[0].downcase.to_sym
|
22
|
+
else
|
23
|
+
options[:shortcut]
|
24
|
+
end
|
25
|
+
|
26
|
+
raise ArgumentError.new(":shortcut must be a symbol") unless @shortcut.nil? or @shortcut.is_a? Symbol
|
27
|
+
|
14
28
|
super(text, options)
|
15
29
|
|
16
30
|
update_colors
|
17
31
|
end
|
18
32
|
|
33
|
+
def text=(value)
|
34
|
+
if @shortcut
|
35
|
+
super value.sub(/#{@shortcut}/i) {|char| "<c=#{@shortcut_color.to_hex}>#{char}</c>" }
|
36
|
+
else
|
37
|
+
super value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def parent=(value)
|
42
|
+
if @shortcut
|
43
|
+
state = $window.game_state_manager.inside_state || $window.current_game_state
|
44
|
+
if parent
|
45
|
+
raise ArgumentError.new("Repeat of shortcut #{@shortcut.inspect}") if state.input.has_key? @shortcut
|
46
|
+
state.on_input(@shortcut) { activate unless state.focus }
|
47
|
+
else
|
48
|
+
state.input.delete @shortcut
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
super(value)
|
53
|
+
end
|
54
|
+
|
19
55
|
def clicked_left_mouse_button(sender, x, y)
|
20
56
|
# TODO: Play click sound?
|
21
57
|
nil
|
@@ -64,5 +100,12 @@ module Fidgit
|
|
64
100
|
def post_init_block(&block)
|
65
101
|
subscribe :clicked_left_mouse_button, &block
|
66
102
|
end
|
103
|
+
|
104
|
+
public
|
105
|
+
# Activate the button, as though it had been clicked on.
|
106
|
+
# Does not do anything if the button is disabled.
|
107
|
+
def activate
|
108
|
+
publish(:clicked_left_mouse_button, x + width / 2, y + height / 2) if enabled?
|
109
|
+
end
|
67
110
|
end
|
68
111
|
end
|
@@ -6,7 +6,7 @@ module Fidgit
|
|
6
6
|
class Container < Element
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
def_delegators :@children, :size, :each, :find, :index, :[]
|
9
|
+
def_delegators :@children, :size, :each, :find, :index, :[], :empty?, :map, :select, :inject
|
10
10
|
|
11
11
|
def x=(value)
|
12
12
|
each {|c| c.x += value - x }
|
@@ -89,38 +89,22 @@ module Fidgit
|
|
89
89
|
List.new({parent: self}.merge!(options), &block)
|
90
90
|
end
|
91
91
|
|
92
|
-
# Deprecated: use horizontal/vertical/grid
|
93
|
-
def pack(arrangement, options = {}, &block)
|
94
|
-
klass = case arrangement
|
95
|
-
when :horizontal
|
96
|
-
HorizontalPacker
|
97
|
-
when :vertical
|
98
|
-
VerticalPacker
|
99
|
-
when :grid
|
100
|
-
GridPacker
|
101
|
-
else
|
102
|
-
raise ArgumentError, "packing arrangement must be one of :horizontal, :vertical or :grid"
|
103
|
-
end
|
104
|
-
|
105
|
-
klass.new({parent: self}.merge!(options), &block)
|
106
|
-
end
|
107
|
-
|
108
92
|
public
|
109
93
|
# Pack elements within the block horizontally.
|
110
94
|
def horizontal(options = {}, &block)
|
111
|
-
|
95
|
+
Horizontal.new({ parent: self }.merge!(options), &block)
|
112
96
|
end
|
113
97
|
|
114
98
|
public
|
115
99
|
# Pack elements within the blockvertically.
|
116
100
|
def vertical(options = {}, &block)
|
117
|
-
|
101
|
+
Vertical.new({ parent: self }.merge!(options), &block)
|
118
102
|
end
|
119
103
|
|
120
104
|
public
|
121
105
|
# Pack elements within the block in a grid (matrix) formation.
|
122
106
|
def grid(options = {}, &block)
|
123
|
-
|
107
|
+
Grid.new({ parent: self }.merge!(options), &block)
|
124
108
|
end
|
125
109
|
|
126
110
|
def radio_button(text, value, options = {}, &block)
|
@@ -67,7 +67,14 @@ module Fidgit
|
|
67
67
|
def drag?(button); false; end
|
68
68
|
|
69
69
|
def enabled?; @enabled; end
|
70
|
-
|
70
|
+
|
71
|
+
def enabled=(value)
|
72
|
+
if @mouse_over and enabled? and not value
|
73
|
+
$window.current_game_state.unset_mouse_over
|
74
|
+
end
|
75
|
+
|
76
|
+
@enabled = value
|
77
|
+
end
|
71
78
|
|
72
79
|
def font; @font ||= Gosu::Font[@font_name, @font_size]; end
|
73
80
|
|
@@ -50,8 +50,8 @@ module Fidgit
|
|
50
50
|
|
51
51
|
super options
|
52
52
|
|
53
|
-
|
54
|
-
@nav_buttons =
|
53
|
+
vertical do
|
54
|
+
@nav_buttons = horizontal padding: 0, spacing: 2
|
55
55
|
|
56
56
|
@scroll_window = scroll_window(height: 250, width: options[:width]) do
|
57
57
|
@files_list = list(width: options[:width]) do
|
@@ -74,7 +74,7 @@ module Fidgit
|
|
74
74
|
|
75
75
|
create_nav_buttons
|
76
76
|
|
77
|
-
|
77
|
+
horizontal align: :center, padding: 0 do
|
78
78
|
@action_button = button(options[:"#{type}_text"]) do
|
79
79
|
publish :selected, @type, file_path
|
80
80
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Fidgit
|
4
4
|
# A vertically aligned element packing container.
|
5
5
|
|
6
|
-
class
|
6
|
+
class Grid < Packer
|
7
7
|
# @return [Integer]
|
8
8
|
attr_reader :num_rows
|
9
9
|
# @return [Integer]
|
@@ -72,8 +72,8 @@ module Fidgit
|
|
72
72
|
protected
|
73
73
|
# Repack all the elements into their positions.
|
74
74
|
def repack
|
75
|
-
@widths = Array.new(@
|
76
|
-
@heights = Array.new(@
|
75
|
+
@widths = Array.new(@rows.empty? ? 0 : @rows[0].size, 0)
|
76
|
+
@heights = Array.new(@rows.size, 0)
|
77
77
|
|
78
78
|
filled_columns = []
|
79
79
|
filled_rows = []
|
@@ -82,35 +82,39 @@ module Fidgit
|
|
82
82
|
@rows.each_with_index do |row, row_num|
|
83
83
|
row.each_with_index do |element, column_num|
|
84
84
|
fills = (element.align_h == :fill)
|
85
|
-
@widths[column_num] = [fills ? 0 : element.outer_width, @widths[column_num]
|
85
|
+
@widths[column_num] = [fills ? 0 : element.outer_width, @widths[column_num]].max
|
86
86
|
filled_columns.push fills
|
87
87
|
|
88
88
|
fills = (element.align_v == :fill)
|
89
|
-
@heights[row_num] = [fills ? 0 : element.outer_height, @heights[row_num]
|
89
|
+
@heights[row_num] = [fills ? 0 : element.outer_height, @heights[row_num]].max
|
90
90
|
filled_rows.push fills
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
# Expand the size of each filled column to make the minimum size required.
|
95
|
-
|
96
|
-
|
95
|
+
unless @widths.empty?
|
96
|
+
num_filled_columns = filled_columns.select {|value| value }.count
|
97
97
|
total_width = @widths.inject(0, :+) + (padding_left + padding_right) + ((@num_columns - 1) * spacing_h)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@widths[
|
98
|
+
extra_width = min_width - total_width
|
99
|
+
if extra_width > 0
|
100
|
+
if num_filled_columns > 0
|
101
|
+
@widths[filled_columns.index true] += extra_width
|
102
|
+
else
|
103
|
+
@widths[-1] += extra_width
|
102
104
|
end
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
106
108
|
# Expand the size of each filled row to make the minimum size required.
|
107
|
-
|
108
|
-
|
109
|
+
unless @heights.empty?
|
110
|
+
num_filled_rows = filled_rows.select {|value| value }.count
|
109
111
|
total_height = @heights.inject(0, :+) + (padding_left + padding_right) + ((@num_rows - 1) * spacing_v)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@heights[
|
112
|
+
extra_height = min_height - total_height
|
113
|
+
if extra_height > 0
|
114
|
+
if num_filled_rows > 0
|
115
|
+
@heights[filled_rows.index true] += extra_height
|
116
|
+
else
|
117
|
+
@heights[-1] += extra_height
|
114
118
|
end
|
115
119
|
end
|
116
120
|
end
|
@@ -127,7 +131,7 @@ module Fidgit
|
|
127
131
|
when :fill
|
128
132
|
if element.width < @widths[column_num]
|
129
133
|
element.width = @widths[column_num]
|
130
|
-
element.send :repack if element.is_a?
|
134
|
+
element.send :repack if element.is_a? Grid
|
131
135
|
end
|
132
136
|
when :center
|
133
137
|
element.x += (@widths[column_num] - element.width) / 2
|
@@ -144,7 +148,7 @@ module Fidgit
|
|
144
148
|
when :fill
|
145
149
|
if element.height < @heights[row_num]
|
146
150
|
element.height = @heights[row_num]
|
147
|
-
element.send :repack if element.is_a?
|
151
|
+
element.send :repack if element.is_a? Grid
|
148
152
|
end
|
149
153
|
when :center
|
150
154
|
element.y += (@heights[row_num] - element.height) / 2
|
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
# @example
|
12
12
|
# group do
|
13
|
-
#
|
13
|
+
# horizontal do
|
14
14
|
# radio_button 1, text: '1', checked: true
|
15
15
|
# radio_button 2, text: '2'
|
16
16
|
# subscribe :changed do |sender, value|
|
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
# @example
|
45
45
|
# @my_group = group do
|
46
|
-
#
|
46
|
+
# horizontal do
|
47
47
|
# radio_button(1, text: '1', checked: true)
|
48
48
|
# radio_button(2, text: '2')
|
49
49
|
# end
|
data/lib/fidgit/elements/list.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "vertical"
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
# Main container that can contains a single "proper" packing element.
|
5
|
+
class MainPacker < Vertical
|
6
|
+
def initialize(options = {})
|
7
|
+
options = {
|
8
|
+
width: $window.width,
|
9
|
+
height: $window.height,
|
10
|
+
}.merge! options
|
11
|
+
|
12
|
+
super options
|
13
|
+
end
|
14
|
+
|
15
|
+
def width; $window.width; end
|
16
|
+
def height; $window.height; end
|
17
|
+
def width=(value); ; end
|
18
|
+
def height=(value); ; end
|
19
|
+
|
20
|
+
def add(element)
|
21
|
+
raise "MainPacker can only contain one packing element" unless empty?
|
22
|
+
raise "MainPacker can only contain packing elements" unless element.is_a? Packer
|
23
|
+
super(element)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,31 +4,30 @@ module Fidgit
|
|
4
4
|
class MenuPane < Composite
|
5
5
|
# An item within the menu.
|
6
6
|
class Item < Button
|
7
|
-
attr_reader :value, :
|
7
|
+
attr_reader :value, :shortcut_text
|
8
8
|
|
9
9
|
# @param (see Button#initialize)
|
10
10
|
#
|
11
11
|
# @option (see Button#initialize)
|
12
12
|
# @param [any] value Value if the user picks this item
|
13
|
-
# @option options [
|
14
|
-
# @option options [String] :shortcut ('')
|
13
|
+
# @option options [String] :shortcut_text ('')
|
15
14
|
def initialize(text, value, options = {})
|
16
15
|
options = {
|
17
16
|
enabled: true,
|
18
17
|
border_color: default(:border_color),
|
18
|
+
shortcut_text: '',
|
19
19
|
}.merge! options
|
20
20
|
|
21
21
|
@value = value
|
22
|
-
@
|
23
|
-
@shortcut = options[:shortcut] || ''
|
22
|
+
@shortcut_text = options[:shortcut_text]
|
24
23
|
|
25
24
|
super(text, options)
|
26
25
|
end
|
27
26
|
|
28
27
|
def draw_foreground
|
29
28
|
super
|
30
|
-
unless @
|
31
|
-
font.draw_rel("#{@
|
29
|
+
unless @shortcut_text.empty?
|
30
|
+
font.draw_rel("#{@shortcut_text}", rect.right - padding_right, y + ((height - font_size) / 2).floor, z, 1, 0, 1, 1, color)
|
32
31
|
end
|
33
32
|
|
34
33
|
nil
|
@@ -37,7 +36,7 @@ module Fidgit
|
|
37
36
|
protected
|
38
37
|
def layout
|
39
38
|
super
|
40
|
-
rect.width += font.text_width(" #{@
|
39
|
+
rect.width += font.text_width(" #{@shortcut_text}") unless @shortcut_text.empty?
|
41
40
|
nil
|
42
41
|
end
|
43
42
|
end
|
@@ -89,7 +88,7 @@ module Fidgit
|
|
89
88
|
|
90
89
|
super(options)
|
91
90
|
|
92
|
-
@items =
|
91
|
+
@items = vertical spacing: 0, padding: 0
|
93
92
|
|
94
93
|
if options[:show] and state.is_a? GuiState
|
95
94
|
show
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Fidgit
|
4
4
|
# A basic scrolling area. It is not managed in any way (use ScrollWindow for that).
|
5
5
|
class ScrollArea < Container
|
6
|
-
# @return [
|
6
|
+
# @return [Vertical] The content shown within this ScrollArea
|
7
7
|
attr_reader :content
|
8
8
|
|
9
9
|
def offset_x; x - @content.x; end
|
@@ -31,7 +31,7 @@ module Fidgit
|
|
31
31
|
|
32
32
|
super(options)
|
33
33
|
|
34
|
-
@content =
|
34
|
+
@content = Vertical.new(parent: self, padding: 0)
|
35
35
|
|
36
36
|
self.offset_x = options[:offset_x] || options[:offset]
|
37
37
|
self.offset_y = options[:offset_y] || options[:offset]
|
@@ -24,7 +24,7 @@ module Fidgit
|
|
24
24
|
|
25
25
|
super(options)
|
26
26
|
|
27
|
-
@grid =
|
27
|
+
@grid = grid num_columns: 2, padding: 0, spacing: 0 do
|
28
28
|
@view = scroll_area(owner: self, width: options[:width], height: options[:height])
|
29
29
|
@spacer = label '', padding: 0, width: 0, height: 0
|
30
30
|
end
|
@@ -48,12 +48,12 @@ module Fidgit
|
|
48
48
|
protected
|
49
49
|
def update_status
|
50
50
|
if @value
|
51
|
-
|
51
|
+
self.text = @text_on.dup
|
52
52
|
@icon = @icon_on ? @icon_on.dup : nil
|
53
53
|
@tip = @tip_on.dup
|
54
54
|
@border_color = @border_color_on.dup
|
55
55
|
else
|
56
|
-
|
56
|
+
self.text = @text_off.dup
|
57
57
|
@icon = @icon_off ? @icon_off.dup : nil
|
58
58
|
@tip = @tip_off.dup
|
59
59
|
@border_color = @border_color_off.dup
|
@@ -77,6 +77,13 @@ module Gosu
|
|
77
77
|
[red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0]
|
78
78
|
end
|
79
79
|
|
80
|
+
# Convert to a 6-digit hexadecimal value, appropriate for passing to the Gosu +<c>+ tag. The alpha channel is ignored.
|
81
|
+
#
|
82
|
+
# @return [String] RGB hexadecimal string, such as "AABB00"
|
83
|
+
def to_hex
|
84
|
+
"%02x%02x%02x" % [red, green, blue]
|
85
|
+
end
|
86
|
+
|
80
87
|
# Show the Color as <RGBA [0, 0, 0, 0]> or, if opaque, <RGB [0, 0, 0]> (Gosu default is '(ARGB:0/0/0/0)')
|
81
88
|
def to_s
|
82
89
|
if opaque?
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Gosu
|
2
|
+
class << self
|
3
|
+
alias_method :register_entity_fidgit, :register_entity
|
4
|
+
|
5
|
+
protected
|
6
|
+
def init_entities
|
7
|
+
@entities = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
public
|
11
|
+
def register_entity(name, image)
|
12
|
+
name = name.to_sym
|
13
|
+
register_entity_fidgit(name, image)
|
14
|
+
@entities[name] = image
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
public
|
19
|
+
def entity(name)
|
20
|
+
@entities[name.to_sym]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
init_entities
|
25
|
+
end
|
@@ -10,7 +10,7 @@ module Fidgit
|
|
10
10
|
|
11
11
|
super(options)
|
12
12
|
|
13
|
-
|
13
|
+
vertical align: :center, padding: 0 do |packer|
|
14
14
|
FileBrowser.new(type, { parent: packer }.merge!(options)) do |sender, result, file_name|
|
15
15
|
hide
|
16
16
|
block.call result, file_name if block
|
@@ -44,15 +44,12 @@ module Fidgit
|
|
44
44
|
# (see MessageDialog#initialize)
|
45
45
|
def message(text, options = {}, &block); MessageDialog.new(text, options, &block); end
|
46
46
|
|
47
|
-
# (see Container#pack)
|
48
|
-
def pack(*args, &block); @container.pack *args, █ end
|
49
|
-
|
50
47
|
# (see Container#clear)
|
51
48
|
def clear(*args, &block); @container.clear *args, █ end
|
52
49
|
|
53
50
|
def initialize
|
54
51
|
# The container is where the user puts their content.
|
55
|
-
@container =
|
52
|
+
@container = MainPacker.new
|
56
53
|
|
57
54
|
unless defined? @@draw_pixel
|
58
55
|
media_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'media'))
|
@@ -164,11 +161,19 @@ module Fidgit
|
|
164
161
|
end
|
165
162
|
|
166
163
|
def finalize
|
164
|
+
unset_mouse_over
|
165
|
+
|
167
166
|
@tool_tip = nil
|
168
167
|
|
169
168
|
nil
|
170
169
|
end
|
171
170
|
|
171
|
+
# Called by active elements when they are disabled.
|
172
|
+
def unset_mouse_over
|
173
|
+
@mouse_over.publish :leave if @mouse_over
|
174
|
+
@mouse_over = nil
|
175
|
+
end
|
176
|
+
|
172
177
|
# Set the menu pane to be displayed.
|
173
178
|
#
|
174
179
|
# @param [MenuPane] menu Menu to display.
|
@@ -42,10 +42,10 @@ module Fidgit
|
|
42
42
|
# Dialog is forced to the centre.
|
43
43
|
options[:align_h] = options[:align_v] = :center
|
44
44
|
|
45
|
-
|
45
|
+
vertical options do
|
46
46
|
text_area(text: message, enabled: false, width: options[:width] - padding_left - padding_right)
|
47
47
|
|
48
|
-
|
48
|
+
horizontal align_h: :center do
|
49
49
|
@type.to_s.split('_').each do |type|
|
50
50
|
button(options[:"#{type}_text"]) do
|
51
51
|
hide
|
data/lib/fidgit/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fidgit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bil Bas (Spooner)
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-10 00:00:00.000000000 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gosu
|
17
|
-
requirement: &
|
17
|
+
requirement: &27888528 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.7.32
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *27888528
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: chingu
|
28
|
-
requirement: &
|
28
|
+
requirement: &27888228 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.9rc5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *27888228
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &27887940 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 2.1.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *27887940
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: texplay
|
50
|
-
requirement: &
|
50
|
+
requirement: &27887640 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: 0.3.5
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *27887640
|
59
59
|
description: Fidgit is a GUI library built on Gosu/Chingu
|
60
60
|
email:
|
61
61
|
- bil.bagpuss@gmail.com
|
@@ -103,11 +103,12 @@ files:
|
|
103
103
|
- lib/fidgit/elements/container.rb
|
104
104
|
- lib/fidgit/elements/element.rb
|
105
105
|
- lib/fidgit/elements/file_browser.rb
|
106
|
-
- lib/fidgit/elements/
|
106
|
+
- lib/fidgit/elements/grid.rb
|
107
107
|
- lib/fidgit/elements/group.rb
|
108
|
-
- lib/fidgit/elements/
|
108
|
+
- lib/fidgit/elements/horizontal.rb
|
109
109
|
- lib/fidgit/elements/label.rb
|
110
110
|
- lib/fidgit/elements/list.rb
|
111
|
+
- lib/fidgit/elements/main_packer.rb
|
111
112
|
- lib/fidgit/elements/menu_pane.rb
|
112
113
|
- lib/fidgit/elements/packer.rb
|
113
114
|
- lib/fidgit/elements/radio_button.rb
|
@@ -118,9 +119,10 @@ files:
|
|
118
119
|
- lib/fidgit/elements/text_area.rb
|
119
120
|
- lib/fidgit/elements/toggle_button.rb
|
120
121
|
- lib/fidgit/elements/tool_tip.rb
|
121
|
-
- lib/fidgit/elements/
|
122
|
+
- lib/fidgit/elements/vertical.rb
|
122
123
|
- lib/fidgit/event.rb
|
123
124
|
- lib/fidgit/gosu_ext/color.rb
|
125
|
+
- lib/fidgit/gosu_ext/gosu_module.rb
|
124
126
|
- lib/fidgit/history.rb
|
125
127
|
- lib/fidgit/redirector.rb
|
126
128
|
- lib/fidgit/schema.rb
|
@@ -166,9 +168,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
169
|
none: false
|
168
170
|
requirements:
|
169
|
-
- - ! '
|
171
|
+
- - ! '>='
|
170
172
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
173
|
+
version: '0'
|
172
174
|
requirements: []
|
173
175
|
rubyforge_project: fidgit
|
174
176
|
rubygems_version: 1.5.2
|