add tooltip class
This commit is contained in:
parent
57ac1247fa
commit
94305e5477
3 changed files with 65 additions and 2 deletions
|
@ -24,7 +24,6 @@ function self.createButtons()
|
|||
local s = {}
|
||||
buttonId = 0
|
||||
|
||||
--[[
|
||||
insertButton(s, {
|
||||
x = outerpadding,
|
||||
y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32,
|
||||
|
@ -32,7 +31,6 @@ function self.createButtons()
|
|||
name = 'clipboard',
|
||||
displayname = 'Copy to Clipboard'
|
||||
})
|
||||
]]
|
||||
|
||||
buttons = s
|
||||
end
|
||||
|
@ -71,6 +69,7 @@ function self.render()
|
|||
love.graphics.setColor(0, 0, 0, 1)
|
||||
if hovering or dragging then
|
||||
love.graphics.setColor(0.2, 0.2, 0.3, 1)
|
||||
tooltips.show('Copy to Clipboard')
|
||||
end
|
||||
love.graphics.rectangle('fill', x, y, w, h)
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
|
|
6
main.lua
6
main.lua
|
@ -12,6 +12,7 @@ slider = require 'slider'
|
|||
dropdown = require 'dropdown'
|
||||
graph = require 'graph'
|
||||
button = require 'button'
|
||||
tooltips = require 'tooltips'
|
||||
|
||||
modes = {
|
||||
preview = 1,
|
||||
|
@ -52,6 +53,7 @@ function love.update(dt)
|
|||
slider.update(dt)
|
||||
dropdown.update(dt)
|
||||
button.update(dt)
|
||||
tooltips.update(dt)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
|
@ -68,6 +70,8 @@ function love.draw()
|
|||
love.graphics.setColor(0.2, 0.2, 0.3, 1)
|
||||
love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - fontHeight - outerpadding)
|
||||
|
||||
tooltips.prerender()
|
||||
|
||||
button.render()
|
||||
|
||||
slider.render()
|
||||
|
@ -75,6 +79,8 @@ function love.draw()
|
|||
dropdown.render()
|
||||
|
||||
graph.render()
|
||||
|
||||
tooltips.render()
|
||||
end
|
||||
|
||||
function love.mousepressed(x, y, m)
|
||||
|
|
58
tooltips.lua
Normal file
58
tooltips.lua
Normal file
|
@ -0,0 +1,58 @@
|
|||
local self = {}
|
||||
|
||||
local tooltipwidth = 0
|
||||
local tooltipx = 0
|
||||
local tooltipy = 0
|
||||
|
||||
local tooltipopen = false
|
||||
local tooltiptext = ''
|
||||
local tooltiptargetwidth = 0
|
||||
|
||||
local tooltipframe = false
|
||||
|
||||
function self.update(dt)
|
||||
local mx, my = love.mouse.getPosition()
|
||||
tooltipx = mix(tooltipx, mx, dt * 14)
|
||||
tooltipy = mix(tooltipy, my, dt * 14)
|
||||
|
||||
tooltipwidth = mix(tooltipwidth, tooltiptargetwidth, dt * 12)
|
||||
end
|
||||
|
||||
function self.prerender()
|
||||
tooltipframe = false
|
||||
end
|
||||
|
||||
function self.show(text)
|
||||
tooltipframe = true
|
||||
tooltiptext = text
|
||||
tooltiptargetwidth = love.graphics.newText(love.graphics.getFont(), text):getWidth()
|
||||
end
|
||||
|
||||
function self.render()
|
||||
local mx, my = love.mouse.getPosition()
|
||||
if not tooltipframe then
|
||||
tooltiptargetwidth = 0
|
||||
end
|
||||
|
||||
if tooltipwidth > 1 then
|
||||
local a = math.min((tooltipwidth - 1) / 6, 1)
|
||||
|
||||
love.graphics.push()
|
||||
|
||||
love.graphics.translate(mx + 16, my + 16)
|
||||
|
||||
love.graphics.setColor(0.2, 0.2, 0.3, a)
|
||||
love.graphics.rectangle('fill', 0, 0, tooltipwidth + 4 + margin, fontHeight + margin)
|
||||
|
||||
love.graphics.setScissor(0, 0, mx + tooltipwidth + 2 + margin/2 + 16, love.graphics.getHeight())
|
||||
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.print(tooltiptext, 2 + margin/2, 2 + margin/2)
|
||||
|
||||
love.graphics.setScissor()
|
||||
|
||||
love.graphics.pop()
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
Loading…
Reference in a new issue