Class: Crimson::Window
- Defined in:
- lib/crimson/widgets/window.rb
Instance Attribute Summary collapse
-
#bottom_resizer ⇒ Object
readonly
Returns the value of attribute bottom_resizer.
-
#content ⇒ Object
Returns the value of attribute content.
-
#left_resizer ⇒ Object
readonly
Returns the value of attribute left_resizer.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#previous_dimensions ⇒ Object
readonly
Returns the value of attribute previous_dimensions.
-
#resizable ⇒ Object
Returns the value of attribute resizable.
-
#right_resizer ⇒ Object
readonly
Returns the value of attribute right_resizer.
-
#titlebar ⇒ Object
readonly
Returns the value of attribute titlebar.
-
#top_resizer ⇒ Object
readonly
Returns the value of attribute top_resizer.
Attributes inherited from Object
#added_children, #event_handlers, #id, #node, #removed_children, #tag
Attributes inherited from Model
#local, #observers, #revision_number, #revisions
Instance Method Summary collapse
-
#initialize(title, width = '800px', height = '600px') ⇒ Window
constructor
A new instance of Window.
- #maximize ⇒ Object
- #maximized? ⇒ Boolean
- #minimize ⇒ Object
- #minimized? ⇒ Boolean
- #on_dragstart(data) ⇒ Object
- #on_mousedown(_data) ⇒ Object
- #resizable? ⇒ Boolean
- #resizers ⇒ Object
Methods inherited from Object
#==, #add, #breadth_each, #children, #commit_tree!, #eql?, #find_descendant, #hash, #hidden?, #hide, #inspect, #move, #on, #on_event, #parent, #parent=, #postordered_each, #preordered_each, #remove, #root, #show, #shown?, #siblings, #to_s, #un
Methods inherited from Model
#add_observer, #apply_changes!, #changed?, #changes, #commit!, #master, #modify, #new_changes, #notify_observers, #reload!, #remove_observer, #rollback!
Constructor Details
#initialize(title, width = '800px', height = '600px') ⇒ Window
Returns a new instance of Window.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/crimson/widgets/window.rb', line 16 def initialize(title, width = '800px', height = '600px') super(:div) @resizable = true @offset = Hashie::Mash.new @previous_dimensions = Hashie::Mash.new @titlebar = Titlebar.new(title) .draggable = true .on('dragstart', method(:on_dragstart)) ..on('click') do |_data| maximized? ? minimize : maximize commit_tree! end ..on('click') do |_data| old_parent = parent old_parent.remove(self) old_parent.commit_tree! end add() @left_resizer = LeftResizer.new add(left_resizer) @right_resizer = RightResizer.new add(right_resizer) @top_resizer = TopResizer.new top_resizer.style.height = '10px' add(top_resizer) @bottom_resizer = BottomResizer.new add(bottom_resizer) @content = Crimson::Object.new(:div) content.style.width = '100%' content.style.height = "calc(100% - #{.style.height})" content.style.padding = 0 content.style.margin = 0 add(content) style.left = '0px' style.top = '0px' style.height = height style.width = width style.minHeight = '200px' style.minWidth = '400px' style.position = 'absolute' style.backgroundColor = 'white' style.boxShadow = '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)' on('mousedown', method(:on_mousedown)) end |
Instance Attribute Details
#bottom_resizer ⇒ Object (readonly)
Returns the value of attribute bottom_resizer.
14 15 16 |
# File 'lib/crimson/widgets/window.rb', line 14 def bottom_resizer @bottom_resizer end |
#content ⇒ Object
Returns the value of attribute content.
13 14 15 |
# File 'lib/crimson/widgets/window.rb', line 13 def content @content end |
#left_resizer ⇒ Object (readonly)
Returns the value of attribute left_resizer.
14 15 16 |
# File 'lib/crimson/widgets/window.rb', line 14 def left_resizer @left_resizer end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
13 14 15 |
# File 'lib/crimson/widgets/window.rb', line 13 def offset @offset end |
#previous_dimensions ⇒ Object (readonly)
Returns the value of attribute previous_dimensions.
13 14 15 |
# File 'lib/crimson/widgets/window.rb', line 13 def previous_dimensions @previous_dimensions end |
#resizable ⇒ Object
Returns the value of attribute resizable.
14 15 16 |
# File 'lib/crimson/widgets/window.rb', line 14 def resizable @resizable end |
#right_resizer ⇒ Object (readonly)
Returns the value of attribute right_resizer.
14 15 16 |
# File 'lib/crimson/widgets/window.rb', line 14 def right_resizer @right_resizer end |
#titlebar ⇒ Object (readonly)
Returns the value of attribute titlebar.
13 14 15 |
# File 'lib/crimson/widgets/window.rb', line 13 def @titlebar end |
#top_resizer ⇒ Object (readonly)
Returns the value of attribute top_resizer.
14 15 16 |
# File 'lib/crimson/widgets/window.rb', line 14 def top_resizer @top_resizer end |
Instance Method Details
#maximize ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/crimson/widgets/window.rb', line 111 def maximize self.resizable = false previous_dimensions.top = style.top.dup previous_dimensions.left = style.left.dup previous_dimensions.width = style.width.dup previous_dimensions.height = style.height.dup style.top = '0px' style.left = '0px' style.width = '100vw' style.height = '100vh' end |
#maximized? ⇒ Boolean
85 86 87 |
# File 'lib/crimson/widgets/window.rb', line 85 def maximized? style.height == '100vh' && style.width == '100vw' end |
#minimize ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/crimson/widgets/window.rb', line 125 def minimize style.top = previous_dimensions.top.dup style.left = previous_dimensions.left.dup style.width = previous_dimensions.width.dup style.height = previous_dimensions.height.dup self.resizable = true end |
#minimized? ⇒ Boolean
89 90 91 |
# File 'lib/crimson/widgets/window.rb', line 89 def minimized? !maximized? end |
#on_dragstart(data) ⇒ Object
75 76 77 78 |
# File 'lib/crimson/widgets/window.rb', line 75 def on_dragstart(data) offset.top = style.top.delete_suffix('px').to_i - data.clientY offset.left = style.left.delete_suffix('px').to_i - data.clientX end |
#on_mousedown(_data) ⇒ Object
80 81 82 83 |
# File 'lib/crimson/widgets/window.rb', line 80 def on_mousedown(_data) parent.move(self, -1) parent.commit_tree!(:children) end |
#resizable? ⇒ Boolean
93 94 95 |
# File 'lib/crimson/widgets/window.rb', line 93 def resizable? resizable end |
#resizers ⇒ Object
107 108 109 |
# File 'lib/crimson/widgets/window.rb', line 107 def resizers [left_resizer, right_resizer, top_resizer, bottom_resizer] end |