Back to Home

ESO Lua File v101042

libraries/zo_fractiondisplay/zo_fractiondisplay.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
ZO_FractionDisplay = ZO_Object:Subclass()
function ZO_FractionDisplay:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_FractionDisplay:Initialize(control, font, dividerThickness)
    self.control = control
    self.numeratorLabel = control:GetNamedChild("Numerator")
    self.denominatorLabel = control:GetNamedChild("Denominator")
    self.dividerTexture = control:GetNamedChild("Divider")
    
    self.numeratorLabel:SetFont(font)
    self.denominatorLabel:SetFont(font)
    self.dividerTexture:SetHeight(dividerThickness)
    self.control:SetHeight(self.numeratorLabel:GetFontHeight() + dividerThickness + self.denominatorLabel:GetFontHeight())
end
function ZO_FractionDisplay:SetHorizontalAlignment(alignment)
    self.numeratorLabel:SetHorizontalAlignment(alignment)
    self.denominatorLabel:SetHorizontalAlignment(alignment)
end
function ZO_FractionDisplay:SetValues(numerator, denominator)
    --Give the label enough space so that it won't wrap on initial layout
    self.numeratorLabel:SetWidth(500)
    self.denominatorLabel:SetWidth(500)
    self.numeratorLabel:SetText(numerator)
    self.denominatorLabel:SetText(denominator)
    local numeratorWidth = self.numeratorLabel:GetTextWidth()
    local denominatorWidth = self.denominatorLabel:GetTextWidth()
    local maxWidth = zo_max(numeratorWidth, denominatorWidth)
    self.control:SetWidth(maxWidth)
    self.numeratorLabel:SetWidth(maxWidth)
    self.dividerTexture:SetWidth(maxWidth)
    self.denominatorLabel:SetWidth(maxWidth)
end