mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
getRectangle returns x,y,w,h instead of x1,y1,x2,y2
This commit is contained in:
@@ -12,9 +12,9 @@ return function (self)
|
||||
end)
|
||||
|
||||
self:onReshape(function ()
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local x, y, w, h = self:getRectangle(true, true)
|
||||
local min = bar.minwidth
|
||||
x1 = x1 + min
|
||||
bar.width = self.value * (x2 - x1) + min
|
||||
x = x + min
|
||||
bar.width = self.value * w + min
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -35,7 +35,8 @@ return function (self)
|
||||
end)
|
||||
|
||||
local function press (event)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local x1, y1, w, h = self:getRectangle(true, true)
|
||||
local x2, y2 = x1 + w, y1 + h
|
||||
local halfThumb = thumb:getWidth() / 2
|
||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||
self.value = clamp((event.x - x1) / (x2 - x1))
|
||||
@@ -58,7 +59,9 @@ return function (self)
|
||||
end)
|
||||
|
||||
self:onReshape(function (event)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
-- TODO: eliminate redundancy with `press`
|
||||
local x1, y1, w, h = self:getRectangle(true, true)
|
||||
local x2, y2 = x1 + w, y1 + h
|
||||
local halfThumb = thumb:getWidth() / 2
|
||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||
spacer.width = self.value * (x2 - x1)
|
||||
|
||||
@@ -4,7 +4,8 @@ local utf8 = require(ROOT .. 'utf8')
|
||||
local Backend = require(ROOT .. 'backend')
|
||||
|
||||
local function scrollToCaret (self)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local x1, y1, w, h = self:getRectangle(true, true)
|
||||
local x2, y2 = x1 + w, y1 + h
|
||||
local oldX = self.endX
|
||||
local newX
|
||||
|
||||
@@ -24,8 +25,8 @@ end
|
||||
|
||||
local function findCaretFromText (self, text)
|
||||
local font = self.fontData
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
return #text, font:getAdvance(text) + x1 - self.scrollX
|
||||
local x = self:getRectangle(true, true)
|
||||
return #text, font:getAdvance(text) + x - self.scrollX
|
||||
end
|
||||
|
||||
local function setCaretFromText (self, text, mode)
|
||||
@@ -43,7 +44,7 @@ end
|
||||
|
||||
-- return caret index and x position
|
||||
local function findCaretFromPoint (self, x, y)
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local x1 = self:getRectangle(true, true)
|
||||
|
||||
local font = self.fontData
|
||||
local width, lastWidth = 0
|
||||
@@ -227,27 +228,27 @@ return function (self)
|
||||
|
||||
self:onDisplay(function (event)
|
||||
local startX, endX = self.startX or 0, self.endX or 0
|
||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||
local width, height = endX - startX, y2 - y1
|
||||
local x, y, w, h = self:getRectangle(true, true)
|
||||
local width, height = endX - startX, h
|
||||
local font = self.fontData
|
||||
local textColor = self.textColor or { 0, 0, 0, 255 }
|
||||
local textTop = math.floor(y1 + ((y2 - y1) - font:getLineHeight()) / 2)
|
||||
local textTop = math.floor(y + (h - font:getLineHeight()) / 2)
|
||||
|
||||
Backend.push()
|
||||
Backend.setScissor(x1, y1, x2 - x1, y2 - y1)
|
||||
Backend.setScissor(x, y, w, h)
|
||||
Backend.setFont(font)
|
||||
|
||||
-- draw highlight
|
||||
Backend.setColor(self.highlight)
|
||||
Backend.drawRectangle('fill', startX, y1, width, height)
|
||||
Backend.drawRectangle('fill', startX, y, width, height)
|
||||
if Backend.getTime() % 2 < 1.75 then
|
||||
Backend.setColor(textColor)
|
||||
Backend.drawRectangle('fill', endX, y1, 1, height)
|
||||
Backend.drawRectangle('fill', endX, y, 1, height)
|
||||
end
|
||||
|
||||
-- draw text
|
||||
Backend.setColor(textColor)
|
||||
Backend.print(self.value, x1 - self.scrollX, textTop)
|
||||
Backend.print(self.value, x - self.scrollX, textTop)
|
||||
if not self.focused then
|
||||
Backend.pop()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user