widget.newProgressView()

类型 函数
widget.*
返回值 ProgressViewWidget
修订 版本 2024.3703
关键词 widget, progress, progressView, progressIndicator
另请参阅 ProgressViewWidget

概述

创建一个 ProgressViewWidget 对象。

注意事项

语法

widget.newProgressView( options )

此函数接受一个参数 options,它是一个包含以下参数的表:

id (可选)

字符串分配给进度视图的可选标识。默认为 widget_progressView

x, y (可选)

数字控件 xy 中心点的坐标。如果定义了 lefttop 值,则这些值将被覆盖。

left, top (可选)

数字创建控件的左侧和顶部位置。如果指定,这些值将覆盖 xy 参数。

width (必填)

数字进度视图的总宽度。

isAnimated (可选)

布尔值如果进度更改应为动画,则设置为 true;如果进度更改应立即发生,则设置为 false(或省略)。

fillXOffset (可选)

数字设置此值可水平偏移进度视图的填充区域。默认为 0

fillYOffset (可选)

数字设置此值可垂直偏移进度视图的填充区域。默认为 0

视觉定制

可以使用 图像表单 对进度视图控件进行视觉定制。如下例所示,可以使用 6 个帧来组装外部边框和内部填充条。外部边框由左帽(红色)、中间跨度(绿色)和右帽(黄色)组成。内部填充区域由左帽(橙色)、中间跨度(蓝色)和右帽(紫色)组成。

根据进度视图的宽度,外部边框帽保持图像表单中规定的尺寸,中间帧(绿色)拉伸以填充它们之间的宽度。当进度设置为高于 0.0 的任何值时,内部左帽和右帽将变为可见。然后,根据当前百分比,中间填充跨度(蓝色)将拉伸以填充两个帽之间的距离。

 → 
sheet (必填)

ImageSheet进度视图的 图像表单 对象。

fillOuterLeftFrame (必填)

数字外部边框左帽的帧索引。

fillOuterMiddleFrame (必填)

数字外部边框中间跨度的帧索引。

fillOuterRightFrame (必填)

数字外部边框右帽的帧索引。

fillOuterWidth, fillOuterHeight (必填)

数字外部边框帧的宽度/高度。所有边框帧应共享相同的宽度和高度。

fillInnerLeftFrame (必填)

数字内部填充左帽的帧索引。

fillInnerMiddleFrame (必填)

数字内部填充中间跨度的帧索引。

fillInnerRightFrame (必填)

数字内部填充右帽的帧索引。

fillWidth, fillHeight (必填)

数字内部填充帧的宽度/高度。所有填充帧应共享相同的宽度和高度。

方法

object:setProgress()

object:getProgress()

object:resizeView()

示例

默认
local widget = require( "widget" )

-- Create the widget
local progressView = widget.newProgressView(
    {
        left = 50,
        top = 200,
        width = 220,
        isAnimated = true
    }
)

-- Set the progress to 50%
progressView:setProgress( 0.5 )
图像表单
local widget = require( "widget" )

-- Image sheet options and declaration
-- For testing, you can copy/save the image under "Visual Customization" above
local options = {
    width = 64,
    height = 64,
    numFrames = 6,
    sheetContentWidth = 384,
    sheetContentHeight = 64
}
local progressSheet = graphics.newImageSheet( "widget-progress-view.png", options )

-- Create the widget
local progressView = widget.newProgressView(
    {
        sheet = progressSheet,
        fillOuterLeftFrame = 1,
        fillOuterMiddleFrame = 2,
        fillOuterRightFrame = 3,
        fillOuterWidth = 64,
        fillOuterHeight = 64,
        fillInnerLeftFrame = 4,
        fillInnerMiddleFrame = 5,
        fillInnerRightFrame = 6,
        fillWidth = 64,
        fillHeight = 64,
        left = 50,
        top = 200,
        width = 220,
        isAnimated = true
    }
)

-- Set the progress to 50%
progressView:setProgress( 0.5 )