Skip to content

Commit

Permalink
add SetTextSize to TOOLTIP
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Feb 19, 2023
1 parent 5925218 commit 4533e70
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions Themes/_fallback/Scripts/96 Tooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ function TOOLTIP.New(self)
end,
OffCommand = function(self)
self:visible(false)
end
end,
ResizeCommand = function(self)
local txt = self:GetChild("Text")
local box = self:GetChild("Box")

txt:zoom(textScale)

local height = txt:GetZoomedHeight()
local width = txt:GetZoomedWidth()
box:zoomto(width + boxBorder * 2, height + boxBorder * 2)
end,
}

t[#t+1] = Def.Quad{
Expand All @@ -49,7 +59,7 @@ function TOOLTIP.New(self)
InitCommand = function(self)
self:zoom(textScale)
self:halign(0):valign(0)
self:xy(boxBorder / textScale, boxBorder / textScale)
self:xy(boxBorder, boxBorder)
end,
}

Expand All @@ -59,7 +69,6 @@ function TOOLTIP.New(self)
self:zoomto(cursorSize, cursorSize)
self:visible(false)
TOOLTIP.Pointer = self

end,
OnCommand = function(self)
end,
Expand All @@ -73,7 +82,6 @@ function TOOLTIP.New(self)
InitCommand = function(self)
self:diffusealpha(0)
TOOLTIP.ClickWave = self

end,
OnCommand = function(self)
end,
Expand All @@ -95,10 +103,7 @@ end

function TOOLTIP.SetText(self, text)
self.Actor:GetChild("Text"):settext(text)
local height = self.Actor:GetChild("Text"):GetHeight() * textScale
local width = self.Actor:GetChild("Text"):GetWidth() * textScale

self.Actor:GetChild("Box"):zoomto(width + boxBorder * 2 / textScale, height + boxBorder * 2 / textScale)
self.Actor:playcommand("Resize")
end

function TOOLTIP.Show(self)
Expand All @@ -117,9 +122,18 @@ function TOOLTIP.HidePointer(self)
self.Pointer:visible(false)
end

function TOOLTIP.SetTextSize(self, zoom)
textScale = zoom
self.Actor:playcommand("Resize")
end

function TOOLTIP.GetTextSize(self)
return textScale
end

function TOOLTIP.SetPosition(self, x, y)
local height = (self.Actor:GetChild("Text"):GetHeight() * textScale) + boxBorder * 2 / textScale
local width = (self.Actor:GetChild("Text"):GetWidth() * textScale) + boxBorder * 2 / textScale
local height = (self.Actor:GetChild("Text"):GetHeight() * textScale) + boxBorder * 2
local width = (self.Actor:GetChild("Text"):GetWidth() * textScale) + boxBorder * 2

self.Pointer:xy(x, y)

Expand All @@ -129,14 +143,14 @@ function TOOLTIP.SetPosition(self, x, y)
clamp(y + tooltipOffSetY, screenBorder, SCREEN_HEIGHT - screenBorder - height)
)
self.Actor:GetChild("Box"):halign(1)
self.Actor:GetChild("Text"):halign(1):x(-boxBorder / textScale)
self.Actor:GetChild("Text"):halign(1):x(-boxBorder)
else
self.Actor:xy(
clamp(x + tooltipOffSetX, screenBorder, SCREEN_WIDTH - screenBorder - width),
clamp(y + tooltipOffSetY, screenBorder, SCREEN_HEIGHT - screenBorder - height)
)
self.Actor:GetChild("Box"):halign(0)
self.Actor:GetChild("Text"):halign(0):x(boxBorder / textScale)
self.Actor:GetChild("Text"):halign(0):x(boxBorder)
end

-- if the mouse ends up on top of the tooltip we may lose visibility on things
Expand Down

0 comments on commit 4533e70

Please sign in to comment.