shoes-core 4.0.0.pre3 → 4.0.0.pre4

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.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes +1 -1
  3. data/bin/shoes-picker +5 -1
  4. data/bin/shoes-stub +1 -1
  5. data/ext/install/shoes.bat +2 -0
  6. data/lib/rubygems_plugin.rb +2 -2
  7. data/lib/shoes/app.rb +18 -19
  8. data/lib/shoes/arc.rb +8 -8
  9. data/lib/shoes/background.rb +4 -8
  10. data/lib/shoes/border.rb +4 -8
  11. data/lib/shoes/builtin_methods.rb +2 -2
  12. data/lib/shoes/button.rb +2 -9
  13. data/lib/shoes/check_button.rb +0 -12
  14. data/lib/shoes/color.rb +29 -34
  15. data/lib/shoes/common/background_element.rb +4 -0
  16. data/lib/shoes/common/fill.rb +9 -0
  17. data/lib/shoes/common/initialization.rb +59 -0
  18. data/lib/shoes/common/inspect.rb +20 -2
  19. data/lib/shoes/common/rotate.rb +10 -0
  20. data/lib/shoes/common/stroke.rb +9 -0
  21. data/lib/shoes/common/style.rb +21 -7
  22. data/lib/shoes/common/style_normalizer.rb +1 -3
  23. data/lib/shoes/common/ui_element.rb +10 -0
  24. data/lib/shoes/common/visibility.rb +4 -4
  25. data/lib/shoes/configuration.rb +4 -2
  26. data/lib/shoes/core/version.rb +1 -1
  27. data/lib/shoes/dialog.rb +2 -2
  28. data/lib/shoes/dimension.rb +78 -68
  29. data/lib/shoes/dimensions.rb +22 -10
  30. data/lib/shoes/download.rb +26 -10
  31. data/lib/shoes/dsl.rb +32 -51
  32. data/lib/shoes/gradient.rb +6 -13
  33. data/lib/shoes/image.rb +4 -9
  34. data/lib/shoes/input_box.rb +6 -9
  35. data/lib/shoes/internal_app.rb +16 -36
  36. data/lib/shoes/line.rb +29 -10
  37. data/lib/shoes/link.rb +13 -2
  38. data/lib/shoes/list_box.rb +33 -11
  39. data/lib/shoes/logger.rb +12 -13
  40. data/lib/shoes/mock/arc.rb +2 -0
  41. data/lib/shoes/mock/common_methods.rb +9 -0
  42. data/lib/shoes/mock/shape.rb +1 -1
  43. data/lib/shoes/mock/slot.rb +1 -0
  44. data/lib/shoes/oval.rb +13 -8
  45. data/lib/shoes/packager.rb +7 -1
  46. data/lib/shoes/point.rb +26 -3
  47. data/lib/shoes/progress.rb +6 -8
  48. data/lib/shoes/rect.rb +14 -10
  49. data/lib/shoes/shape.rb +28 -14
  50. data/lib/shoes/slot.rb +33 -24
  51. data/lib/shoes/slot_contents.rb +4 -4
  52. data/lib/shoes/star.rb +7 -16
  53. data/lib/shoes/text.rb +5 -3
  54. data/lib/shoes/text_block.rb +17 -16
  55. data/lib/shoes/text_block_dimensions.rb +1 -1
  56. data/lib/shoes/ui/cli.rb +12 -3
  57. data/lib/shoes/ui/picker.rb +64 -19
  58. data/lib/shoes/version.rb +1 -1
  59. data/shoes-core.gemspec +2 -2
  60. data/spec/shoes/animation_spec.rb +1 -1
  61. data/spec/shoes/app_spec.rb +4 -23
  62. data/spec/shoes/color_spec.rb +16 -1
  63. data/spec/shoes/common/style_normalizer_spec.rb +3 -3
  64. data/spec/shoes/common/style_spec.rb +42 -5
  65. data/spec/shoes/dimension_spec.rb +5 -7
  66. data/spec/shoes/dimensions_spec.rb +7 -7
  67. data/spec/shoes/download_spec.rb +49 -8
  68. data/spec/shoes/flow_spec.rb +1 -1
  69. data/spec/shoes/helpers/fake_element.rb +7 -0
  70. data/spec/shoes/helpers/sample17_helper.rb +3 -3
  71. data/spec/shoes/integration_spec.rb +1 -1
  72. data/spec/shoes/internal_app_spec.rb +8 -0
  73. data/spec/shoes/line_spec.rb +35 -3
  74. data/spec/shoes/link_spec.rb +24 -12
  75. data/spec/shoes/list_box_spec.rb +14 -2
  76. data/spec/shoes/point_spec.rb +28 -0
  77. data/spec/shoes/renamed_delegate_spec.rb +2 -2
  78. data/spec/shoes/shape_spec.rb +15 -2
  79. data/spec/shoes/shared_examples/changeable.rb +1 -1
  80. data/spec/shoes/shared_examples/common_methods.rb +1 -1
  81. data/spec/shoes/shared_examples/dsl/style.rb +1 -1
  82. data/spec/shoes/shared_examples/dsl/text_elements.rb +3 -3
  83. data/spec/shoes/shared_examples/dsl/video.rb +1 -1
  84. data/spec/shoes/shared_examples/dsl_app_context.rb +0 -1
  85. data/spec/shoes/shared_examples/parent.rb +1 -1
  86. data/spec/shoes/shared_examples/slot.rb +11 -5
  87. data/spec/shoes/shared_examples/state.rb +2 -2
  88. data/spec/shoes/shared_examples/style.rb +1 -1
  89. data/spec/shoes/spec_helper.rb +1 -1
  90. data/spec/shoes/text_block_spec.rb +20 -3
  91. data/spec/shoes/ui/picker_spec.rb +70 -0
  92. metadata +8 -2
@@ -33,12 +33,12 @@ class Shoes
33
33
  @contents.clear
34
34
  end
35
35
 
36
- def inspect
37
- super.insert(-2, " @size=#{size} @prepending=#{@prepending} @prepending_index=#{@prepending_index}")
38
- end
39
-
40
36
  private
41
37
 
38
+ def inspect_details
39
+ " @size=#{size} @prepending=#{@prepending} @prepending_index=#{@prepending_index}"
40
+ end
41
+
42
42
  def append_element(element)
43
43
  @contents << element
44
44
  end
data/lib/shoes/star.rb CHANGED
@@ -1,17 +1,15 @@
1
1
  class Shoes
2
2
  class Star
3
3
  include Common::UIElement
4
+ include Common::Fill
5
+ include Common::Stroke
4
6
  include Common::Style
5
7
  include Common::Clickable
6
8
 
7
- attr_reader :app, :parent, :dimensions, :gui
8
9
  style_with :angle, :art_styles, :common_styles, :dimensions, :inner, :outer, :points
9
- STYLES = { angle: 0 }
10
-
11
- def initialize(app, parent, left, top, points, outer, inner, styles = {}, blk = nil)
12
- @app = app
13
- @parent = parent
10
+ STYLES = { angle: 0, fill: Shoes::COLORS[:black] }
14
11
 
12
+ def create_dimensions(left, top, points, outer, inner)
15
13
  # Don't use param defaults as DSL explicit passes nil for missing params
16
14
  points ||= 10
17
15
  outer ||= 100.0
@@ -28,16 +26,9 @@ class Shoes
28
26
  inner_dimensions = AbsoluteDimensions.new 0, 0, inner * 2, 0
29
27
 
30
28
  # Get actual outer/inner from the dimension to handle relative values
31
- outer = @dimensions.width / 2
32
- inner = inner_dimensions.width / 2
33
-
34
- # Now set style using adjust outer and inner
35
- style_init(styles, inner: inner, outer: outer, points: points)
36
-
37
- @parent.add_child self
38
- @gui = Shoes.backend_for self
39
-
40
- register_click blk
29
+ style[:outer] = @dimensions.width / 2
30
+ style[:inner] = inner_dimensions.width / 2
31
+ style[:points] = points
41
32
  end
42
33
 
43
34
  def in_bounds?(x, y)
data/lib/shoes/text.rb CHANGED
@@ -14,11 +14,13 @@ class Shoes
14
14
  end
15
15
 
16
16
  def app
17
- @parent.app
17
+ parent && parent.app
18
18
  end
19
19
 
20
- def inspect
21
- super.insert(-2, %( "#{self}"))
20
+ private
21
+
22
+ def inspect_details
23
+ " \"#{self}\""
22
24
  end
23
25
  end
24
26
  end
@@ -8,24 +8,21 @@ class Shoes
8
8
  include Common::Clickable
9
9
  include TextBlockDimensionsDelegations
10
10
 
11
- attr_reader :gui, :parent, :text, :contents, :app, :text_styles, :dimensions
11
+ attr_reader :text, :contents, :text_styles
12
12
  attr_accessor :cursor, :textcursor
13
+
13
14
  style_with :common_styles, :dimensions, :text_block_styles
14
- STYLES = { font: "Arial" } # used in TextBlock specs only
15
+ STYLES = { font: DEFAULT_TEXTBLOCK_FONT } # used in TextBlock specs only
16
+
17
+ def create_dimensions(*_)
18
+ @dimensions = TextBlockDimensions.new @parent, @style
19
+ end
15
20
 
16
- def initialize(app, parent, text, styles = {})
17
- @parent = parent
18
- @app = app
19
- style_init styles
20
- @dimensions = TextBlockDimensions.new parent, @style
21
+ def after_initialize(text)
21
22
  handle_styles @style
22
- @gui = Shoes.backend_for self
23
- @parent.add_child self
24
23
 
25
24
  # Important to use accessor and do this after the backend exists!
26
25
  self.text = Array(text)
27
-
28
- register_click
29
26
  end
30
27
 
31
28
  def in_bounds?(*args)
@@ -37,6 +34,12 @@ class Shoes
37
34
  end
38
35
 
39
36
  def replace(*texts)
37
+ opts = texts.pop if texts.last.is_a?(Hash)
38
+ if opts
39
+ style(opts)
40
+ handle_styles(opts)
41
+ end
42
+
40
43
  # Order here matters as well--backend#replace shouldn't rely on DSL state
41
44
  # but the texts that it's passed if it needs information at this point.
42
45
  @gui.replace(*texts)
@@ -62,7 +65,7 @@ class Shoes
62
65
  @textcursor ||= app.textcursor(line_height)
63
66
  end
64
67
 
65
- def has_textcursor?
68
+ def textcursor?
66
69
  @textcursor
67
70
  end
68
71
 
@@ -71,9 +74,7 @@ class Shoes
71
74
  end
72
75
 
73
76
  def links
74
- return [] unless @contents
75
-
76
- @contents.select do |element|
77
+ contents.to_a.select do |element|
77
78
  element.is_a?(Shoes::Link)
78
79
  end
79
80
  end
@@ -135,7 +136,7 @@ class Shoes
135
136
  "Inscription" => { size: 10 }
136
137
  }.each do |name, styles|
137
138
  clazz = Class.new(TextBlock) do
138
- const_set("STYLES", { font: "Arial", fill: nil }.merge(styles))
139
+ const_set("STYLES", { font: DEFAULT_TEXTBLOCK_FONT, fill: nil }.merge(styles))
139
140
  end
140
141
  Shoes.const_set(name, clazz)
141
142
  end
@@ -31,7 +31,7 @@ class Shoes
31
31
 
32
32
  # This is the width the text block initially wants to try and fit into.
33
33
  def desired_width(containing = containing_width)
34
- parent.absolute_left + containing - absolute_left
34
+ parent.absolute_left + containing - absolute_left - margin_left - margin_right
35
35
  end
36
36
 
37
37
  # If an explicit width's set, use that when asking how much space we need.
data/lib/shoes/ui/cli.rb CHANGED
@@ -5,7 +5,11 @@ class Shoes
5
5
  class CLI
6
6
  attr_reader :packager
7
7
 
8
- def initialize
8
+ def initialize(backend)
9
+ $LOAD_PATH.unshift(Dir.pwd)
10
+ backend_const = Shoes.load_backend(backend)
11
+ backend_const.initialize_backend
12
+
9
13
  @packager = Shoes::Packager.new
10
14
  end
11
15
 
@@ -33,6 +37,12 @@ Usage: #{opts.program_name} [-h] [-p package] file
33
37
  exit
34
38
  end
35
39
 
40
+ opts.on('-b', '--backend [BACKEND]', 'Select a Shoes backend') do |backend|
41
+ require 'shoes/ui/picker'
42
+ Shoes::UI::Picker.new.run(ENV["SHOES_BIN_DIR"], backend)
43
+ exit
44
+ end
45
+
36
46
  opts.separator @packager.help(opts.program_name)
37
47
  end
38
48
 
@@ -43,9 +53,8 @@ Usage: #{opts.program_name} [-h] [-p package] file
43
53
  # Execute a shoes app.
44
54
  #
45
55
  # @param [String] app the location of the app to run
56
+ # @param [String] backend name of backend to load with the app
46
57
  def execute_app(app)
47
- $LOAD_PATH.unshift(Dir.pwd)
48
- require 'shoes/swt'
49
58
  load app
50
59
  end
51
60
 
@@ -3,38 +3,83 @@ class Shoes
3
3
  # This class is used for interactively (if necessary) picking the Shoes
4
4
  # backend that the user will run their Shoes app with.
5
5
  class Picker
6
- def run
6
+ def initialize(input=STDIN, output=STDOUT)
7
+ @input = input
8
+ @output = output
9
+ end
10
+
11
+ def run(bin_dir, desired_backend=nil)
7
12
  bundle
8
- generator_file = select_generator
9
- write_backend(generator_file)
13
+ generator_file = select_generator(desired_backend)
14
+ write_backend(generator_file, bin_dir)
10
15
  end
11
16
 
12
17
  # Only bundle if we find a local Gemfile. This allows us to work properly
13
- # running from source without finding gem-nstalled backends.
18
+ # running from source without finding gem-installed backends.
14
19
  def bundle
15
- if File.exist?("Gemfile")
16
- require 'bundler/setup'
17
- Bundler.require
18
- end
20
+ return unless File.exist?("Gemfile")
21
+
22
+ # Only need bundler/setup to get our paths right--we don't need to
23
+ # actually require the gems, since we find the generate-backend.rb's
24
+ # and just require them directly.
25
+ require 'bundler/setup'
19
26
  end
20
27
 
21
- def select_generator
22
- puts "Selecting Shoes backend to use. This is a one-time operation."
23
- candidates = Gem.find_files("shoes/**/generate-backend.rb")
24
- if candidates.one?
25
- generator_file = candidates.first
28
+ def select_generator(desired_backend=nil)
29
+ candidates = find_candidates(desired_backend)
30
+
31
+ if candidates.empty?
32
+ raise ArgumentError.new("No gems found matching '#{desired_backend}'")
33
+ elsif candidates.one?
34
+ candidate = candidates.first
35
+ @output.puts "Selecting #{name_for_candidate(candidate)} backend to use. This is a one-time operation."
36
+ candidate
26
37
  else
27
- fail NotImplementedError("Currently can't interactively select a backend. See #929")
38
+ candidates.sort!
39
+ output_candidates(candidates)
40
+ prompt_for_candidate(candidates)
28
41
  end
42
+ end
29
43
 
30
- generator_file
44
+ def find_candidates(desired_backend)
45
+ search_string = "shoes/**/#{desired_backend}/generate-backend.rb"
46
+ search_string.gsub!("//", "/")
47
+ Gem.find_files(search_string)
31
48
  end
32
49
 
33
- def write_backend(generator_file)
34
- require generator_file
50
+ def output_candidates(candidates)
51
+ @output.puts
52
+ @output.puts "Enter a number to select a Shoes backend (This is a one-time operation):"
35
53
 
36
- # On Windows getting odd paths with trailing double-quote
37
- bin_dir = ARGV[0].gsub('"', '')
54
+ candidates.each_with_index do |candidate, index|
55
+ @output.puts " #{index + 1}. #{name_for_candidate(candidate)}"
56
+ end
57
+
58
+ @output.print "> "
59
+ end
60
+
61
+ def prompt_for_candidate(candidates)
62
+ candidate = nil
63
+
64
+ until candidate
65
+ entered_index = @input.readline.to_i
66
+ if entered_index > 0
67
+ candidate = candidates[entered_index - 1]
68
+ break if candidate
69
+ end
70
+ @output.puts "Invalid selection. Try again with a number from 1 to #{candidates.size}."
71
+ end
72
+
73
+ candidate
74
+ end
75
+
76
+ def name_for_candidate(candidate)
77
+ /.*lib\/shoes\/(.*)\/generate-backend.rb/.match(candidate)
78
+ return "shoes-#{$1.gsub("/", "-")}"
79
+ end
80
+
81
+ def write_backend(generator_file, bin_dir)
82
+ require generator_file
38
83
 
39
84
  File.open(File.expand_path(File.join(bin_dir, "shoes-backend")), "w") do |file|
40
85
  # Contract with backends is to define generate_backend method that we
data/lib/shoes/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Shoes
2
- VERSION = "4.0.0.pre3"
2
+ VERSION = "4.0.0.pre4"
3
3
  end
data/shoes-core.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Team Shoes"]
9
9
  s.email = ["shoes@librelist.com"]
10
10
  s.homepage = "https://github.com/shoes/shoes4"
11
- s.summary = %q{The best little DSL for the best little GUI toolkit for Ruby.}
12
- s.description = %q{Shoes is the best little GUI toolkit for Ruby. Shoes makes building for Mac, Windows, and Linux super simple. This is the DSL for writing your app. You'll need a backend to run it.}
11
+ s.summary = 'The best little DSL for the best little GUI toolkit for Ruby.'
12
+ s.description = "Shoes is the best little GUI toolkit for Ruby. Shoes makes building for Mac, Windows, and Linux super simple. This is the DSL for writing your app. You'll need a backend to run it."
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files`.split($/)
@@ -37,7 +37,7 @@ describe Shoes::Animation do
37
37
  let(:opts) { {} }
38
38
  let(:block) { double('block') }
39
39
  let(:bound_block) { double('bound block') }
40
- subject { Shoes::Animation.new( app, opts, block ) }
40
+ subject { Shoes::Animation.new(app, opts, block) }
41
41
 
42
42
  before :each do
43
43
  expect(app).to receive(:gui) { app_gui }
@@ -58,7 +58,7 @@ describe Shoes::App do
58
58
  end
59
59
 
60
60
  it "shows title in #inspect" do
61
- expect(subject.inspect).to match("(Shoes::App:#{shoes_object_id_pattern} \"#{defaults.fetch :title}\")")
61
+ expect(subject.inspect).to match(/\(Shoes::App:#{shoes_object_id_pattern} "#{defaults.fetch :title}"\)/)
62
62
  end
63
63
  end
64
64
  end
@@ -81,8 +81,8 @@ describe Shoes::App do
81
81
 
82
82
  it 'initializes a flow with the right parameters' do
83
83
  expect(Shoes::Flow).to receive(:new).with(anything, anything,
84
- {width: opts[:width],
85
- height: opts[:height]}).
84
+ width: opts[:width],
85
+ height: opts[:height]).
86
86
  and_call_original
87
87
  subject
88
88
  end
@@ -283,25 +283,6 @@ describe Shoes::App do
283
283
  end
284
284
  end
285
285
 
286
- describe "#gutter" do
287
- context "when app has a scrollbar" do
288
- let(:input_opts) { {width: 100, height: 100} }
289
- let(:input_block) { Proc.new { para "Round peg, square hole" * 200 } }
290
-
291
- it "has gutter of 16" do
292
- expect(app.gutter).to be_within(2).of(16)
293
- end
294
- end
295
-
296
- context "when app has no scrollbar" do
297
- let(:input_block) { Proc.new { para "Round peg, square hole" } }
298
-
299
- it "has gutter of 16" do
300
- expect(app.gutter).to be_within(2).of(16)
301
- end
302
- end
303
- end
304
-
305
286
  describe "#parent" do
306
287
  context "for a top-level element (not explicitly in a slot)" do
307
288
  it "returns the top_slot" do
@@ -319,7 +300,7 @@ describe Shoes::App do
319
300
  it "returns the enclosing slot" do
320
301
  my_parent = nil
321
302
  my_stack = nil
322
- app = Shoes.app do
303
+ Shoes.app do
323
304
  my_stack = stack do
324
305
  flow do
325
306
  my_parent = parent
@@ -238,6 +238,17 @@ describe Shoes::Color do
238
238
  expect(green).to eq green
239
239
  end
240
240
 
241
+ # shoes 3 compatibility behavior
242
+ describe 'different colors' do
243
+ it 'takes the total of rgb values to compare, less is less' do
244
+ expect(create_rgb 100, 200, 0).to be < create_rgb(50, 100, 151)
245
+ end
246
+
247
+ it 'takes the total of rgb values to compare, more is more' do
248
+ expect(create_rgb 0, 200, 200).to be > create_rgb(150, 150, 99)
249
+ end
250
+ end
251
+
241
252
  context "same rgb values" do
242
253
  let(:color_2) { Shoes::Color.new(255, 69, 0, 254) }
243
254
  it "is less than when less opaque" do
@@ -250,6 +261,10 @@ describe Shoes::Color do
250
261
  end
251
262
  end
252
263
  end
264
+
265
+ def create_rgb(r, g, b)
266
+ Shoes::Color.new r, g, b
267
+ end
253
268
  end
254
269
 
255
270
  describe "Shoes built-in colors" do
@@ -284,7 +299,7 @@ describe "Shoes built in gray" do
284
299
  end
285
300
 
286
301
  specify "float parameters should be normalised" do
287
- expect(app.gray(1.0, 0.5)).to eq(Shoes::Color.new( 255, 255, 255, 128 ))
302
+ expect(app.gray(1.0, 0.5)).to eq(Shoes::Color.new(255, 255, 255, 128))
288
303
  end
289
304
 
290
305
  it 'hangles 0.93 right as well' do
@@ -13,7 +13,7 @@ describe Shoes::Common::StyleNormalizer do
13
13
  expected = {fill: Shoes::Color.new(255, 255, 255)}
14
14
  expect(subject.normalize input).to eq expected
15
15
  end
16
-
16
+
17
17
  it 'turns hexcodes for stroke into colors' do
18
18
  input = {stroke: 'ffffff'}
19
19
  expected = {stroke: Shoes::Color.new(255, 255, 255)}
@@ -23,6 +23,6 @@ describe Shoes::Common::StyleNormalizer do
23
23
  it 'does not modify the original hash' do
24
24
  input = {stroke: '333333'}
25
25
  subject.normalize input
26
- expect(input).to eq({stroke: '333333'})
26
+ expect(input).to eq(stroke: '333333')
27
27
  end
28
- end
28
+ end
@@ -5,15 +5,22 @@ describe Shoes::Common::Style do
5
5
  let(:blue) { Shoes::COLORS[:blue] }
6
6
 
7
7
  class StyleTester
8
+ include Shoes::Common::Visibility
9
+ include Shoes::DimensionsDelegations
8
10
  include Shoes::Common::Style
9
- attr_accessor :left
11
+
12
+ attr_reader :dimensions
10
13
  style_with :key, :left, :click, :strokewidth, :fill
14
+
11
15
  STYLES = {fill: Shoes::COLORS[:blue]}
12
16
 
13
17
  def initialize(app, styles = {})
14
18
  @app = app #needed for style init
19
+ @dimensions = Shoes::Dimensions.new(@app, left: 15)
20
+
21
+ # Would normally be done by Common::Initialization
15
22
  style_init(styles, key: 'value')
16
- @left = 15
23
+ update_dimensions
17
24
  end
18
25
 
19
26
  def click(&arg)
@@ -23,17 +30,21 @@ describe Shoes::Common::Style do
23
30
  def click_blk
24
31
  @click
25
32
  end
33
+
34
+ def update_visibility
35
+ end
26
36
  end
37
+
27
38
  subject {StyleTester.new(app)}
28
39
 
29
- its(:style) { should eq (initial_style) }
30
- let(:initial_style) { {key: 'value', left: 15, click: nil, strokewidth: 1, fill: blue} }
40
+ its(:style) { should eq(initial_style) }
41
+ let(:initial_style) { {key: 'value', left: 15, click: nil, strokewidth: 1, fill: blue,
42
+ margin: [0,0,0,0], margin_left: 0, margin_top: 0, margin_right: 0, margin_bottom: 0 } }
31
43
 
32
44
  describe 'reading and writing through #style(hash)' do
33
45
  let(:input_proc) { Proc.new {} }
34
46
  let(:changed_style) { {key: 'changed value'} }
35
47
 
36
-
37
48
  before :each do
38
49
  subject.style changed_style
39
50
  end
@@ -57,6 +68,16 @@ describe Shoes::Common::Style do
57
68
  expect(subject.left).to eq 200
58
69
  end
59
70
 
71
+ it 'reads visibility' do
72
+ subject.hide
73
+ expect(subject.style[:hidden]).to be true
74
+ end
75
+
76
+ it 'writes visibility' do
77
+ subject.style(hidden: true)
78
+ expect(subject.hidden?).to be true
79
+ end
80
+
60
81
  it 'sets click' do
61
82
  subject.style(click: input_proc)
62
83
  expect(subject.click_blk).to eq input_proc
@@ -117,6 +138,7 @@ describe Shoes::Common::Style do
117
138
 
118
139
  describe "style priorities" do
119
140
  subject {StyleTester.new(app, key: 'pumpkin')}
141
+ let(:green) { Shoes::COLORS[:green] }
120
142
 
121
143
  it 'uses arguments-styles over element-styles' do
122
144
  expect(subject.key).to eq 'pumpkin'
@@ -126,6 +148,21 @@ describe Shoes::Common::Style do
126
148
  expect(subject.fill).to eq blue
127
149
  end
128
150
 
151
+ describe "with app level styles applied" do
152
+ let(:app) { Shoes::App.new}
153
+
154
+ it "should override class level defaults with app level styles provided those app styles are supported by the class" do
155
+ app.style(fill: green)
156
+ expect(app.line(0, 0, 10, 10).fill).to eq green
157
+ end
158
+
159
+ it "should not override class level defaults with app level styles for already instanciated objects" do
160
+ line_instance = app.line(0, 0, 10, 10)
161
+ app.style(fill: green)
162
+ expect(line_instance.fill).not_to eq green
163
+ end
164
+ end
165
+
129
166
  #related priority specs are tested individually in spec/shared_examples/style
130
167
  end
131
168
 
@@ -307,9 +307,8 @@ describe Shoes::Dimension do
307
307
  it {is_expected.to be_in_bounds 105}
308
308
  it {is_expected.to be_in_bounds 20.021}
309
309
  it {is_expected.not_to be_in_bounds absolute_end + ONE_PIXEL}
310
- it {is_expected.not_to be_in_bounds absolute_start - ONE_PIXEL
311
- }
312
- it {is_expected.not_to be_in_bounds -5}
310
+ it {is_expected.not_to be_in_bounds absolute_start - ONE_PIXEL }
311
+ it {is_expected.not_to be_in_bounds(-5)}
313
312
  it {is_expected.not_to be_in_bounds 0}
314
313
  it {is_expected.not_to be_in_bounds 150}
315
314
  it {is_expected.not_to be_in_bounds 123178}
@@ -334,12 +333,12 @@ describe Shoes::Dimension do
334
333
 
335
334
  it 'parses negative values' do
336
335
  subject.start = '-13'
337
- expect(subject.start).to eq -13
336
+ expect(subject.start).to eq(-13)
338
337
  end
339
338
 
340
339
  it 'even parses negative values with px' do
341
340
  subject.start = '-22px'
342
- expect(subject.start).to eq -22
341
+ expect(subject.start).to eq(-22)
343
342
  end
344
343
 
345
344
  it 'returns nil for unknown values' do
@@ -397,7 +396,7 @@ describe Shoes::Dimension do
397
396
 
398
397
  it 'can still handle special values like a negative extent' do
399
398
  subject.extent = -10
400
- expect(subject.extent).to eq (parent_extent - 2 * margin) - 10
399
+ expect(subject.extent).to eq(parent_extent - 2 * margin - 10)
401
400
  end
402
401
 
403
402
  it 'can also still handle special values like relative values' do
@@ -430,4 +429,3 @@ describe Shoes::Dimension do
430
429
  end
431
430
 
432
431
  end
433
-
@@ -211,10 +211,10 @@ describe Shoes::Dimensions do
211
211
  let(:parent_height) {300}
212
212
  subject {Shoes::Dimensions.new parent, "- 100", "-20px", "- 50px", "- 80"}
213
213
 
214
- its(:left) {should eq -100}
215
- its(:top) {should eq -20}
216
- its(:width) {should eq (parent_width - 50)}
217
- its(:height) {should eq (parent_height - 80)}
214
+ its(:left) {should eq(-100)}
215
+ its(:top) {should eq(-20)}
216
+ its(:width) {should eq(parent_width - 50)}
217
+ its(:height) {should eq(parent_height - 80)}
218
218
  end
219
219
  end
220
220
 
@@ -553,12 +553,12 @@ describe Shoes::Dimensions do
553
553
  subject.margin_right = 7
554
554
  expect(subject.margin).to eq([margin, margin, 7, margin])
555
555
  end
556
-
556
+
557
557
  it 'adapts margins when margin is changed with single value' do
558
558
  subject.margin = 7
559
559
  expect(subject.margin).to eq([7, 7, 7, 7])
560
560
  end
561
-
561
+
562
562
  it 'adapts margin when margin is changed with array' do
563
563
  subject.margin = [7, 7, 7, 7]
564
564
  expect(subject.margin).to eq([7, 7, 7, 7])
@@ -759,7 +759,7 @@ describe Shoes::Dimensions do
759
759
 
760
760
  it 'can also still handle special values like a negative width' do
761
761
  subject.width = -10
762
- expect(subject.width).to eq (parent.width - 10)
762
+ expect(subject.width).to eq(parent.width - 10)
763
763
  end
764
764
 
765
765
  it 'can also still handle special values like a relative height' do