Class: Crimson::Desktop

Inherits:
Object show all
Defined in:
lib/crimson/widgets/desktop.rb

Instance Attribute Summary

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

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

#initializeDesktop

Returns a new instance of Desktop.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/crimson/widgets/desktop.rb', line 8

def initialize
  super(:div)

  self.style = {
    "height": '100vh',
    "width": '100vw',
    "max-height": '100vh',
    "max-width": '100vw',
    "overflow": 'hidden',
    "position": 'fixed',
    "left": "0px",
    "top": "0px"
  }

  self.ondragover = 'event.preventDefault();'
  self.ondrop = 'event.preventDefault();'

  on('drop', method(:on_drop))
end

Instance Method Details

#create_window(*args) ⇒ Object



38
39
40
41
42
# File 'lib/crimson/widgets/desktop.rb', line 38

def create_window(*args)
  window = Crimson::Window.new(*args)
  add(window)
  window
end

#on_drop(data) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/crimson/widgets/desktop.rb', line 28

def on_drop(data)
  window = find_descendant(data.target.to_sym).parent

  unless window.nil?
    window.style.left = "#{data.clientX + window.offset.left}px"
    window.style.top = "#{data.clientY + window.offset.top}px"
    window.commit!
  end
end