-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
dropdownlistitemgroup.lua
95 lines (76 loc) · 2.5 KB
/
dropdownlistitemgroup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Drop-Down List Item Group class
--
--==========================================================================--
class "gui.dropdownlistitemgroup" ( "gui.radiobuttongroup" )
local dropdownlistitemgroup = gui.dropdownlistitemgroup
function dropdownlistitemgroup:dropdownlistitemgroup( parent, name )
gui.radiobuttongroup.radiobuttongroup( self, nil, name )
self:setParent( parent:getRootPanel() )
self.height = nil
self:setBorderWidth( 1 )
self:setBorderColor( self:getScheme( "dropdownlistitem.borderColor" ) )
self:setDisplay( "block" )
self:setPosition( "absolute" )
self.width = parent:getWidth()
self:setUseFullscreenCanvas( true )
self.dropDownList = parent
end
function dropdownlistitemgroup:addItem( item, default )
item:setParent( self )
gui.radiobuttongroup.addItem( self, item )
if ( default or #self:getItems() == 1 ) then
item:setDefault( true )
end
self:invalidateLayout()
end
function dropdownlistitemgroup:draw()
if ( self:getItems() == nil ) then
return
end
gui.box.draw( self )
end
accessor( dropdownlistitemgroup, "dropDownList" )
function dropdownlistitemgroup:invalidateLayout()
self:updatePos()
self:setWidth( self:getDropDownList():getWidth() )
gui.panel.invalidateLayout( self )
end
function dropdownlistitemgroup:isVisible()
local dropDownList = self:getDropDownList()
return dropDownList:isVisible() and dropDownList:isActive()
end
function dropdownlistitemgroup:mousepressed( x, y, button, istouch )
if ( button == 1 ) then
local dropDownList = self:getDropDownList()
if ( dropDownList ~= gui._topPanel and
( not ( self.mouseover or self:isChildMousedOver() ) ) ) then
dropDownList:setActive( false )
end
end
return gui.panel.mousepressed( self, x, y, button, istouch )
end
function dropdownlistitemgroup:onValueChanged( oldValue, newValue )
local dropDownList = self:getDropDownList()
dropDownList:setActive( false )
dropDownList:onValueChanged( oldValue, newValue )
end
function dropdownlistitemgroup:updatePos()
local dropDownList = self:getDropDownList()
if ( dropDownList == nil ) then
return
end
local x, y = dropDownList:localToScreen()
y = y + dropDownList:getHeight()
local windowPadding = 4
local overflow = y + self:getHeight() + windowPadding
if ( overflow > love.graphics.getHeight() ) then
overflow = overflow - love.graphics.getHeight()
y = y - overflow
end
if ( y < windowPadding ) then
y = windowPadding
end
self:setPos( x, y )
end