opal 0.0.1 → 0.1.0
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.
- data/.gitignore +10 -1
- data/.gitmodules +0 -0
- data/Opalfile +371 -0
- data/README.md +45 -0
- data/Rakefile +237 -34
- data/VERSION +1 -1
- data/bin/opal +13 -0
- data/demos/apps/browser_demo/index.html +11 -0
- data/demos/apps/browser_demo/lib/browser_demo.rb +31 -0
- data/demos/apps/simple_opal/Opalfile +13 -0
- data/demos/apps/simple_opal/index.html +11 -0
- data/demos/apps/simple_opal/lib/app_controller.rb +62 -0
- data/demos/apps/simple_opal/lib/main_window.rb +146 -0
- data/demos/browser/request/index.html +52 -0
- data/demos/browser/request/request.rb +48 -0
- data/gen/browser/__PROJECT_NAME__/index.html +10 -0
- data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +1 -0
- data/lib/opal.rb +48 -3
- data/lib/opal/builders/base.rb +50 -0
- data/lib/opal/builders/css.rb +46 -0
- data/lib/opal/builders/javascript.rb +44 -0
- data/lib/opal/builders/opal.rb +79 -0
- data/lib/opal/builders/ruby.rb +50 -0
- data/lib/opal/builders/ruby/generate.rb +1851 -0
- data/lib/opal/builders/ruby/nodes.rb +210 -0
- data/lib/opal/builders/ruby/ruby.rb +916 -0
- data/lib/opal/builders/ruby/ruby_parser.rb +6008 -0
- data/lib/opal/builders/ruby/ruby_parser.rb.y +1451 -0
- data/lib/opal/models/build_item.rb +104 -0
- data/lib/opal/models/hash_struct.rb +40 -0
- data/lib/opal/models/project.rb +215 -0
- data/lib/opal/models/struct_accessors.rb +58 -0
- data/lib/opal/models/target.rb +176 -0
- data/lib/opal/opal/env/console.rb +66 -0
- data/lib/opal/opal/env/fs.rb +98 -0
- data/lib/opal/opal/env/object.rb +48 -0
- data/lib/opal/opal/environment.rb +139 -0
- data/lib/opal/opal/gen.rb +62 -0
- data/lib/opal/opal/opal.rb +68 -0
- data/lib/opal/opal/repl.rb +38 -0
- data/lib/opal/opalfile/dsl.rb +62 -0
- data/lib/opal/opalfile/opalfile.rb +133 -0
- data/lib/opal/opalfile/task.rb +96 -0
- data/lib/opal/opalfile/task_manager.rb +63 -0
- data/lib/opal/opalfile/task_scope.rb +52 -0
- data/lib/opal/rack/app_server.rb +119 -0
- data/opals/aristo/README.md +16 -0
- data/opals/browser/Opalfile +11 -0
- data/opals/browser/README.md +146 -0
- data/opals/browser/SIZZLE_LICESNSE.txt +148 -0
- data/opals/browser/lib/browser.rb +118 -0
- data/opals/browser/lib/browser/builder.rb +41 -0
- data/opals/browser/lib/browser/canvas_context.rb +115 -0
- data/opals/browser/lib/browser/dimensions.rb +50 -0
- data/opals/browser/lib/browser/document.rb +146 -0
- data/opals/browser/lib/browser/element.rb +487 -0
- data/opals/browser/lib/browser/element/attributes.rb +88 -0
- data/opals/browser/lib/browser/element/css.rb +290 -0
- data/opals/browser/lib/browser/element/form.rb +146 -0
- data/opals/browser/lib/browser/event/dom_events.rb +81 -0
- data/opals/browser/lib/browser/event/event.rb +177 -0
- data/opals/browser/lib/browser/event/trigger_events.rb +53 -0
- data/opals/browser/lib/browser/geometry.rb +97 -0
- data/opals/browser/lib/browser/json.rb +32 -0
- data/opals/browser/lib/browser/json_parse.js +321 -0
- data/opals/browser/lib/browser/request/request.rb +201 -0
- data/opals/browser/lib/browser/sizzle.js +1068 -0
- data/opals/browser/lib/browser/string.rb +42 -0
- data/opals/browser/lib/browser/touch.rb +37 -0
- data/{runtime/yaml.js → opals/browser/lib/browser/vml_context.js} +8 -8
- data/opals/browser/lib/browser/window.rb +36 -0
- data/opals/browser/spec/browser/browser_detection_spec.rb +7 -0
- data/opals/browser/spec/document/aref_spec.rb +110 -0
- data/opals/browser/spec/document/ready_spec.rb +16 -0
- data/opals/browser/spec/element/body_spec.rb +11 -0
- data/opals/browser/spec/element/clear_spec.rb +26 -0
- data/opals/browser/spec/element/empty_spec.rb +29 -0
- data/opals/browser/spec/element/has_class_spec.rb +40 -0
- data/opals/browser/spec/element/hidden_spec.rb +23 -0
- data/opals/browser/spec/element/hide_spec.rb +31 -0
- data/opals/browser/spec/element/remove_spec.rb +25 -0
- data/opals/browser/spec/element/show_spec.rb +31 -0
- data/opals/browser/spec/element/style_spec.rb +69 -0
- data/opals/browser/spec/element/toggle_spec.rb +31 -0
- data/opals/browser/spec/element/visible_spec.rb +23 -0
- data/opals/browser/spec/spec_helper.rb +1 -0
- data/opals/cherry_kit/Opalfile +6 -0
- data/opals/cherry_kit/bin/cherry_kit.rb +11 -0
- data/opals/cherry_kit/lib/cherry_kit.rb +29 -0
- data/opals/foundation/Opalfile +11 -0
- data/opals/foundation/bin/foundation.rb +12 -0
- data/opals/foundation/lib/foundation.rb +32 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/outline_view.rb +57 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/table_column.rb +59 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/table_header_view.rb +34 -0
- data/opals/foundation/lib/foundation/__table_view_desktop/table_view.rb +304 -0
- data/opals/foundation/lib/foundation/controllers/array_controller.rb +54 -0
- data/opals/foundation/lib/foundation/controllers/controller.rb +74 -0
- data/opals/foundation/lib/foundation/controllers/controller_selection_proxy.rb +67 -0
- data/opals/foundation/lib/foundation/controllers/object_controller.rb +145 -0
- data/opals/foundation/lib/foundation/controllers/view.rb +40 -0
- data/opals/foundation/lib/foundation/core/application.rb +476 -0
- data/opals/foundation/lib/foundation/core/attributes.rb +146 -0
- data/opals/foundation/lib/foundation/core/bindings.rb +125 -0
- data/opals/foundation/lib/foundation/core/builder.rb +101 -0
- data/opals/foundation/lib/foundation/core/event.rb +112 -0
- data/opals/foundation/lib/foundation/core/index_path.rb +49 -0
- data/opals/foundation/lib/foundation/core/index_set.rb +97 -0
- data/opals/foundation/lib/foundation/core/notification.rb +113 -0
- data/opals/foundation/lib/foundation/core/observable.rb +275 -0
- data/opals/foundation/lib/foundation/core/observable_array.rb +30 -0
- data/opals/foundation/lib/foundation/core/responder.rb +85 -0
- data/opals/foundation/lib/foundation/core/run_loop.rb +89 -0
- data/opals/foundation/lib/foundation/core/touch.rb +95 -0
- data/opals/foundation/lib/foundation/gestures/gesture_recognizer.rb +35 -0
- data/opals/foundation/lib/foundation/rendering/render_context.rb +100 -0
- data/opals/foundation/lib/foundation/rendering/renderer.rb +137 -0
- data/opals/foundation/lib/foundation/rendering/root_theme.rb +77 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/button.rb +62 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/control.rb +72 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/label.rb +54 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/scroller.rb +58 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/slider.rb +72 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/table_view.rb +97 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/text_field.rb +55 -0
- data/opals/foundation/lib/foundation/rendering/root_theme/view.rb +81 -0
- data/opals/foundation/lib/foundation/rendering/theme.rb +38 -0
- data/opals/foundation/lib/foundation/table_view/cell.rb +39 -0
- data/opals/foundation/lib/foundation/table_view/table.rb +171 -0
- data/opals/foundation/lib/foundation/views/button.rb +63 -0
- data/opals/foundation/lib/foundation/views/checkbox.rb +28 -0
- data/opals/foundation/lib/foundation/views/clip.rb +47 -0
- data/opals/foundation/lib/foundation/views/control.rb +199 -0
- data/opals/foundation/lib/foundation/views/label.rb +54 -0
- data/opals/foundation/lib/foundation/views/scroll.rb +294 -0
- data/opals/foundation/lib/foundation/views/scroll_view_desktop.rb +152 -0
- data/opals/foundation/lib/foundation/views/scroller.rb +54 -0
- data/opals/foundation/lib/foundation/views/slider.rb +93 -0
- data/opals/foundation/lib/foundation/views/text_field.rb +83 -0
- data/opals/foundation/lib/foundation/views/view.rb +426 -0
- data/opals/foundation/lib/foundation/windows/window.rb +191 -0
- data/opals/foundation/resources/button/button.css +23 -0
- data/{runtime/init.js → opals/foundation/resources/foundation.css} +27 -33
- data/opals/foundation/resources/scroll/scroll.css +22 -0
- data/opals/foundation/resources/scroll_view/scroll_view.css +3 -0
- data/opals/foundation/resources/scroll_view/scroller.css +3 -0
- data/opals/foundation/resources/slider/regular/slider.css +3 -0
- data/opals/foundation/resources/slider/slider.css +27 -0
- data/opals/foundation/resources/table_view/outline_view.css +3 -0
- data/opals/foundation/resources/table_view/table_view.css +15 -0
- data/opals/foundation/resources/text_field/text_field.css +71 -0
- data/opals/foundation/spec/spec_helper.rb +1 -0
- data/opals/foundation/spec/system/attributes/get_attribute_spec.rb +69 -0
- data/opals/foundation/spec/system/attributes/get_path_spec.rb +44 -0
- data/opals/foundation/spec/system/attributes/set_path_spec.rb +24 -0
- data/opals/foundation/spec/system/attributes/set_spec.rb +58 -0
- data/opals/foundation/spec/system/bindings/bindings.rb +85 -0
- data/opals/foundation/spec/system/key_value_binding/bind_spec.rb +43 -0
- data/opals/foundation/spec/system/observable/dependant_keys_spec.rb +74 -0
- data/opals/foundation/spec/system/observable/observe_spec.rb +292 -0
- data/opals/foundation/spec/system/observable/remove_observer_spec.rb +60 -0
- data/opals/opal/Opalfile +14 -0
- data/opals/opal/spec/core/array/append_spec.rb +30 -0
- data/opals/opal/spec/core/array/assoc_spec.rb +29 -0
- data/opals/opal/spec/core/array/at_spec.rb +37 -0
- data/opals/opal/spec/core/array/clear_spec.rb +22 -0
- data/opals/opal/spec/core/array/collect_bang_spec.rb +27 -0
- data/opals/opal/spec/core/array/collect_spec.rb +27 -0
- data/opals/opal/spec/core/array/compact_spec.rb +15 -0
- data/opals/opal/spec/core/array/concat_spec.rb +15 -0
- data/opals/opal/spec/core/array/constructor_spec.rb +14 -0
- data/opals/opal/spec/core/array/each_spec.rb +9 -0
- data/opals/opal/spec/core/array/element_reference_spec.rb +4 -0
- data/opals/opal/spec/core/array/first_spec.rb +35 -0
- data/opals/opal/spec/core/array/include_spec.rb +9 -0
- data/opals/opal/spec/core/array/map_spec.rb +31 -0
- data/opals/opal/spec/core/builtin_constants/builtin_constants_spec.rb +7 -0
- data/opals/opal/spec/core/false/and_spec.rb +10 -0
- data/opals/opal/spec/core/false/inspect_spec.rb +6 -0
- data/opals/opal/spec/core/false/or_spec.rb +10 -0
- data/opals/opal/spec/core/false/to_s_spec.rb +6 -0
- data/opals/opal/spec/core/false/xor_spec.rb +10 -0
- data/opals/opal/spec/core/file/join_spec.rb +19 -0
- data/opals/opal/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/opals/opal/spec/core/kernel/loop_spec.rb +24 -0
- data/opals/opal/spec/core/kernel/raise_spec.rb +0 -0
- data/opals/opal/spec/core/module/attr_accessor_spec.rb +28 -0
- data/opals/opal/spec/core/number/lt_spec.rb +12 -0
- data/opals/opal/spec/core/true/and_spec.rb +10 -0
- data/opals/opal/spec/core/true/inspect_spec.rb +6 -0
- data/opals/opal/spec/core/true/or_spec.rb +10 -0
- data/opals/opal/spec/core/true/to_s_spec.rb +6 -0
- data/opals/opal/spec/core/true/xor_spec.rb +10 -0
- data/opals/opal/spec/fixtures/super.rb +70 -0
- data/opals/opal/spec/language/____temp_remove_this.rb +12 -0
- data/opals/opal/spec/language/and_spec.rb +62 -0
- data/opals/opal/spec/language/array_spec.rb +52 -0
- data/opals/opal/spec/language/block_spec.rb +18 -0
- data/opals/opal/spec/language/break_spec.rb +36 -0
- data/opals/opal/spec/language/case_spec.rb +103 -0
- data/opals/opal/spec/language/def_spec.rb +11 -0
- data/opals/opal/spec/language/eigenclass_spec.rb +60 -0
- data/opals/opal/spec/language/hash_spec.rb +29 -0
- data/opals/opal/spec/language/if_spec.rb +54 -0
- data/opals/opal/spec/language/loop_spec.rb +11 -0
- data/opals/opal/spec/language/metaclass_spec.rb +21 -0
- data/opals/opal/spec/language/method_spec.rb +64 -0
- data/opals/opal/spec/language/next_spec.rb +25 -0
- data/opals/opal/spec/language/or_spec.rb +34 -0
- data/opals/opal/spec/language/redo_spec.rb +24 -0
- data/opals/opal/spec/language/rescue_spec.rb +20 -0
- data/opals/opal/spec/language/return_spec.rb +47 -0
- data/opals/opal/spec/language/string_spec.rb +25 -0
- data/opals/opal/spec/language/super_spec.rb +26 -0
- data/opals/opal/spec/language/until_spec.rb +157 -0
- data/opals/opal/spec/language/while_spec.rb +163 -0
- data/opals/opal/spec/spec_helper.rb +5 -0
- data/opals/runtime/Opalfile +68 -0
- data/opals/runtime/README.md +12 -0
- data/opals/runtime/docs/debugging.md +51 -0
- data/opals/runtime/lib/array.rb +1516 -0
- data/opals/runtime/lib/basic_object.rb +49 -0
- data/opals/runtime/lib/class.rb +54 -0
- data/opals/runtime/lib/dir.rb +36 -0
- data/opals/runtime/lib/error.rb +49 -0
- data/opals/runtime/lib/false_class.rb +52 -0
- data/opals/runtime/lib/file.rb +79 -0
- data/opals/runtime/lib/hash.rb +791 -0
- data/opals/runtime/lib/io.rb +39 -0
- data/opals/runtime/lib/kernel.rb +288 -0
- data/opals/runtime/lib/match_data.rb +36 -0
- data/opals/runtime/lib/module.rb +109 -0
- data/opals/runtime/lib/nil_class.rb +69 -0
- data/opals/runtime/lib/number.rb +398 -0
- data/opals/runtime/lib/proc.rb +77 -0
- data/opals/runtime/lib/range.rb +63 -0
- data/opals/runtime/lib/regexp.rb +111 -0
- data/opals/runtime/lib/ruby.rb +30 -0
- data/opals/runtime/lib/string.rb +328 -0
- data/opals/runtime/lib/symbol.rb +40 -0
- data/opals/runtime/lib/top_self.rb +33 -0
- data/opals/runtime/lib/true_class.rb +45 -0
- data/opals/runtime/runtime/browser.js +287 -0
- data/opals/runtime/runtime/debug.js +182 -0
- data/opals/runtime/runtime/opal.js +1010 -0
- data/opals/runtime/runtime/post_opal.js +1 -0
- data/opals/runtime/runtime/pre_opal.js +2 -0
- data/opals/runtime/runtime/server_side.js +50 -0
- data/opals/spec/LICENSE.txt +26 -0
- data/opals/spec/Opalfile +5 -0
- data/opals/spec/bin/spec.rb +43 -0
- data/opals/spec/lib/spec.rb +33 -0
- data/opals/spec/lib/spec/dsl.rb +41 -0
- data/opals/spec/lib/spec/example.rb +35 -0
- data/opals/spec/lib/spec/example/before_and_after_hooks.rb +81 -0
- data/opals/spec/lib/spec/example/errors.rb +42 -0
- data/opals/spec/lib/spec/example/example_group.rb +37 -0
- data/opals/spec/lib/spec/example/example_group_factory.rb +43 -0
- data/opals/spec/lib/spec/example/example_group_hierarchy.rb +45 -0
- data/opals/spec/lib/spec/example/example_group_methods.rb +142 -0
- data/opals/spec/lib/spec/example/example_group_proxy.rb +41 -0
- data/opals/spec/lib/spec/example/example_methods.rb +73 -0
- data/opals/spec/lib/spec/example/example_proxy.rb +48 -0
- data/opals/spec/lib/spec/expectations.rb +46 -0
- data/opals/spec/lib/spec/expectations/errors.rb +35 -0
- data/opals/spec/lib/spec/expectations/fail_with.rb +37 -0
- data/opals/spec/lib/spec/expectations/handler.rb +48 -0
- data/opals/spec/lib/spec/matchers.rb +50 -0
- data/opals/spec/lib/spec/matchers/be.rb +26 -0
- data/opals/spec/lib/spec/matchers/generated_descriptions.rb +47 -0
- data/opals/spec/lib/spec/matchers/operator_matcher.rb +66 -0
- data/opals/spec/lib/spec/runner.rb +48 -0
- data/opals/spec/lib/spec/runner/example_group_runner.rb +71 -0
- data/opals/spec/lib/spec/runner/formatter/html_formatter.rb +100 -0
- data/opals/spec/lib/spec/runner/formatter/terminal_formatter.rb +82 -0
- data/opals/spec/lib/spec/runner/options.rb +63 -0
- data/opals/spec/lib/spec/runner/reporter.rb +123 -0
- data/opals/spec/resources/index.html +25 -0
- data/opals/spec/resources/spec.css +132 -0
- data/spec/cherry_kit/iseq_spec.rb +38 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/vienna_spec.rb +7 -0
- data/yard/index.html +43 -0
- data/yard/style.css +765 -0
- metadata +312 -49
- data/docs/jarv.rdoc +0 -27
- data/runtime/array.js +0 -153
- data/runtime/class.js +0 -469
- data/runtime/compar.js +0 -73
- data/runtime/dir.js +0 -115
- data/runtime/enum.js +0 -74
- data/runtime/file.js +0 -165
- data/runtime/gem.js +0 -241
- data/runtime/hash.js +0 -181
- data/runtime/load.js +0 -251
- data/runtime/module.js +0 -98
- data/runtime/number.js +0 -148
- data/runtime/object.js +0 -522
- data/runtime/opal.js +0 -200
- data/runtime/parse.js +0 -2218
- data/runtime/range.js +0 -56
- data/runtime/re.js +0 -91
- data/runtime/string.js +0 -199
- data/runtime/variable.js +0 -184
- data/runtime/vm.js +0 -1150
- data/tasks/build.rb +0 -16
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#
|
|
2
|
+
# scroll_view.rb
|
|
3
|
+
# vienna
|
|
4
|
+
#
|
|
5
|
+
# Created by Adam Beynon.
|
|
6
|
+
# Copyright 2010 Adam Beynon.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
# furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
|
16
|
+
# all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
# THE SOFTWARE.
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
require 'foundation/views/view'
|
|
28
|
+
|
|
29
|
+
module CherryKit
|
|
30
|
+
|
|
31
|
+
class ScrollViewDesktop < View
|
|
32
|
+
|
|
33
|
+
register_builder :scroll_view,
|
|
34
|
+
{}
|
|
35
|
+
|
|
36
|
+
class_names 'ck-scroll-view'
|
|
37
|
+
|
|
38
|
+
attr_accessor :vertical_scroller, :horizontal_scroller
|
|
39
|
+
|
|
40
|
+
def initialize(layout)
|
|
41
|
+
super layout
|
|
42
|
+
|
|
43
|
+
@content_view = ClipView.new
|
|
44
|
+
self << @content_view
|
|
45
|
+
|
|
46
|
+
@header_clip_view = ClipView.new
|
|
47
|
+
self << @header_clip_view
|
|
48
|
+
|
|
49
|
+
self.has_vertical_scroller = true
|
|
50
|
+
self.has_horizontal_scroller = true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def document_view
|
|
54
|
+
@content_view.document_view
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def document_view=(document_view)
|
|
58
|
+
@content_view.document_view = document_view
|
|
59
|
+
|
|
60
|
+
reflect_scrolled_clip_view @content_view
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def reflect_scrolled_clip_view(clip_view)
|
|
64
|
+
return unless @content_view == clip_view
|
|
65
|
+
|
|
66
|
+
document_view = self.document_view
|
|
67
|
+
|
|
68
|
+
# handle case where we have no document view..
|
|
69
|
+
|
|
70
|
+
@content_view.layout = {
|
|
71
|
+
:left => 0,
|
|
72
|
+
:top => 20,
|
|
73
|
+
:bottom => 16,
|
|
74
|
+
:right => 16
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@header_clip_view.layout = {
|
|
78
|
+
:left => 0,
|
|
79
|
+
:top => 0,
|
|
80
|
+
:right => 16,
|
|
81
|
+
:height => 20
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if @vertical_scroller
|
|
85
|
+
@vertical_scroller.layout = {
|
|
86
|
+
:right => 0,
|
|
87
|
+
:top => 20,
|
|
88
|
+
:bottom => 16,
|
|
89
|
+
:width => 16
|
|
90
|
+
}
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if @horizontal_scroller
|
|
94
|
+
@horizontal_scroller.layout = {
|
|
95
|
+
:left => 0,
|
|
96
|
+
:bottom => 0,
|
|
97
|
+
:right => 16,
|
|
98
|
+
:height => 16
|
|
99
|
+
}
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def has_vertical_scroller=(flag)
|
|
104
|
+
# puts "making vertical scroller"
|
|
105
|
+
return if @has_vertical_scroller == flag
|
|
106
|
+
# puts "need to set"
|
|
107
|
+
@has_vertical_scroller = flag
|
|
108
|
+
|
|
109
|
+
# if we want a scroller, but have not yet made one... make one
|
|
110
|
+
if flag && !@vertical_scroller
|
|
111
|
+
# self.vertical_scroller = Scroller.build({
|
|
112
|
+
# :layout => {
|
|
113
|
+
# :height => 24,
|
|
114
|
+
# :width => layout[:width]
|
|
115
|
+
# }
|
|
116
|
+
# })
|
|
117
|
+
self.vertical_scroller = Scroller.build(:vertical => true)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
reflect_scrolled_clip_view @content_view
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def has_horizontal_scroller=(flag)
|
|
124
|
+
return if @has_horizontal_scroller == flag
|
|
125
|
+
|
|
126
|
+
@has_horizontal_scroller = flag
|
|
127
|
+
|
|
128
|
+
if flag && !@horizontal_scroller
|
|
129
|
+
self.horizontal_scroller = Scroller.new
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def vertical_scroller=(vertical_scroller)
|
|
134
|
+
# remove old..
|
|
135
|
+
|
|
136
|
+
@vertical_scroller = vertical_scroller
|
|
137
|
+
# vertical_scroller.on_action do
|
|
138
|
+
# _vertical_scroller_did_scroll
|
|
139
|
+
# end
|
|
140
|
+
self << vertical_scroller
|
|
141
|
+
reflect_scrolled_clip_view @clip_view
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def horizontal_scroller=(horizontal_scroller)
|
|
145
|
+
@horizontal_scroller = horizontal_scroller
|
|
146
|
+
|
|
147
|
+
self << horizontal_scroller
|
|
148
|
+
reflect_scrolled_clip_view @clip_view
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#
|
|
2
|
+
# scroller.rb
|
|
3
|
+
# vienna
|
|
4
|
+
#
|
|
5
|
+
# Created by Adam Beynon.
|
|
6
|
+
# Copyright 2010 Adam Beynon.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
# furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
|
16
|
+
# all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
# THE SOFTWARE.
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
require 'foundation/views/control'
|
|
28
|
+
|
|
29
|
+
module CherryKit
|
|
30
|
+
|
|
31
|
+
class Scroller < Control
|
|
32
|
+
|
|
33
|
+
class_names 'ck-scroller'
|
|
34
|
+
|
|
35
|
+
attr_writer :vertical
|
|
36
|
+
|
|
37
|
+
def initialize
|
|
38
|
+
super
|
|
39
|
+
@vertical = false
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def create_renderer(theme)
|
|
43
|
+
theme.scroller self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def vertical?
|
|
47
|
+
@vertical
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def horizontal?
|
|
51
|
+
!@vertical
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#
|
|
2
|
+
# slider.rb
|
|
3
|
+
# vienna
|
|
4
|
+
#
|
|
5
|
+
# Created by Adam Beynon.
|
|
6
|
+
# Copyright 2010 Adam Beynon.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
# furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
|
16
|
+
# all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
# THE SOFTWARE.
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
require 'foundation/views/control'
|
|
28
|
+
|
|
29
|
+
module CherryKit
|
|
30
|
+
|
|
31
|
+
class Slider < Control
|
|
32
|
+
|
|
33
|
+
register_builder :slider, {}
|
|
34
|
+
|
|
35
|
+
class_names 'ck-slider'
|
|
36
|
+
|
|
37
|
+
display_attributes :value, :min, :max
|
|
38
|
+
|
|
39
|
+
attr_accessor :value, :min, :max
|
|
40
|
+
|
|
41
|
+
def initialize
|
|
42
|
+
super
|
|
43
|
+
# puts "====================================== setting value to 0"
|
|
44
|
+
@value = 0
|
|
45
|
+
@min = 0
|
|
46
|
+
@max = 100
|
|
47
|
+
# puts @value
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def create_renderer(theme)
|
|
51
|
+
theme.slider self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# slider value for the given location (point)
|
|
55
|
+
#
|
|
56
|
+
def value_for_location(location)
|
|
57
|
+
# 14/7 should be got from the renderer.. each theme/control size may
|
|
58
|
+
# define a different indent
|
|
59
|
+
|
|
60
|
+
# our width is less 2x the track indent
|
|
61
|
+
width = bounds.width - 14
|
|
62
|
+
# our location is the track indent less than what it actually is
|
|
63
|
+
x = location.x - 7
|
|
64
|
+
|
|
65
|
+
(x / width) * 100
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def start_tracking?(location)
|
|
69
|
+
self.value = value_for_location location
|
|
70
|
+
self.highlighted = true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def stop_tracking(location)
|
|
74
|
+
self.value = value_for_location location
|
|
75
|
+
self.highlighted = false
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def continue_tracking?(location)
|
|
79
|
+
# puts "value should be #{value_for_location(location)}"
|
|
80
|
+
self.value = value_for_location location
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def value=(value)
|
|
84
|
+
if value < @min
|
|
85
|
+
@value = @min
|
|
86
|
+
elsif @max < value
|
|
87
|
+
@value = @max
|
|
88
|
+
else
|
|
89
|
+
@value = value
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#
|
|
2
|
+
# text_field.rb
|
|
3
|
+
# vienna
|
|
4
|
+
#
|
|
5
|
+
# Created by Adam Beynon.
|
|
6
|
+
# Copyright 2010 Adam Beynon.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
# furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
|
16
|
+
# all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
# THE SOFTWARE.
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
require 'foundation/views/control'
|
|
28
|
+
|
|
29
|
+
module CherryKit
|
|
30
|
+
|
|
31
|
+
class TextField < Control
|
|
32
|
+
|
|
33
|
+
register_builder :text_field, {}
|
|
34
|
+
|
|
35
|
+
class_names 'ck-text-field'
|
|
36
|
+
|
|
37
|
+
display_attributes :bezel
|
|
38
|
+
|
|
39
|
+
# Set the bezel style. May be :rounded or :square
|
|
40
|
+
#
|
|
41
|
+
attr_accessor :bezel
|
|
42
|
+
|
|
43
|
+
def initialize(layout)
|
|
44
|
+
super layout
|
|
45
|
+
@value = ""
|
|
46
|
+
@bezel = :square
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def create_renderer(theme)
|
|
50
|
+
theme.text_field self
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def key_down(event)
|
|
54
|
+
if event.key == :return
|
|
55
|
+
false
|
|
56
|
+
elsif event.key == :tab
|
|
57
|
+
false
|
|
58
|
+
else
|
|
59
|
+
true
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def key_up(event)
|
|
64
|
+
puts "key up event!"
|
|
65
|
+
old_value = self.value
|
|
66
|
+
|
|
67
|
+
unless old_value == "some old valye...s.s.s"
|
|
68
|
+
|
|
69
|
+
unless @editing
|
|
70
|
+
@editing = true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def _string_value=(value)
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
#
|
|
2
|
+
# view.rb
|
|
3
|
+
# vienna
|
|
4
|
+
#
|
|
5
|
+
# Created by Adam Beynon.
|
|
6
|
+
# Copyright 2010 Adam Beynon.
|
|
7
|
+
#
|
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
# furnished to do so, subject to the following conditions:
|
|
14
|
+
#
|
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
|
16
|
+
# all copies or substantial portions of the Software.
|
|
17
|
+
#
|
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
# THE SOFTWARE.
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
require 'foundation/core/responder'
|
|
28
|
+
require 'foundation/core/builder'
|
|
29
|
+
|
|
30
|
+
module CherryKit
|
|
31
|
+
|
|
32
|
+
class View < Responder
|
|
33
|
+
|
|
34
|
+
# Get the layout hash from the receiver (Hash)
|
|
35
|
+
attr_accessor :layout
|
|
36
|
+
|
|
37
|
+
# the view's window
|
|
38
|
+
attr_reader :window
|
|
39
|
+
|
|
40
|
+
# Boolean whether or not the view can receive multi-touch events. Default
|
|
41
|
+
# is false. If false (default), then the view is only sent details of the
|
|
42
|
+
# first touch in the view, all other touches will be ignored within CKApp
|
|
43
|
+
# and not passed to this view.
|
|
44
|
+
#
|
|
45
|
+
# @getter multiple_touch_enabled?
|
|
46
|
+
#
|
|
47
|
+
# @attribute {true|false} multiple_touch_enabled
|
|
48
|
+
#
|
|
49
|
+
attr_writer :multiple_touch_enabled
|
|
50
|
+
|
|
51
|
+
def initialize(frame)
|
|
52
|
+
# initialize
|
|
53
|
+
# default layout
|
|
54
|
+
@layout = {
|
|
55
|
+
:left => 0,
|
|
56
|
+
:top => 0,
|
|
57
|
+
:right => 0,
|
|
58
|
+
:bottom => 0
|
|
59
|
+
}
|
|
60
|
+
# all of our subviews
|
|
61
|
+
@subviews = []
|
|
62
|
+
|
|
63
|
+
# by default only receive single touches
|
|
64
|
+
@multiple_touch_enabled = false
|
|
65
|
+
|
|
66
|
+
# for every display property defined, we add an observer when it changes,
|
|
67
|
+
# so we can tell the view that it needs a redisplay
|
|
68
|
+
self.class.all_display_attributes.each do |property|
|
|
69
|
+
self.observe(property) do |oldvalue, newvalue|
|
|
70
|
+
self.needs_display = true
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# For duplicating views. This will duplicate all relevant properties.
|
|
76
|
+
# Subclasses should do their own behaviour. Does NOT copy subviews,
|
|
77
|
+
# superview or window
|
|
78
|
+
#
|
|
79
|
+
def dup
|
|
80
|
+
result = self.class.new
|
|
81
|
+
result.layout = layout
|
|
82
|
+
|
|
83
|
+
result
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# ======================
|
|
87
|
+
# = Display attributes =
|
|
88
|
+
# ======================
|
|
89
|
+
|
|
90
|
+
def self.all_display_attributes
|
|
91
|
+
if CherryKit::View == self
|
|
92
|
+
return @display_attributes ||= []
|
|
93
|
+
else
|
|
94
|
+
@display_attributes ||= []
|
|
95
|
+
return @display_attributes + superclass.all_display_attributes
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Add each of the given display properties to the array of properties for
|
|
100
|
+
# this class
|
|
101
|
+
def self.display_attributes(*properties)
|
|
102
|
+
@display_attributes ||= []
|
|
103
|
+
@display_attributes = @display_attributes + properties
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Set each of the given class names (strings) to the array of class names
|
|
107
|
+
# which will all be added together with superclass' to build up the full
|
|
108
|
+
# class name. (e.g. CK::Control will be 'ck-view ck-control')
|
|
109
|
+
#
|
|
110
|
+
def self.class_names(*names)
|
|
111
|
+
# puts "setting class names to #{names.inspect} for #{self}"
|
|
112
|
+
@css_class_names = names
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def self.all_class_names
|
|
116
|
+
# puts "looking for #{self} with #{@css_class_names.inspect}"
|
|
117
|
+
if CherryKit::View == self
|
|
118
|
+
return @css_class_names ||= []
|
|
119
|
+
else
|
|
120
|
+
@css_class_names ||= []
|
|
121
|
+
return ([] + superclass.all_class_names) + @css_class_names
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
display_attributes :visible, :layout
|
|
126
|
+
|
|
127
|
+
class_names 'ck-view'
|
|
128
|
+
|
|
129
|
+
# Return the theme name to use for the view. In all systems, root_theme is
|
|
130
|
+
# used as the default. To use another theme, set the theme_name property for
|
|
131
|
+
# the window when created so that all subviews will inherit that theme.
|
|
132
|
+
#
|
|
133
|
+
# @returns {Symbol} theme name
|
|
134
|
+
#
|
|
135
|
+
def theme_name
|
|
136
|
+
:root_theme
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Returns the receivers container view
|
|
140
|
+
#
|
|
141
|
+
# @returns [View] containing view
|
|
142
|
+
#
|
|
143
|
+
def superview
|
|
144
|
+
@superview
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def render_context
|
|
148
|
+
@render_context
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# NEVER EVER call this method directly. This will create and / or update
|
|
152
|
+
# the rendering context as needed
|
|
153
|
+
#
|
|
154
|
+
def display
|
|
155
|
+
if @render_context
|
|
156
|
+
update
|
|
157
|
+
else
|
|
158
|
+
render_context = create_render_context
|
|
159
|
+
# first call .render(), then immediately update() it
|
|
160
|
+
render render_context
|
|
161
|
+
update
|
|
162
|
+
# add to super
|
|
163
|
+
@superview.render_context.element << render_context.element
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Create the render_context based on the theme and create_renderer()
|
|
168
|
+
def create_render_context
|
|
169
|
+
return @render_context if @render_context
|
|
170
|
+
|
|
171
|
+
render_context = RenderContext.new tag_name
|
|
172
|
+
theme = Theme.find_theme theme_name
|
|
173
|
+
# unless we could find the theme, throw an error - theme must exist
|
|
174
|
+
theme or raise "Cannot find theme named #{theme_name}"
|
|
175
|
+
# get our renderer. unless overridden, this will be theme::View renderer
|
|
176
|
+
@renderer = create_renderer theme
|
|
177
|
+
|
|
178
|
+
@render_context = render_context
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Create the renderer just for this view. The default action is to create
|
|
182
|
+
# a simple view renderer. In this case, the most likely behaviour is that
|
|
183
|
+
# .render() and .update() of this view should be overridden for rendering
|
|
184
|
+
# custom views/data etc
|
|
185
|
+
#
|
|
186
|
+
# @param {CherryKit::Theme} theme to create renderer from
|
|
187
|
+
# @returns {CherryKit::Renderer} renderer
|
|
188
|
+
#
|
|
189
|
+
def create_renderer(theme)
|
|
190
|
+
theme.view self
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Core method for the initial render of the view. This method is passed the
|
|
194
|
+
# render context that we render to. The default behaviour is to simply call
|
|
195
|
+
# on the @renderer to render itself in the given context. Any view that does
|
|
196
|
+
# not have a themed renderer should use this method instead and MUST call
|
|
197
|
+
# super()
|
|
198
|
+
#
|
|
199
|
+
# @param {CherryKit::RenderContext} render_context to render to
|
|
200
|
+
# @returns nil
|
|
201
|
+
#
|
|
202
|
+
def render(render_context)
|
|
203
|
+
@renderer.render render_context
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Core method for updating the view. This is called immediately after render
|
|
207
|
+
# and also everytime the view needs an update (self.needs_display=true).
|
|
208
|
+
# Again the default behaviour is to simply call .update() on the @renderer,
|
|
209
|
+
# but non themed views may simply have their own code here for updating,
|
|
210
|
+
# but as before, MUST call super() to allow the default ViewRenderer do its
|
|
211
|
+
# business
|
|
212
|
+
#
|
|
213
|
+
# @returns nil
|
|
214
|
+
#
|
|
215
|
+
def update
|
|
216
|
+
@renderer.update
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def visible?
|
|
222
|
+
true
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Bounds of the view. This often needs to be recalculated based on css
|
|
226
|
+
# layout etc.
|
|
227
|
+
#
|
|
228
|
+
# @returns {Browser::Rect} rect bounds
|
|
229
|
+
def bounds
|
|
230
|
+
Browser::Rect.new 0, 0, `#{render_context.element}.__element__.clientWidth`, `#{render_context.element}.__element__.clientHeight`
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# Root element tag_name used for building the responder context. Should be a
|
|
235
|
+
# Symbol. Default is <tt>:div</tt>
|
|
236
|
+
#
|
|
237
|
+
# @returns {Symbol} tag name
|
|
238
|
+
#
|
|
239
|
+
def tag_name
|
|
240
|
+
:div
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def <<(subview)
|
|
244
|
+
add_subview subview
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Add subview
|
|
248
|
+
#
|
|
249
|
+
# @param {CherryKit::View} view to append as subview
|
|
250
|
+
# @returns {self}
|
|
251
|
+
#
|
|
252
|
+
def add_subview(subview)
|
|
253
|
+
# inform subview that it must first remove itself from its superview
|
|
254
|
+
subview.remove_from_superview
|
|
255
|
+
# privately set the window to our current window
|
|
256
|
+
subview._window = @window
|
|
257
|
+
# notify subview that it is soon to move to this view
|
|
258
|
+
subview.will_move_to_superview self
|
|
259
|
+
# set private superview variable on subview
|
|
260
|
+
subview.instance_variable_set :@superview, self
|
|
261
|
+
# do DOM manipulation here
|
|
262
|
+
@subviews << subview
|
|
263
|
+
# reset responder chain for subview
|
|
264
|
+
subview.next_responder = self
|
|
265
|
+
# alert subview that its move is complete
|
|
266
|
+
subview.did_move_to_superview self
|
|
267
|
+
# any callbacks that might be ndded
|
|
268
|
+
did_add_subview subview
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Remove the receiver from its current superview
|
|
272
|
+
#
|
|
273
|
+
def remove_from_superview
|
|
274
|
+
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Perform additonal actions once the subview has been added to the
|
|
278
|
+
# receiver
|
|
279
|
+
#
|
|
280
|
+
# @param {CherryKit::View} subview that was added
|
|
281
|
+
# @returns {nil}
|
|
282
|
+
#
|
|
283
|
+
def did_add_subview(subview)
|
|
284
|
+
# nothing by default
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Called when the receiver is about to move to the given superview
|
|
288
|
+
#
|
|
289
|
+
# @param {CherryKit::View} view to move to
|
|
290
|
+
#
|
|
291
|
+
def will_move_to_superview(superview)
|
|
292
|
+
# nothing by default
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# Called when the receiver has just moved to the given superview. Default
|
|
296
|
+
# action is to simply call self.needs_display which marks this view as
|
|
297
|
+
# needing display. This should always be called in a custom overridden
|
|
298
|
+
# method, or just use super().
|
|
299
|
+
#
|
|
300
|
+
# @param {CherryKit::View} view that is now the superview
|
|
301
|
+
#
|
|
302
|
+
def did_move_to_superview(superview)
|
|
303
|
+
self.needs_display = true
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# Marks the receiver as needing displaying (rendering). Windows are in
|
|
307
|
+
# charge of calling renderers etc as needed, so this method simply
|
|
308
|
+
# registers itself with its window as needing display.
|
|
309
|
+
#
|
|
310
|
+
# @param {true|false} needs_displaying
|
|
311
|
+
#
|
|
312
|
+
def needs_display=(needs_displaying)
|
|
313
|
+
# puts "======= needs_display"
|
|
314
|
+
# we should only mark ourself as needing display if we have a window
|
|
315
|
+
if @window
|
|
316
|
+
RunLoop.current_run_loop.add_task self, :display
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Sets the window for the view. This method should never be directly called.
|
|
321
|
+
# Instead, use <tt><<</tt> to add the view to another view within the window
|
|
322
|
+
# hierarchy.
|
|
323
|
+
#
|
|
324
|
+
# @private
|
|
325
|
+
#
|
|
326
|
+
# @param {CherryKit::Window} window to set
|
|
327
|
+
#
|
|
328
|
+
def _window=(window)
|
|
329
|
+
# puts "setting window to #{window} for #{self}"
|
|
330
|
+
# if we already belong to the window, just return
|
|
331
|
+
return if @window == window
|
|
332
|
+
# callback
|
|
333
|
+
will_move_to_window window
|
|
334
|
+
|
|
335
|
+
@window = window
|
|
336
|
+
|
|
337
|
+
# mark ourselves as needing redisplay (before our subviews are)
|
|
338
|
+
self.needs_display = true
|
|
339
|
+
|
|
340
|
+
# inform each subview that we are all moving
|
|
341
|
+
@subviews.each do |subview|
|
|
342
|
+
subview._window = window
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# second callback
|
|
346
|
+
did_move_to_window window
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# Callback informing the receiver that it is about to join the new window
|
|
350
|
+
#
|
|
351
|
+
# @param {CherryKit::Window} window to join
|
|
352
|
+
#
|
|
353
|
+
def will_move_to_window(window)
|
|
354
|
+
# do nothing by default
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# Inform the receiver that it has joined the new window
|
|
358
|
+
#
|
|
359
|
+
# @param {CherryKit::Window} window just joint
|
|
360
|
+
#
|
|
361
|
+
def did_move_to_window(window)
|
|
362
|
+
# do nothing by default
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# ==========
|
|
366
|
+
# = Events =
|
|
367
|
+
# ==========
|
|
368
|
+
|
|
369
|
+
# IF the view should capture all touches (instead of allowing subviews to),
|
|
370
|
+
# then return true. Default is false. ScrollView, for example, returns true
|
|
371
|
+
#
|
|
372
|
+
def capture_touches?
|
|
373
|
+
false
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
# Can the view receive multiple touches: true or false
|
|
377
|
+
def multiple_touch_enabled?
|
|
378
|
+
@multiple_touch_enabled
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
# ===================
|
|
382
|
+
# = Handling events =
|
|
383
|
+
# ===================
|
|
384
|
+
|
|
385
|
+
# Handle mouse down. Default implementation simply calls super(), which
|
|
386
|
+
# passes the event back up to CK::Responders implementation which passes the
|
|
387
|
+
# event onto the next_responder
|
|
388
|
+
#
|
|
389
|
+
# @param {Browser::Event}
|
|
390
|
+
#
|
|
391
|
+
def mouse_down(event)
|
|
392
|
+
super event
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
# ================
|
|
396
|
+
# = Touch Events =
|
|
397
|
+
# ================
|
|
398
|
+
def touches_began(touches, event)
|
|
399
|
+
puts "#{self}#touches_began"
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def touches_ended(touches, event)
|
|
403
|
+
puts "#{self}#touches_ended"
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
def touches_moved(touches, event)
|
|
407
|
+
puts "#{self}#touches_moved"
|
|
408
|
+
end
|
|
409
|
+
#
|
|
410
|
+
# def touched_cancelled(touches, event)
|
|
411
|
+
#
|
|
412
|
+
# end
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
# ==================================
|
|
416
|
+
# = Register views to DOM id names =
|
|
417
|
+
# ==================================
|
|
418
|
+
def self.[]=(id, view)
|
|
419
|
+
(@view_ids ||= {})[id] = view
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def self.[](id)
|
|
423
|
+
@view_ids[id]
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
end
|