2424 Slider, Color, ColorPreview
2525 Text
2626
27+ cancelMouseActions
2728 delete
2829 draw
2930 drawChecker, drawCheckerBox
@@ -165,6 +166,7 @@ export State :: struct {
165166
166167 -- @Cleanup: Use !self here istead of _*, maybe. (@Compiler: We get redeclaration error becase !self.getElement etc. isn't a simple identifier.)
167168 blurFocus :: _blurFocus,
169+ cancelMouseActions :: _cancelMouseActions,
168170 delete :: _delete,
169171 draw :: _draw,
170172 findParent :: _findParent,
@@ -199,6 +201,7 @@ export State :: struct {
199201}
200202
201203local _blurFocus :: blurFocus
204+ local _cancelMouseActions :: cancelMouseActions
202205local _delete :: delete
203206local _draw :: draw
204207local _findParent :: findParent
@@ -248,26 +251,13 @@ local register :: (state:State, el:Element, T:Type) -> Element {
248251
249252local unregisterTree :: (state:State, el:Element) {
250253 do {
251- -- @Robustness: This all is not very safe, probably...
252-
253- if state.activeId == el.id {
254- -- @Robustness: Do we need to release more buttons?
255- -- (Note that we don't want to open any context menu or anything. Maybe we need a standard way of canceling mouse stuff.)
256- local mx, my = LM.getPosition()
257- state.onMouseReleased!(mx, my, 1, 0)
258-
259- state.activeId = 0
260- state.activeSubid = 0
261- }
254+ if state.focusId == el.id state.blurFocus!(abort=false)
255+ if state.activeId == el.id state.cancelMouseActions!()
262256
263257 if state.hoveredId == el.id {
264258 state.hoveredId = 0
265259 state.hoveredSubid = 0
266260 }
267-
268- if state.focusId == el.id {
269- state.blurFocus!(abort=false)
270- }
271261 }
272262
273263 state.elementsById[el.id] = NULL
@@ -1076,14 +1066,14 @@ export onMouseMoved :: (state:State, mx,my:int, dx,dy:int, begin=false, end=fals
10761066 updateMouseCursor(state)
10771067}
10781068
1079- export onMouseReleased :: (state:State, mx,my:int, mbutton:int, presses:int) {
1069+ export onMouseReleased :: (state:State, mx,my:int, mbutton:int, presses:int, cancel=false ) {
10801070 if state.focusId {
10811071 local input = cast(InputText) state.elementsById[state.focusId]
10821072 if input.field.mousereleased!(mx, my, mbutton) state.onMouseMoved!(mx, my, 0, 0)
10831073 }
10841074
10851075 -- LMB.
1086- if mbutton == 1 and state.activeId {
1076+ if mbutton == 1 and state.activeId and not cancel {
10871077 local widget = cast(Widget) state.elementsById[state.activeId]
10881078
10891079 if widget ~= NULL if widget.type == {
@@ -1153,7 +1143,7 @@ export onMouseReleased :: (state:State, mx,my:int, mbutton:int, presses:int) {
11531143 }
11541144
11551145 -- MMB.
1156- if mbutton == 3 and not state.activeId and state.hoveredId {
1146+ if mbutton == 3 and not state.activeId and state.hoveredId and not cancel {
11571147 local widget = cast(Widget) state.elementsById[state.hoveredId]
11581148
11591149 if widget ~= NULL if widget.type == {
@@ -1167,7 +1157,7 @@ export onMouseReleased :: (state:State, mx,my:int, mbutton:int, presses:int) {
11671157 }
11681158
11691159 -- RMB.
1170- if mbutton == 2 and not state.activeId and state.hoveredId {
1160+ if mbutton == 2 and not state.activeId and state.hoveredId and not cancel {
11711161 local widget = cast(Widget) state.elementsById[state.hoveredId]
11721162 local name = ""
11731163
@@ -1346,7 +1336,7 @@ export onMouseReleased :: (state:State, mx,my:int, mbutton:int, presses:int) {
13461336 }
13471337
13481338 -- Release active ID.
1349- if state.activeId and mbutton == 1 {
1339+ if state.activeId and ( mbutton == 1 or cancel) {
13501340 if state.elementsById[state.activeId] ~= NULL state.onMouseMoved!(mx, my, 0, 0, end=true)
13511341
13521342 if state.activeDragging {
@@ -1379,6 +1369,16 @@ export onMouseReleased :: (state:State, mx,my:int, mbutton:int, presses:int) {
13791369 }
13801370}
13811371
1372+ export cancelMouseActions :: (state:State) {
1373+ if state.activeId {
1374+ local mx, my = LM.getPosition()
1375+ state.onMouseReleased!(mx, my, 1, 0, cancel=true)
1376+
1377+ state.activeId = 0
1378+ state.activeSubid = 0
1379+ }
1380+ }
1381+
13821382export onMouseWheel :: (state:State, dx,dy:int) -> (handled:bool) {
13831383 if state.activeId return true
13841384 if getModifierKey() ~= .NONE return false
0 commit comments