-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathscrollablepanel.lua
88 lines (73 loc) · 2.39 KB
/
scrollablepanel.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
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Scrollable Panel class
--
--==========================================================================--
class "gui.scrollablepanel" ( "gui.box" )
local scrollablepanel = gui.scrollablepanel
function scrollablepanel:scrollablepanel( parent, name )
gui.box.box( self, parent, name )
self.panel = gui.box( self, self:getName() .. " Inner Panel" )
self.panel:setPosition( "absolute" )
self.scrollbar = gui.scrollbar( self, self:getName() .. " Scrollbar" )
self.scrollbar.onValueChanged = function( _, oldValue, newValue )
self.panel:setY( -newValue )
end
self:setScheme( "Default" )
end
accessor( scrollablepanel, "innerHeight" )
accessor( scrollablepanel, "innerPanel", nil, "panel" )
accessor( scrollablepanel, "scrollbar" )
function scrollablepanel:invalidateLayout()
self:setDimensions( self:getDimensions() )
gui.panel.invalidateLayout( self )
end
local function getParentFrame( self )
local panel = self
while ( panel ~= nil ) do
panel = panel:getParent()
if ( typeof( panel, "frame" ) ) then
return panel
end
end
end
function scrollablepanel:keypressed( key, scancode, isrepeat )
local parentFrame = getParentFrame( self )
local parentFocus = parentFrame and parentFrame.focus
if ( key == "tab" and ( self.focus or parentFocus ) ) then
gui.frame.moveFocus( self.panel )
end
return gui.panel.keypressed( self, key, scancode, isrepeat )
end
function scrollablepanel:setWidth( width )
self.panel:setWidth( width )
gui.panel.setWidth( self, width )
end
function scrollablepanel:setHeight( height )
self.scrollbar:setRangeWindow( height )
gui.panel.setHeight( self, height )
end
function scrollablepanel:setInnerHeight( innerHeight )
self.innerHeight = innerHeight
self.panel:setHeight( innerHeight )
self.scrollbar:setRange( 0, innerHeight )
end
function scrollablepanel:wheelmoved( x, y )
local panel = self:getInnerPanel()
if ( panel.mouseover or panel:isChildMousedOver() ) then
local scrollbar = self:getScrollbar()
if ( scrollbar ) then
local font = self:getScheme( "font" )
if ( y < 0 ) then
gui.setFocusedPanel( nil, false )
scrollbar:scrollDown( 3 * font:getHeight() )
return true
elseif ( y > 0 ) then
gui.setFocusedPanel( nil, false )
scrollbar:scrollUp( 3 * font:getHeight() )
return true
end
end
end
return gui.panel.wheelmoved( self, x, y )
end