Skip to main content
Version: v3

TEXT_IMG

Support displaying text as images, you need to pass in the image font array font_array.

Create UI widget

const textImg = hmUI.createWidget(hmUI.widget.TEXT_IMG, Param)

Type

Param: object

PropertiesDescriptionRequiredType
xThe x-axis coordinate of the component.YESnumber
yThe y-axis coordinate of the component.YESnumber
wThe width of the component.It will be calculated automatically according to the type if not written.YESnumber
hThe height of the component.It will be calculated automatically according to the type if not written.YESnumber
font_arrayImage font array.To sort by 0-9.YESarray
typeThe type of data. See the data_type.NOnumber
textIt is used to specify the text content to be displayed; the type attribute will be disabled when this field is specified; the content only supports 0-9.NOstring
unit_scSimplified Chinese Units.NOstring
unit_enEnglish Units.NOstring
unit_tcTraditional Chinese Unit.NOstring
imperial_unit_scChinese Simplified (English Units).NOstring
imperial_unit_enEnglish imperial units.NOstring
imperial_unit_tcTraditional Chinese (English Units).NOstring
negative_imageNegative sign picture.NOstring
dot_imageDecimal-point-pictures can be used as separators.NOstring
h_spaceThe font of space.NOnumber
align_hHorizontal axis alignment (see ALIGN for values).NOALIGN

ALIGN alignment

ValueDescription
hmUI.align.LEFTHorizontal axis-left aligned
hmUI.align.RIGHTHorizontal axis-align right
hmUI.align.CENTER_HHorizontal axis-centered

Text field binding unit minus sign decimal point resource picture.

CharactersCorresponding Resources
uInternational units and imperial units
-Negative Sign Picture
.Decimal point picture

If the text field is set to "12u", the preceding 12 will go to the picture array to fetch the corresponding picture. When it encounters u, it will be automatically converted to a unit picture for drawing.

Update Text

const widget = hmUI.createWidget(hmUI.widget.TEXT_IMG, Param)
const text = '12' //If you want to not display the data write "" directly.
widget.setProperty(hmUI.prop.TEXT, text)

Code example

const fontArray = [
fontRootPath + '00.png',
fontRootPath + '01.png',
fontRootPath + '02.png',
fontRootPath + '03.png',
fontRootPath + '04.png',
fontRootPath + '05.png',
fontRootPath + '06.png',
fontRootPath + '07.png',
fontRootPath + '08.png',
fontRootPath + '09.png'
]

const dayText = hmUI.createWidget(hmUI.widget.TEXT_IMG, {
x: 207,
y: 340,
type: hmUI.data_type.BATTERY,
font_array: fontArray,
h_space: 1,
align_h: 16,
text: '123'
})