This commit is contained in:
SweetSea-ButImNotSweet
2024-05-21 20:07:53 +07:00
parent 7c39c1ada8
commit 5cf9deb9eb
7 changed files with 149 additions and 61 deletions

View File

@@ -7,10 +7,13 @@ FONT_tromi = love.graphics.newFont('res/fonts/monofonto rg.otf', 28)
FONT_big = love.graphics.newFont('res/fonts/monofonto rg.otf', 56)
local font_height = FONT_tromi:getHeight() * 0.5
local font_big_height = FONT_big:getHeight() * 0.5
-- BUTTON library
BUTTON = require "libs.simple-button"
BUTTON.setDefaultOption{
draw = function(self)
local need_big_font = (self.font == FONT_big)
love.graphics.setColor(0, 0, 0, 0.8)
love.graphics.rectangle('fill', self.x, self.y, self.w, self.h, self.r)
@@ -21,14 +24,25 @@ BUTTON.setDefaultOption{
local lineAmount
do
local _, t = FONT_tromi:getWrap(self.text, self.w * 2)
local _, t
if need_big_font then
_, t = FONT_big:getWrap(self.text, self.w * 2)
else
_, t = FONT_tromi:getWrap(self.text, self.w * 2)
end
lineAmount = #t
end
local textHeight = font_height * (lineAmount * 0.5)
local _font_height = need_big_font and font_big_height or font_height
local textHeight = _font_height * (lineAmount * 0.5)
local textPos = self.y + (self.h * 0.5) - textHeight
drawText(self.text, self.x, textPos, self.w, 'center')
if need_big_font then
drawBigText(self.text, self.x, textPos, self.w, 'center')
else
drawText(self.text, self.x, textPos, self.w, 'center')
end
love.graphics.setColor(1, 1, 1, 0.8)
love.graphics.setLineWidth(1)