reflexion 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.doc/ext/reflex/application.cpp +54 -39
- data/.doc/ext/reflex/capture_event.cpp +87 -0
- data/.doc/ext/reflex/draw_event.cpp +103 -0
- data/.doc/ext/reflex/event.cpp +73 -0
- data/.doc/ext/reflex/focus_event.cpp +98 -0
- data/.doc/ext/reflex/frame_event.cpp +133 -0
- data/.doc/ext/reflex/image_view.cpp +74 -0
- data/.doc/ext/reflex/key_event.cpp +124 -0
- data/.doc/ext/reflex/native.cpp +45 -6
- data/.doc/ext/reflex/pointer_event.cpp +181 -0
- data/.doc/ext/reflex/reflex.cpp +17 -41
- data/.doc/ext/reflex/scroll_event.cpp +141 -0
- data/.doc/ext/reflex/selector.cpp +135 -0
- data/.doc/ext/reflex/style.cpp +253 -0
- data/.doc/ext/reflex/style_length.cpp +133 -0
- data/.doc/ext/reflex/style_length2.cpp +149 -0
- data/.doc/ext/reflex/style_length4.cpp +192 -0
- data/.doc/ext/reflex/update_event.cpp +77 -0
- data/.doc/ext/reflex/view.cpp +408 -88
- data/.doc/ext/reflex/wheel_event.cpp +146 -0
- data/.doc/ext/reflex/window.cpp +95 -92
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +67 -49
- data/ext/reflex/capture_event.cpp +92 -0
- data/ext/reflex/draw_event.cpp +110 -0
- data/ext/reflex/event.cpp +77 -0
- data/ext/reflex/extconf.rb +18 -68
- data/ext/reflex/focus_event.cpp +104 -0
- data/ext/reflex/frame_event.cpp +143 -0
- data/ext/reflex/image_view.cpp +77 -0
- data/ext/reflex/key_event.cpp +133 -0
- data/ext/reflex/native.cpp +45 -6
- data/ext/reflex/pointer_event.cpp +195 -0
- data/ext/reflex/reflex.cpp +21 -47
- data/ext/reflex/scroll_event.cpp +152 -0
- data/ext/reflex/selector.cpp +144 -0
- data/ext/reflex/style.cpp +277 -0
- data/ext/reflex/style_length.cpp +140 -0
- data/ext/reflex/style_length2.cpp +157 -0
- data/ext/reflex/style_length4.cpp +204 -0
- data/ext/reflex/update_event.cpp +81 -0
- data/ext/reflex/view.cpp +469 -114
- data/ext/reflex/wheel_event.cpp +158 -0
- data/ext/reflex/window.cpp +130 -123
- data/include/reflex/application.h +12 -7
- data/include/reflex/defs.h +13 -89
- data/include/reflex/event.h +260 -0
- data/include/reflex/exception.h +17 -11
- data/include/reflex/image_view.h +45 -0
- data/include/reflex/reflex.h +2 -6
- data/include/reflex/ruby/application.h +40 -13
- data/include/reflex/ruby/event.h +72 -0
- data/include/reflex/ruby/image_view.h +25 -0
- data/include/reflex/ruby/selector.h +27 -0
- data/include/reflex/ruby/style.h +27 -0
- data/include/reflex/ruby/style_length.h +37 -0
- data/include/reflex/ruby/view.h +193 -38
- data/include/reflex/ruby/window.h +123 -39
- data/include/reflex/ruby.h +3 -2
- data/include/reflex/selector.h +64 -0
- data/include/reflex/style.h +144 -0
- data/include/reflex/style_length.h +147 -0
- data/include/reflex/view.h +182 -19
- data/include/reflex/window.h +35 -19
- data/include/reflex.h +7 -0
- data/lib/reflex/application.rb +14 -5
- data/lib/reflex/arc_shape.rb +20 -0
- data/lib/reflex/button.rb +75 -0
- data/lib/reflex/capture_event.rb +37 -0
- data/lib/reflex/color.rb +13 -0
- data/lib/reflex/color_space.rb +13 -0
- data/lib/reflex/draw_event.rb +19 -0
- data/lib/reflex/ellipse_shape.rb +20 -0
- data/lib/reflex/ext.rb +1 -1
- data/lib/reflex/flags.rb +18 -0
- data/lib/reflex/focus_event.rb +38 -0
- data/lib/reflex/font.rb +13 -0
- data/lib/reflex/frame_event.rb +42 -0
- data/lib/reflex/helper.rb +87 -30
- data/lib/reflex/image_view.rb +25 -0
- data/lib/reflex/key_event.rb +38 -0
- data/lib/reflex/line_shape.rb +20 -0
- data/lib/reflex/list_view.rb +15 -0
- data/lib/reflex/model.rb +149 -0
- data/lib/reflex/model_owner.rb +57 -0
- data/lib/reflex/model_view.rb +22 -0
- data/lib/reflex/module.rb +11 -7
- data/lib/reflex/pointer_event.rb +85 -0
- data/lib/reflex/rect_shape.rb +20 -0
- data/lib/reflex/reflex.rb +13 -2
- data/lib/reflex/scroll_event.rb +19 -0
- data/lib/reflex/selector.rb +31 -0
- data/lib/reflex/shader.rb +13 -0
- data/lib/reflex/shape.rb +34 -0
- data/lib/reflex/style.rb +55 -0
- data/lib/reflex/style_length.rb +30 -0
- data/lib/reflex/style_length2.rb +34 -0
- data/lib/reflex/style_length4.rb +38 -0
- data/lib/reflex/text_view.rb +55 -0
- data/lib/reflex/update_event.rb +19 -0
- data/lib/reflex/view.rb +38 -4
- data/lib/reflex/wheel_event.rb +19 -0
- data/lib/reflex/window.rb +7 -5
- data/lib/reflex.rb +38 -1
- data/lib/reflexion/include.rb +5 -0
- data/lib/reflexion.rb +100 -0
- data/reflex.gemspec +3 -4
- data/samples/app.rb +13 -0
- data/samples/bats.rb +91 -0
- data/samples/checker.rb +36 -0
- data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
- data/samples/fps.rb +46 -0
- data/samples/grid.rb +60 -0
- data/{examples/ruby → samples}/hello.rb +14 -16
- data/samples/image.rb +44 -0
- data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
- data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/ios/hello/hello/hello-Info.plist +47 -0
- data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
- data/samples/ios/hello/hello/main.cpp +79 -0
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/{examples/ruby → samples}/key.rb +11 -14
- data/samples/layout.rb +89 -0
- data/samples/model.rb +86 -0
- data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
- data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
- data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/osx/hello/hello/hello-Info.plist +32 -0
- data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
- data/samples/osx/hello/hello/main.cpp +79 -0
- data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/samples/reflexion/hello.rb +24 -0
- data/samples/reflexion/paint.rb +40 -0
- data/samples/reflexion/pulse.rb +34 -0
- data/samples/repl.rb +69 -0
- data/samples/shader.rb +41 -0
- data/samples/shapes.rb +30 -0
- data/{examples/ruby → samples}/text.rb +7 -8
- data/samples/tree.rb +71 -0
- data/samples/views.rb +41 -0
- data/samples/visuals.rb +22 -0
- data/src/event.cpp +225 -0
- data/src/exception.cpp +24 -15
- data/src/image_view.cpp +70 -0
- data/src/ios/app_delegate.h +17 -0
- data/src/ios/app_delegate.mm +120 -0
- data/src/ios/application.mm +116 -0
- data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
- data/src/ios/event.h +26 -0
- data/src/ios/event.mm +31 -0
- data/src/ios/native_window.h +37 -0
- data/src/ios/native_window.mm +220 -0
- data/src/ios/opengl_view.h +13 -0
- data/src/ios/opengl_view.mm +131 -0
- data/src/{cocoa → ios}/reflex.mm +8 -12
- data/src/ios/window.mm +303 -0
- data/src/ios/window_data.h +75 -0
- data/src/osx/app_delegate.h +17 -0
- data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
- data/src/osx/application.mm +132 -0
- data/src/osx/application_data.h +45 -0
- data/src/osx/event.h +42 -0
- data/src/osx/event.mm +112 -0
- data/src/osx/native_window.h +26 -0
- data/src/osx/native_window.mm +322 -0
- data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
- data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
- data/src/osx/reflex.mm +50 -0
- data/src/osx/window.mm +308 -0
- data/src/osx/window_data.h +75 -0
- data/src/selector.cpp +121 -0
- data/src/style.cpp +576 -0
- data/src/style_length.cpp +341 -0
- data/src/view.cpp +1228 -129
- data/src/win32/application.cpp +1 -1
- data/src/window.cpp +54 -26
- data/test/helper.rb +8 -4
- data/test/test_capture_event.rb +41 -0
- data/test/test_event.rb +20 -0
- data/test/test_has_frame.rb +45 -0
- data/test/test_model.rb +9 -0
- data/test/test_model_owner.rb +9 -0
- data/test/test_selector.rb +75 -0
- data/test/test_style.rb +70 -0
- data/test/test_style_length.rb +38 -0
- data/test/test_style_length2.rb +50 -0
- data/test/test_style_length4.rb +56 -0
- data/test/test_view.rb +97 -23
- data/test/test_window.rb +54 -46
- metadata +205 -84
- data/.doc/ext/reflex/defs.cpp +0 -8
- data/.doc/ext/reflex/key.cpp +0 -122
- data/.doc/ext/reflex/points.cpp +0 -151
- data/.gitignore +0 -14
- data/ChangeLog +0 -8
- data/examples/hello/.gitignore +0 -2
- data/examples/hello/Rakefile +0 -41
- data/examples/hello/main.cpp +0 -18
- data/examples/ruby/app.rb +0 -13
- data/examples/ruby/checker.rb +0 -41
- data/examples/ruby/fps.rb +0 -49
- data/examples/ruby/grid.rb +0 -65
- data/examples/ruby/views.rb +0 -88
- data/examples/ruby/visuals.rb +0 -27
- data/ext/reflex/defs.cpp +0 -8
- data/ext/reflex/key.cpp +0 -129
- data/ext/reflex/points.cpp +0 -161
- data/include/reflex/ruby/key.h +0 -39
- data/include/reflex/ruby/points.h +0 -39
- data/lib/reflex/visuals/string.rb +0 -53
- data/src/cocoa/application.mm +0 -101
- data/src/cocoa/cocoaapplication.h +0 -21
- data/src/cocoa/cocoawindow.h +0 -46
- data/src/cocoa/cocoawindow.mm +0 -230
- data/src/cocoa/defs.h +0 -34
- data/src/cocoa/defs.mm +0 -87
- data/src/cocoa/window.mm +0 -148
- data/src/cocoa/windowdata.h +0 -56
- data/src/defs.cpp +0 -47
- data/src/helper.h +0 -12
- data/src/reflex.cpp +0 -43
- /data/{README → README.md} +0 -0
data/src/win32/application.cpp
CHANGED
data/src/window.cpp
CHANGED
@@ -3,16 +3,17 @@
|
|
3
3
|
|
4
4
|
#include <rays/bounds.h>
|
5
5
|
#include <rays/painter.h>
|
6
|
-
#include
|
6
|
+
#include "reflex/view.h"
|
7
|
+
#include "reflex/exception.h"
|
7
8
|
|
8
9
|
|
9
10
|
namespace Reflex
|
10
11
|
{
|
11
12
|
|
12
13
|
|
13
|
-
void update_view_tree (View* v,
|
14
|
+
void update_view_tree (View* v, const UpdateEvent& e);
|
14
15
|
|
15
|
-
void draw_view_tree (View* v,
|
16
|
+
void draw_view_tree (View* v, const DrawEvent& e, const Point& offset, const Bounds& clip);
|
16
17
|
|
17
18
|
|
18
19
|
const View*
|
@@ -21,70 +22,97 @@ namespace Reflex
|
|
21
22
|
return const_cast<Window*>(this)->root();
|
22
23
|
}
|
23
24
|
|
25
|
+
const View*
|
26
|
+
Window::focus () const
|
27
|
+
{
|
28
|
+
return const_cast<Window*>(this)->focus();
|
29
|
+
}
|
30
|
+
|
24
31
|
const Painter*
|
25
32
|
Window::painter () const
|
26
33
|
{
|
27
34
|
return const_cast<Window*>(this)->painter();
|
28
35
|
}
|
29
36
|
|
30
|
-
|
31
|
-
Window::
|
37
|
+
Rays::Point
|
38
|
+
Window::from_screen (const Rays::Point& point) const
|
32
39
|
{
|
33
|
-
|
40
|
+
not_implemented_error(__FILE__, __LINE__);
|
41
|
+
return 0;
|
34
42
|
}
|
35
43
|
|
36
|
-
|
37
|
-
Window::
|
44
|
+
Rays::Point
|
45
|
+
Window::to_screen (const Rays::Point& point) const
|
38
46
|
{
|
39
|
-
|
40
|
-
|
47
|
+
not_implemented_error(__FILE__, __LINE__);
|
48
|
+
return 0;
|
49
|
+
}
|
41
50
|
|
42
|
-
|
43
|
-
|
51
|
+
void
|
52
|
+
Window::on_update (UpdateEvent* e)
|
53
|
+
{
|
54
|
+
if (!e)
|
55
|
+
argument_error(__FILE__, __LINE__);
|
44
56
|
|
45
|
-
|
46
|
-
draw_view_tree(v, p, 0, 0);
|
47
|
-
p->end();
|
57
|
+
update_view_tree(root(), *e);
|
48
58
|
}
|
49
59
|
|
50
60
|
void
|
51
|
-
Window::
|
61
|
+
Window::on_draw (DrawEvent* e)
|
52
62
|
{
|
63
|
+
if (!e)
|
64
|
+
argument_error(__FILE__, __LINE__);
|
65
|
+
|
66
|
+
draw_view_tree(root(), *e, 0, frame().dup().move_to(0));
|
53
67
|
}
|
54
68
|
|
55
69
|
void
|
56
|
-
Window::
|
70
|
+
Window::on_move (FrameEvent* e)
|
57
71
|
{
|
58
|
-
|
59
|
-
|
72
|
+
if (!e)
|
73
|
+
argument_error(__FILE__, __LINE__);
|
74
|
+
}
|
60
75
|
|
61
|
-
|
62
|
-
|
76
|
+
void
|
77
|
+
Window::on_resize (FrameEvent* e)
|
78
|
+
{
|
79
|
+
if (!e)
|
80
|
+
argument_error(__FILE__, __LINE__);
|
63
81
|
}
|
64
82
|
|
65
83
|
void
|
66
|
-
Window::
|
84
|
+
Window::on_key_down (KeyEvent* e)
|
67
85
|
{
|
86
|
+
if (!e)
|
87
|
+
argument_error(__FILE__, __LINE__);
|
68
88
|
}
|
69
89
|
|
70
90
|
void
|
71
|
-
Window::
|
91
|
+
Window::on_key_up (KeyEvent* e)
|
72
92
|
{
|
93
|
+
if (!e)
|
94
|
+
argument_error(__FILE__, __LINE__);
|
73
95
|
}
|
74
96
|
|
75
97
|
void
|
76
|
-
Window::
|
98
|
+
Window::on_pointer_down (PointerEvent* e)
|
77
99
|
{
|
100
|
+
if (!e)
|
101
|
+
argument_error(__FILE__, __LINE__);
|
78
102
|
}
|
79
103
|
|
80
104
|
void
|
81
|
-
Window::
|
105
|
+
Window::on_pointer_up (PointerEvent* e)
|
82
106
|
{
|
107
|
+
if (!e)
|
108
|
+
argument_error(__FILE__, __LINE__);
|
83
109
|
}
|
84
110
|
|
85
111
|
void
|
86
|
-
Window::
|
112
|
+
Window::on_pointer_move (PointerEvent* e)
|
87
113
|
{
|
114
|
+
if (!e)
|
115
|
+
argument_error(__FILE__, __LINE__);
|
88
116
|
}
|
89
117
|
|
90
118
|
bool
|
data/test/helper.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
%w[../xot ../rucy ../rays .]
|
5
|
+
.map {|s| File.expand_path "../../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
6
7
|
|
7
8
|
require 'test/unit'
|
9
|
+
require 'xot/test'
|
8
10
|
require 'reflex'
|
9
11
|
|
12
|
+
include Xot::Test
|
13
|
+
|
10
14
|
|
11
15
|
unless $REFLEX_NOAUTOINIT
|
12
|
-
def Rays.fin! ()
|
13
|
-
def Reflex.fin! ()
|
16
|
+
def Rays.fin! () end
|
17
|
+
def Reflex.fin! () end
|
14
18
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestCaptureEvent < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def cap (*args)
|
10
|
+
Reflex::CaptureEvent.new *args.map {|arg| Reflex::CAPTURE_FLAG.symbols2bits *arg}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_begin ()
|
14
|
+
c = cap [:key, :pointer], []
|
15
|
+
assert_equal [:key, :pointer], c.begin
|
16
|
+
assert_equal true, c.begin?(:key)
|
17
|
+
assert_equal true, c.begin?(:pointer)
|
18
|
+
assert_equal true, c.begin?(:all)
|
19
|
+
|
20
|
+
c = cap [:key], []
|
21
|
+
assert_equal [:key], c.begin
|
22
|
+
assert_equal true, c.begin?(:key)
|
23
|
+
assert_equal false, c.begin?(:pointer)
|
24
|
+
assert_equal false, c.begin?(:all)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_end ()
|
28
|
+
c = cap [], [:key, :pointer]
|
29
|
+
assert_equal [:key, :pointer], c.end
|
30
|
+
assert_equal true, c.end?(:key)
|
31
|
+
assert_equal true, c.end?(:pointer)
|
32
|
+
assert_equal true, c.end?(:all)
|
33
|
+
|
34
|
+
c = cap [], [:key]
|
35
|
+
assert_equal [:key], c.end
|
36
|
+
assert_equal true, c.end?(:key)
|
37
|
+
assert_equal false, c.end?(:pointer)
|
38
|
+
assert_equal false, c.end?(:all)
|
39
|
+
end
|
40
|
+
|
41
|
+
end# TestCaptureEvent
|
data/test/test_event.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestEvent < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def event ()
|
10
|
+
Reflex::Event.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_block ()
|
14
|
+
e = event
|
15
|
+
assert_equal false, e.block?
|
16
|
+
e.block
|
17
|
+
assert_equal true, e.block?
|
18
|
+
end
|
19
|
+
|
20
|
+
end# TestEvent
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestHasFrame < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def view (*args)
|
10
|
+
Reflex::View.new *args
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_accessors ()
|
14
|
+
v = view
|
15
|
+
b = v.frame.dup
|
16
|
+
assert_equal b, v.frame
|
17
|
+
|
18
|
+
v.x = 10; assert_equal 10, v.x
|
19
|
+
v.y = 20; assert_equal 20, v.y
|
20
|
+
v.z = 30; assert_equal 30, v.z
|
21
|
+
|
22
|
+
v.width = 100; assert_equal 100, v.width
|
23
|
+
v.height = 200; assert_equal 200, v.height
|
24
|
+
v.depth = 300; assert_equal 300, v.depth
|
25
|
+
|
26
|
+
v.inset_by 5, 5
|
27
|
+
assert_equal [15, 25, 90, 190], v.frame.to_a
|
28
|
+
assert_equal [15, 25, 30, 90, 190, 300], v.frame.to_a(3)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_move ()
|
32
|
+
v = view
|
33
|
+
v.move_to 10, 10; assert_equal [10, 10], v.pos.to_a
|
34
|
+
v.move_by 40, 40; assert_equal [50, 50], v.pos.to_a
|
35
|
+
v.move_by -10, -10; assert_equal [40, 40], v.pos.to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_resize ()
|
39
|
+
v = view
|
40
|
+
v.resize_to 100, 100; assert_equal [100, 100], v.size.to_a
|
41
|
+
v.resize_by 400, 400; assert_equal [500, 500], v.size.to_a
|
42
|
+
v.resize_by -100, -100; assert_equal [400, 400], v.size.to_a
|
43
|
+
end
|
44
|
+
|
45
|
+
end# TestHasFrame
|
data/test/test_model.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestSelector < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def sel (*args, &block)
|
10
|
+
Reflex::Selector.new *args, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize ()
|
14
|
+
assert_equal 'A', sel(name: :A).name
|
15
|
+
assert_equal 'B', sel(name: :A){set name: :B}.name
|
16
|
+
assert_equal %w[T1], sel(tag: :T1 ).tags.to_a
|
17
|
+
assert_equal %w[T1 T2], sel(tag: [:T1, :T2]).tags.to_a
|
18
|
+
assert_equal %w[T1], sel(tags: :T1 ).tags.to_a
|
19
|
+
assert_equal %w[T1 T2], sel(tags: [:T1, :T2]).tags.to_a
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_name ()
|
23
|
+
s = sel
|
24
|
+
assert_equal nil, s.name
|
25
|
+
s.name = 'Test'
|
26
|
+
assert_equal 'Test', s.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_tags ()
|
30
|
+
s = sel
|
31
|
+
assert_equal [], s.tags.to_a
|
32
|
+
s.tag 'A'
|
33
|
+
assert_equal %w[A], s.tags.to_a
|
34
|
+
s.tag :B
|
35
|
+
assert_equal %w[A B], s.tags.to_a
|
36
|
+
s.tag :C, :D
|
37
|
+
assert_equal %w[A B C D], s.tags.to_a
|
38
|
+
s.untag :B, :C
|
39
|
+
assert_equal %w[A D], s.tags.to_a
|
40
|
+
assert_equal %w[a d], s.tags.map(&:downcase).to_a
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_clear_tags ()
|
44
|
+
s = sel tag: [:T1, :T2]
|
45
|
+
s.clear_tags
|
46
|
+
assert_equal [], s.tags.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_match ()
|
50
|
+
assert_not sel.match(sel name: :A, tag: :T)
|
51
|
+
assert sel(name: :A).match(sel name: :A)
|
52
|
+
assert_not sel(name: :A).match(sel name: :B)
|
53
|
+
assert sel(tag: :T1).match(sel tag: :T1)
|
54
|
+
assert_not sel(tag: :T1).match(sel tag: :T2)
|
55
|
+
assert sel(tag: :T1).match(sel tag: [:T1, :T2])
|
56
|
+
assert_not sel(tag: [:T1, :T2]).match(sel tag: :T1)
|
57
|
+
assert sel(name: :A, tag: :T1).match(sel name: :A, tag: :T1)
|
58
|
+
assert_not sel(name: :A, tag: :T1).match(sel name: :A)
|
59
|
+
assert_not sel(name: :A, tag: :T1).match(sel tag: :T1)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_compare ()
|
63
|
+
assert_equal sel(name: :A), sel(name: :A)
|
64
|
+
assert_not_equal sel(name: :A), sel(name: :X)
|
65
|
+
assert_equal sel(tag: [:A, :B]), sel(tag: [:A, :B])
|
66
|
+
assert_not_equal sel(tag: [:A, :B]), sel(tag: [:A, :X])
|
67
|
+
assert_equal sel(name: :A, tag: :B), sel(name: :A, tag: :B)
|
68
|
+
assert_not_equal sel(name: :A, tag: :B), sel(name: :X, tag: :B)
|
69
|
+
assert_not_equal sel(name: :A, tag: :B), sel(name: :A, tag: :X)
|
70
|
+
assert_equal sel(name: :A, tag: [:B, :C]), sel(name: :A, tag: [:B, :C])
|
71
|
+
assert_not_equal sel(name: :A, tag: :B), sel(name: :A, tag: [:B, :C])
|
72
|
+
assert_not_equal sel(name: :A, tag: [:B, :C]), sel(name: :A, tag: :B)
|
73
|
+
end
|
74
|
+
|
75
|
+
end# TestSelector
|
data/test/test_style.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestStyle < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def style (*args, &block)
|
10
|
+
Reflex::Style.new *args, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize ()
|
14
|
+
assert_equal nil, style.name
|
15
|
+
assert_equal 'A', style(name: :A).name
|
16
|
+
assert_equal 'A', style{self.name = :A}.name
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_selector ()
|
20
|
+
assert_equal 'A', style(name: :A).selector.name
|
21
|
+
assert_equal %w[T], style(tag: :T).selector.tags.to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_flow ()
|
25
|
+
s = style
|
26
|
+
|
27
|
+
assert_equal [:down, :none], s.flow
|
28
|
+
s.flow = :up
|
29
|
+
assert_equal [:up, :none], s.flow
|
30
|
+
s.flow = [:left, :down]
|
31
|
+
assert_equal [:left, :down], s.flow
|
32
|
+
s.flow = :none
|
33
|
+
assert_equal [:none, :none], s.flow
|
34
|
+
assert_raise(ArgumentError) {s.flow = []}
|
35
|
+
assert_raise(ArgumentError) {s.flow = [:down, :right, :none]}
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_margin_padding ()
|
39
|
+
s = style
|
40
|
+
|
41
|
+
assert_equal [0, 0, 0, 0], s.margin.to_a.map(&:value)
|
42
|
+
s.margin = [1]
|
43
|
+
assert_equal [1, 1, 1, 1], s.margin.to_a.map(&:value)
|
44
|
+
s.margin = [1, 2]
|
45
|
+
assert_equal [1, 2, 1, 2], s.margin.to_a.map(&:value)
|
46
|
+
s.margin = [1, 2, 3]
|
47
|
+
assert_equal [1, 2, 3, 2], s.margin.to_a.map(&:value)
|
48
|
+
s.margin = [1, 2, 3, 4]
|
49
|
+
assert_equal [1, 2, 3, 4], s.margin.to_a.map(&:value)
|
50
|
+
|
51
|
+
assert_equal [0, 0, 0, 0], s.padding.to_a.map(&:value)
|
52
|
+
s.padding = [1]
|
53
|
+
assert_equal [1, 1, 1, 1], s.padding.to_a.map(&:value)
|
54
|
+
s.padding = [1, 2]
|
55
|
+
assert_equal [1, 2, 1, 2], s.padding.to_a.map(&:value)
|
56
|
+
s.padding = [1, 2, 3]
|
57
|
+
assert_equal [1, 2, 3, 2], s.padding.to_a.map(&:value)
|
58
|
+
s.padding = [1, 2, 3, 4]
|
59
|
+
assert_equal [1, 2, 3, 4], s.padding.to_a.map(&:value)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_background_color ()
|
63
|
+
assert_equal [0, 0, 0, 1], style.background_color.to_a
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_background_image ()
|
67
|
+
assert_equal nil, style.background_image
|
68
|
+
end
|
69
|
+
|
70
|
+
end# TestStyle
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestStyleLength < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def len (*args, &block)
|
10
|
+
Reflex::StyleLength.new *args, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize ()
|
14
|
+
assert_equal 0, len.value
|
15
|
+
assert_equal nil, len.unit
|
16
|
+
assert_equal 100, len(100).value
|
17
|
+
assert_equal :px, len(100).unit
|
18
|
+
assert_equal 100, len(100, :px).value
|
19
|
+
assert_equal :px, len(100, :px).unit
|
20
|
+
#assert_equal :%, len(100, :%).unit
|
21
|
+
assert_equal 100, len('100px').value
|
22
|
+
assert_equal :px, len('100px').unit
|
23
|
+
#assert_equal :%, len('100%').unit
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_s ()
|
27
|
+
assert_equal '100px', len(100, :px).to_s
|
28
|
+
#assert_equal '100%', len(100, :%).to_s
|
29
|
+
#assert_equal '100.5%', len(100.5, :%).to_s
|
30
|
+
assert_raises(Rucy::NativeError) {len.to_s}
|
31
|
+
assert ((len.to_s rescue $!.message)) =~ /InvalidStateError/
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_inspect ()
|
35
|
+
assert_nothing_raised {len.inspect}
|
36
|
+
end
|
37
|
+
|
38
|
+
end# TestStyleLength
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestStyleLength2 < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def len2 (w = 0, h = 0, &block)
|
10
|
+
Reflex::StyleLength2.new width: w, height: h, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize ()
|
14
|
+
assert_equal 0, len2(*%w[]) .width.value
|
15
|
+
assert_equal 1, len2(*%w[1px]) .width.value
|
16
|
+
assert_equal 2, len2(*%w[1px 2px]).height.value
|
17
|
+
assert_equal :px, len2(*%w[1px]).width.unit
|
18
|
+
#assert_equal :%, len2(*%w[1%]).width.unit
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_wh ()
|
22
|
+
assert_equal '1px', len2(1) .width.to_s
|
23
|
+
assert_equal '2px', len2(1, 2).height.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_a ()
|
27
|
+
assert_equal [0, 0], len2.to_a.map(&:value)
|
28
|
+
assert_equal [:px] * 2, len2.to_a.map(&:unit)
|
29
|
+
assert_equal [1, 2], len2(1, 2).to_a.map(&:value)
|
30
|
+
assert_equal [:px] * 2, len2(1, 2).to_a.map(&:unit)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_set_at ()
|
34
|
+
l = len2 1, 2
|
35
|
+
|
36
|
+
assert_equal 1, l[0].value
|
37
|
+
assert_equal 2, l[1].value
|
38
|
+
|
39
|
+
l[0] = '10px'
|
40
|
+
assert_equal 10, l[0].value
|
41
|
+
l[1] = '40px'
|
42
|
+
assert_equal 40, l[1].value
|
43
|
+
l[-1] = '30px'
|
44
|
+
assert_equal 30, l[ 1].value
|
45
|
+
assert_equal 30, l[-1].value
|
46
|
+
|
47
|
+
assert_raises(IndexError) {l[2] = '50px'}
|
48
|
+
end
|
49
|
+
|
50
|
+
end# TestStyleLength2
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestStyleLength4 < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def len4 (l = 0, t = 0, r = 0, b = 0, &block)
|
10
|
+
Reflex::StyleLength4.new left: l, top: t, right: r, bottom: b, &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize ()
|
14
|
+
assert_equal 0, len4(*%w[]) .left.value
|
15
|
+
assert_equal 1, len4(*%w[1px]) .left.value
|
16
|
+
assert_equal 2, len4(*%w[1px 2px]) .top.value
|
17
|
+
assert_equal 3, len4(*%w[1px 2px 3px]) .right.value
|
18
|
+
assert_equal 4, len4(*%w[1px 2px 3px 4px]).bottom.value
|
19
|
+
assert_equal :px, len4(*%w[1px]).left.unit
|
20
|
+
#assert_equal :%, len4(*%w[1%]).left.unit
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_ltrb ()
|
24
|
+
assert_equal '1px', len4(1) .left.to_s
|
25
|
+
assert_equal '2px', len4(1, 2) .top.to_s
|
26
|
+
assert_equal '3px', len4(1, 2, 3) .right.to_s
|
27
|
+
assert_equal '4px', len4(1, 2, 3, 4).bottom.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_to_a ()
|
31
|
+
assert_equal [0, 0, 0, 0], len4.to_a.map(&:value)
|
32
|
+
assert_equal [:px] * 4, len4.to_a.map(&:unit)
|
33
|
+
assert_equal [1, 2, 3, 4], len4(1, 2, 3, 4).to_a.map(&:value)
|
34
|
+
assert_equal [:px] * 4, len4(1, 2, 3, 4).to_a.map(&:unit)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_get_set_at ()
|
38
|
+
l = len4 1, 2, 3, 4
|
39
|
+
|
40
|
+
assert_equal 1, l[0].value
|
41
|
+
assert_equal 2, l[1].value
|
42
|
+
assert_equal 3, l[2].value
|
43
|
+
assert_equal 4, l[3].value
|
44
|
+
|
45
|
+
l[0] = '10px'
|
46
|
+
assert_equal 10, l[0].value
|
47
|
+
l[3] = '40px'
|
48
|
+
assert_equal 40, l[3].value
|
49
|
+
l[-1] = '30px'
|
50
|
+
assert_equal 30, l[ 3].value
|
51
|
+
assert_equal 30, l[-1].value
|
52
|
+
|
53
|
+
assert_raises(IndexError) {l[4] = '50px'}
|
54
|
+
end
|
55
|
+
|
56
|
+
end# TestStyleLength4
|