This commit is contained in:
Paul Liverman III 2017-08-13 18:15:08 -07:00
parent c9df709c80
commit 048e8c7961
6 changed files with 32 additions and 15 deletions

View File

@ -325,6 +325,7 @@ do
self.header.mousereleased = function(self, x, y, button) self.header.mousereleased = function(self, x, y, button)
if button == pop.constants.left_mouse then if button == pop.constants.left_mouse then
selected = false selected = false
pop.focused = false
return true return true
end end
return false return false

View File

@ -152,6 +152,7 @@ class window extends element
@header.mousereleased = (x, y, button) => @header.mousereleased = (x, y, button) =>
if button == pop.constants.left_mouse if button == pop.constants.left_mouse
selected = false selected = false
pop.focused = false -- maybe it should check if it is focused first?
return true return true
return false return false

View File

@ -300,17 +300,20 @@ pop.mousereleased = function(x, y, button, element)
end end
else else
log("mousereleased", x, y, button) log("mousereleased", x, y, button)
if element == pop.focused then do
if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then element = pop.focused
if element.clicked then if element then
clickedHandled = element:clicked(x - element.data.x, y - element.data.y, button) if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then
if element.clicked then
clickedHandled = element:clicked(x - element.data.x, y - element.data.y, button)
end
end
if element.mousereleased then
mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button)
end
if clickedHandled ~= false or mousereleasedHandled ~= false then
return clickedHandled, mousereleasedHandled
end end
end
if element.mousereleased then
mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button)
end
if clickedHandled ~= false or mousereleasedHandled ~= false then
return clickedHandled, mousereleasedHandled
end end
end end
pop.mousereleased(x, y, button, pop.screen) pop.mousereleased(x, y, button, pop.screen)

View File

@ -374,7 +374,7 @@ pop.mousereleased = (x, y, button, element) ->
if element.mousereleased if element.mousereleased
mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button
-- if we clicked, we're focused! -- if we clicked (AND returned true), we're focused!
if clickedHandled != false if clickedHandled != false
log " #{clickedHandled} (click handled)", "#{element} (#{element.data.type})" log " #{clickedHandled} (click handled)", "#{element} (#{element.data.type})"
if clickedHandled if clickedHandled
@ -393,7 +393,7 @@ pop.mousereleased = (x, y, button, element) ->
else else
log "mousereleased", x, y, button log "mousereleased", x, y, button
if element == pop.focused if element = pop.focused
if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h)
if element.clicked if element.clicked
clickedHandled = element\clicked x - element.data.x, y - element.data.y, button clickedHandled = element\clicked x - element.data.x, y - element.data.y, button

View File

@ -51,7 +51,9 @@ love.load = function()
h = 10 h = 10
}):align("center", "bottom") }):align("center", "bottom")
pop.text(centerBox, "Align me!"):align("right", "top") pop.text(centerBox, "Align me!"):align("right", "top")
pop.window(centerBox):align("right", "bottom") pop.window(centerBox, {
closeable = true
}):align("right", "bottom")
centerBox:setPadding(5) centerBox:setPadding(5)
pop.box(centerBox, { pop.box(centerBox, {
w = 10, w = 10,
@ -119,7 +121,7 @@ love.load = function()
100 100
} }
}, "Align me!"):align("right", "top") }, "Align me!"):align("right", "top")
return pop.window(centerBox, { pop.window(centerBox, {
titleColor = { titleColor = {
0, 0,
0, 0,
@ -139,6 +141,14 @@ love.load = function()
100 100
} }
}):align("right", "bottom") }):align("right", "bottom")
pop.window(centerBox, {
containMethod = "title",
w = 125
}, "Title can't leave")
return pop.window(centerBox, {
containMethod = "body",
w = 125
}, "Body can't leave")
end end
local new_method local new_method
new_method = function() new_method = function()

View File

@ -24,7 +24,7 @@ love.load = ->
pop.box(centerBox)\align("left", "bottom")\setSize 5, 5 pop.box(centerBox)\align("left", "bottom")\setSize 5, 5
pop.box(centerBox, {w: 25, h: 10})\align "center", "bottom" pop.box(centerBox, {w: 25, h: 10})\align "center", "bottom"
pop.text(centerBox, "Align me!")\align "right", "top" pop.text(centerBox, "Align me!")\align "right", "top"
pop.window(centerBox)\align "right", "bottom" pop.window(centerBox, {closeable: true})\align "right", "bottom"
centerBox\setPadding 5 centerBox\setPadding 5
@ -36,6 +36,8 @@ love.load = ->
pop.box(centerBox, {w: 25, h: 10, background: {0, 0, 255, 100}})\align "center", "bottom" pop.box(centerBox, {w: 25, h: 10, background: {0, 0, 255, 100}})\align "center", "bottom"
pop.text(centerBox, {color: {0, 0, 255, 100}}, "Align me!")\align "right", "top" pop.text(centerBox, {color: {0, 0, 255, 100}}, "Align me!")\align "right", "top"
pop.window(centerBox, {titleColor: {0, 0, 0, 150}, titleBackground: {0, 0, 255, 100}, windowBackground: {200, 200, 255, 100}})\align "right", "bottom" pop.window(centerBox, {titleColor: {0, 0, 0, 150}, titleBackground: {0, 0, 255, 100}, windowBackground: {200, 200, 255, 100}})\align "right", "bottom"
pop.window(centerBox, {containMethod: "title", w: 125}, "Title can't leave")
pop.window(centerBox, {containMethod: "body", w: 125}, "Body can't leave")
new_method = -> new_method = ->
partsGrid = pop.dynamicGrid! partsGrid = pop.dynamicGrid!