StatusBar
CreateFrame("StatusBar", …) makes one. It has every method of Frame, plus 28 of its own.
Inherits from
- StatusBar · 28
- Frame · 126
- Region · 16
- ScriptRegion · 55
- ScriptRegionResizing · 13
- AnimatableObject · 3
- Object · 5
- FrameScriptObject · 21
The number is each type's own documented methods. A StatusBar has all of them.
Example
A health bar for the player. The bar takes UnitHealth as it is, secret or
not.
import unitEvent from "wowlua:events" -- The player's health, in a bar below the character.export local healthBar = CreateFrame("StatusBar", nil, UIParent)healthBar:SetSize(200, 16)healthBar:SetPoint("CENTER", 0, -120)healthBar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")healthBar:SetStatusBarColor(0.1, 0.8, 0.2) local function update() -- The range first: a value outside the range is clamped into it. healthBar:SetMinMaxValues(0, UnitHealthMax("player")) healthBar:SetValue(UnitHealth("player"))end @unitEvent("UNIT_HEALTH", "player")@unitEvent("UNIT_MAXHEALTH", "player")local function healthChanged(_unit: UnitToken) update()end update()Methods
In the emulator: 25 implemented, 3 guessed.
A status bar in wowlua test keeps its range and value the way the client
does. This was recorded from the client:
- Values are kept as 32-bit floats, so
SetValue(7.3)reads back as7.3000001907349. - The range is 0 to 0 until
SetMinMaxValuessets it, and a value is clamped into the range. ASetValuebefore the firstSetMinMaxValuesis lost: the value stays 0. The first range then clamps the value without runningOnValueChanged, so a new bar given the range 3 to 10 reads 3. Set the range first, as Blizzard's unit frames do inUnitFrameHealthBar_Update. OnValueChanged(self, value)runs at once, even while the bar is hidden, and only when the value actually changes. A status bar passes only the value. TheuserInputargument is a slider's.SetMinMaxValuesrunsOnMinMaxChanged(self, min, max)when the range changes, then clamps the value into the new range, which runsOnValueChangedif the value moves. A maximum below the minimum is an error:max must be >= min.- The color is kept with 8 bits per channel, so
SetStatusBarColor(0.2, 0.8, 0.3)reads back as about0.2, 0.8, 0.302.
SetStatusBarTexture with a file path creates the bar's texture, which
GetStatusBarTexture returns. Before that, GetStatusBarTexture returns
nil. The bar's color is that texture's vertex color. A screenshot draws the
texture over the part of the bar the value fills, following SetOrientation
and SetReverseFill.
The emulator doesn't animate. With an interpolation argument, the bar still
jumps straight to the new value, GetInterpolatedValue returns that value
and IsInterpolating returns false.
SetValue and SetMinMaxValues accept secret values. After a secret one,
GetValue or GetMinMaxValues returns a secret, and OnValueChanged or
OnMinMaxChanged gets the value or range as a secret. The handlers' value
is typed number | Secret<number>; the getters are typed number, or
number | Secret<number> with check.secret-widget-results. They return
plain numbers again after the next plain SetValue or SetMinMaxValues. In a camelot test, UnitHealth("player") returns a
secret, so a health bar's GetValue returns one too.
| method | what it does | status |
|---|---|---|
GetFillStyle | Returns how the status bar fills. · by wowlua(): StatusBarFillStyle | implemented |
GetInterpolatedValue | Returns the current interpolated value displayed by the bar. · warcraft.wiki.gg ↗(): number | implemented |
GetMinMaxValues | Returns the minimum and maximum values of a status bar. · warcraft.wiki.gg ↗(): (number, number) | implemented |
GetOrientation | Returns whether the status bar is horizontal or vertical. · by wowlua(): Orientation | implemented |
GetRenderMode | Returns how the status bar draws its fill: linear or radial. · by wowlua(): StatusBarRenderMode | guessed |
GetReverseFill | Whether the status bar fills in the reverse direction. · by wowlua(): boolean | implemented |
GetRotatesTexture | Whether the bar texture is rotated along with a vertical orientation. · by wowlua(): boolean | implemented |
GetStatusBarColor | Returns the color of the status bar. · warcraft.wiki.gg ↗(): (number, number, number, number) | implemented |
GetStatusBarDesaturation | Returns how much the bar texture is desaturated, from 0 to 1. · by wowlua(): normalizedValue | guessed |
GetStatusBarTexture | Returns the status bar's fill texture. · by wowlua(): Texture | implemented |
GetTimerDuration | Returns the duration the status bar tracks as a timer. · by wowlua(): LuaDurationObject | guessed |
GetValue | Returns the status bar's current value. · by wowlua(): number | implemented |
IsInterpolating | Returns true if the status bar is currently interpolating toward a target value. · warcraft.wiki.gg ↗(): boolean | implemented |
IsStatusBarDesaturated | Whether the bar texture is shown desaturated. · by wowlua(): boolean | implemented |
SetColorFill | Fills the status bar with a solid color. · by wowlua(colorR: number, colorG: number, colorB: number, a: number?) | implemented |
SetFillStyle | Set the style in which the bar will be filled. · warcraft.wiki.gg ↗(fillStyle: StatusBarFillStyle) | implemented |
SetMinMaxValues | Sets the status bar's lowest and highest values. · by wowlua(minValue: number, maxValue: number, interpolation: StatusBarInterpolation) | implemented |
SetOrientation | Sets whether the status bar is horizontal or vertical. · by wowlua(orientation: Orientation) | implemented |
SetRenderMode | Sets how the status bar draws its fill: linear, by resizing the bar texture, or radial, by driving the texture's radial fill progress. · by wowlua(renderMode: StatusBarRenderMode) | implemented |
SetReverseFill | Sets the fill direction of the status bar. · warcraft.wiki.gg ↗(isReverseFill: boolean) | implemented |
SetRotatesTexture | Sets whether the bar texture is rotated along with a vertical orientation. · by wowlua(rotatesTexture: boolean) | implemented |
SetStatusBarColor | Sets the color of the status bar. · warcraft.wiki.gg ↗(colorR: number, colorG: number, colorB: number, a: number?) | implemented |
SetStatusBarDesaturated | Sets whether the bar texture is shown desaturated. · by wowlua(desaturated: boolean) | implemented |
SetStatusBarDesaturation | Sets how much the bar texture is desaturated, from 0 to 1. · by wowlua(desaturation: normalizedValue) | implemented |
SetStatusBarTexture | Sets the texture of the status bar. · warcraft.wiki.gg ↗(asset: TextureAsset): boolean | implemented |
SetTimerDuration | Makes the status bar track a duration as a timer. · by wowlua(duration: LuaDurationObject, interpolation: StatusBarInterpolation, direction: StatusBarTimerDirection) | implemented |
SetToTargetValue | Immediately finishes any interpolation of the bar and snaps it to the target value. · warcraft.wiki.gg ↗() | implemented |
SetValue | Sets the current value of the status bar. · warcraft.wiki.gg ↗(value: number, interpolation: StatusBarInterpolation) | implemented |
Testing it
mock.player:damage lowers the player's health and fires UNIT_HEALTH.
Because the bar's value is a secret, check that it is one with toBeSecret,
and check what the bar shows with toMatchScreenshot.
mock.setPlayer(data, { events = true }) changes the player's maximum health
and fires UNIT_MAXHEALTH. Without events = true, it fires nothing.
import test, expect from "wowlua:test"import * as mock from "wowlua:mock"import healthBar from "/healthbar" @test("the bar follows the player's health")local function followsHealth() mock.setPlayer({ health = 60, maxHealth = 60 }) mock.player:damage(15) expect(healthBar:GetValue()).toBeSecret() expect(healthBar).toMatchScreenshot("hurt")end @test("the range follows the maximum health")local function followsMaximum() mock.setPlayer({ health = 100, maxHealth = 120 }, { events = true }) local min, max = healthBar:GetMinMaxValues() expect(min).toBe(0) expect(max).toBe(120)endThe first run writes the screenshot to
tests/__screenshots__/healthbar.test.wowlua/, and later runs compare against
it. Here it shows the bar three quarters full.
sources
Methods and inheritance: Blizzard's API documentation (Blizzard_APIDocumentationGenerated) (camelot 1.60.1). Descriptions: warcraft.wiki.gg's API pages, by its contributors, CC BY-SA 4.0 ↗; written by wowlua where no documentation describes the entry.