1-- @docclass
2UIWindow = extends(UIWidget, "UIWindow")
3
4function UIWindow.create()
5 local window = UIWindow.internalCreate()
6 window:setTextAlign(AlignTopCenter)
7 window:setDraggable(true)
8 window:setAutoFocusPolicy(AutoFocusFirst)
9 return window
10end
11
12function UIWindow:onKeyDown(keyCode, keyboardModifiers)
13 if keyboardModifiers == KeyboardNoModifier then
14 if keyCode == KeyEnter then
15 signalcall(self.onEnter, self)
16 elseif keyCode == KeyEscape then
17 signalcall(self.onEscape, self)
18 end
19 end
20end
21
22function UIWindow:onFocusChange(focused)
23 if focused then self:raise() end
24end
25
26function UIWindow:onDragEnter(mousePos)
27 if self.static then
28 return false
29 end
30 self:breakAnchors()
31 self.movingReference = { x = mousePos.x - self:getX(), y = mousePos.y - self:getY() }
32 return true
33end
34
35function UIWindow:onDragLeave(droppedWidget, mousePos)
36 -- TODO: auto detect and reconnect anchors
37end
38
39function UIWindow:onDragMove(mousePos, mouseMoved)
40 if self.static then
41 return
42 end
43 local pos = { x = mousePos.x - self.movingReference.x, y = mousePos.y - self.movingReference.y }
44 self:setPosition(pos)
45 self:bindRectToParent()
46end
47