@@ -9,23 +9,16 @@ local Frame = setmetatable({}, Container)
99Frame .__index = Frame
1010
1111--- @property draggable boolean false Whether the frame is draggable
12- Frame .defineProperty (Frame , " draggable" , {default = false , type = " boolean" , setter = function (self , value )
13- if value then
14- self :listenEvent (" mouse_click" , true )
15- self :listenEvent (" mouse_up" , true )
16- self :listenEvent (" mouse_drag" , true )
17- end
18- return value
19- end })
12+ Frame .defineProperty (Frame , " draggable" , {default = false , type = " boolean" })
2013--- @property draggingMap table {} The map of dragging positions
2114Frame .defineProperty (Frame , " draggingMap" , {default = {{x = 1 , y = 1 , width = " width" , height = 1 }}, type = " table" })
2215--- @property scrollable boolean false Whether the frame is scrollable
23- Frame .defineProperty (Frame , " scrollable" , {default = false , type = " boolean" , setter = function ( self , value )
24- if value then
25- self : listenEvent ( " mouse_scroll " , true )
26- end
27- return value
28- end } )
16+ Frame .defineProperty (Frame , " scrollable" , {default = false , type = " boolean" } )
17+
18+ Frame . defineEvent ( Frame , " mouse_click " )
19+ Frame . defineEvent ( Frame , " mouse_drag " )
20+ Frame . defineEvent ( Frame , " mouse_up " )
21+ Frame . defineEvent ( Frame , " mouse_scroll " )
2922
3023--- Creates a new Frame instance
3124--- @shortDescription Creates a new Frame instance
5952--- @return boolean handled Whether the event was handled
6053--- @protected
6154function Frame :mouse_click (button , x , y )
62- if VisualElement . mouse_click ( self , button , x , y ) then
55+ if self : isInBounds ( x , y ) then
6356 if self .get (" draggable" ) then
6457 local relX , relY = self :getRelativePosition (x , y )
6558 local draggingMap = self .get (" draggingMap" )
@@ -150,23 +143,33 @@ function Frame:getChildrenHeight()
150143 return maxHeight
151144end
152145
146+ local function convertMousePosition (self , event , ...)
147+ local args = {... }
148+ if event and event :find (" mouse_" ) then
149+ local button , absX , absY = ...
150+ local xOffset , yOffset = self .get (" offsetX" ), self .get (" offsetY" )
151+ local relX , relY = self :getRelativePosition (absX + xOffset , absY + yOffset )
152+ args = {button , relX , relY }
153+ end
154+ return args
155+ end
156+
153157--- @shortDescription Handles mouse scroll events
154158--- @param direction number The scroll direction
155159--- @param x number The x position of the scroll
156160--- @param y number The y position of the scroll
157161--- @return boolean handled Whether the event was handled
158162--- @protected
159163function Frame :mouse_scroll (direction , x , y )
160- if Container .mouse_scroll (self , direction , x , y ) then
161- return true
162- end
163-
164- if self . get ( " scrollable " ) then
165- local relX , relY = self : getRelativePosition ( x , y )
166- local width = self .get (" width " )
167- local height = self .get (" height" )
164+ if ( VisualElement .mouse_scroll (self , direction , x , y )) then
165+ local args = convertMousePosition ( self , " mouse_scroll " , direction , x , y )
166+ local success , child = self : callChildrenEvent ( true , " mouse_scroll " , table.unpack ( args ))
167+ if success then
168+ return true
169+ end
170+ if self .get (" scrollable " ) then
171+ local height = self .get (" height" )
168172
169- if relX >= 1 and relX <= width and relY >= 1 and relY <= height then
170173 local childrenHeight = self :getChildrenHeight ()
171174 local currentOffset = self .get (" offsetY" )
172175 local maxScroll = math.max (0 , childrenHeight - height )
@@ -178,7 +181,6 @@ function Frame:mouse_scroll(direction, x, y)
178181 return true
179182 end
180183 end
181-
182184 return false
183185end
184186
0 commit comments