v0.13.8

StatusBar

widget type28 methodsavailable in: camelot

CreateFrame("StatusBar", …) makes one. It has every method of Frame, plus 28 of its own.

Inherits from

  1. StatusBar · 28
  2. Frame · 126
  3. Region · 16
  4. ScriptRegion · 55
  5. ScriptRegionResizing · 13
  6. AnimatableObject · 3
  7. Object · 5
  8. 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.

src/healthbar.wowluawowlua
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 as 7.3000001907349.
  • The range is 0 to 0 until SetMinMaxValues sets it, and a value is clamped into the range. A SetValue before the first SetMinMaxValues is lost: the value stays 0. The first range then clamps the value without running OnValueChanged, so a new bar given the range 3 to 10 reads 3. Set the range first, as Blizzard's unit frames do in UnitFrameHealthBar_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. The userInput argument is a slider's.
  • SetMinMaxValues runs OnMinMaxChanged(self, min, max) when the range changes, then clamps the value into the new range, which runs OnValueChanged if 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 about 0.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.

methodwhat it doesstatus
GetFillStyleReturns how the status bar fills. · by wowlua
(): StatusBarFillStyle
implemented
GetInterpolatedValueReturns the current interpolated value displayed by the bar. · warcraft.wiki.gg ↗
(): number
implemented
GetMinMaxValuesReturns the minimum and maximum values of a status bar. · warcraft.wiki.gg ↗
(): (number, number)
implemented
GetOrientationReturns whether the status bar is horizontal or vertical. · by wowlua
(): Orientation
implemented
GetRenderModeReturns how the status bar draws its fill: linear or radial. · by wowlua
(): StatusBarRenderMode
guessed
GetReverseFillWhether the status bar fills in the reverse direction. · by wowlua
(): boolean
implemented
GetRotatesTextureWhether the bar texture is rotated along with a vertical orientation. · by wowlua
(): boolean
implemented
GetStatusBarColorReturns the color of the status bar. · warcraft.wiki.gg ↗
(): (number, number, number, number)
implemented
GetStatusBarDesaturationReturns how much the bar texture is desaturated, from 0 to 1. · by wowlua
(): normalizedValue
guessed
GetStatusBarTextureReturns the status bar's fill texture. · by wowlua
(): Texture
implemented
GetTimerDurationReturns the duration the status bar tracks as a timer. · by wowlua
(): LuaDurationObject
guessed
GetValueReturns the status bar's current value. · by wowlua
(): number
implemented
IsInterpolatingReturns true if the status bar is currently interpolating toward a target value. · warcraft.wiki.gg ↗
(): boolean
implemented
IsStatusBarDesaturatedWhether the bar texture is shown desaturated. · by wowlua
(): boolean
implemented
SetColorFillFills the status bar with a solid color. · by wowlua
(colorR: number, colorG: number, colorB: number, a: number?)
implemented
SetFillStyleSet the style in which the bar will be filled. · warcraft.wiki.gg ↗
(fillStyle: StatusBarFillStyle)
implemented
SetMinMaxValuesSets the status bar's lowest and highest values. · by wowlua
(minValue: number, maxValue: number, interpolation: StatusBarInterpolation)
implemented
SetOrientationSets whether the status bar is horizontal or vertical. · by wowlua
(orientation: Orientation)
implemented
SetRenderModeSets 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
SetReverseFillSets the fill direction of the status bar. · warcraft.wiki.gg ↗
(isReverseFill: boolean)
implemented
SetRotatesTextureSets whether the bar texture is rotated along with a vertical orientation. · by wowlua
(rotatesTexture: boolean)
implemented
SetStatusBarColorSets the color of the status bar. · warcraft.wiki.gg ↗
(colorR: number, colorG: number, colorB: number, a: number?)
implemented
SetStatusBarDesaturatedSets whether the bar texture is shown desaturated. · by wowlua
(desaturated: boolean)
implemented
SetStatusBarDesaturationSets how much the bar texture is desaturated, from 0 to 1. · by wowlua
(desaturation: normalizedValue)
implemented
SetStatusBarTextureSets the texture of the status bar. · warcraft.wiki.gg ↗
(asset: TextureAsset): boolean
implemented
SetTimerDurationMakes the status bar track a duration as a timer. · by wowlua
(duration: LuaDurationObject, interpolation: StatusBarInterpolation, direction: StatusBarTimerDirection)
implemented
SetToTargetValueImmediately finishes any interpolation of the bar and snaps it to the target value. · warcraft.wiki.gg ↗
()
implemented
SetValueSets 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.

tests/healthbar.test.wowluawowlua
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)end

The 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.