App:Library:LVGL:docs:Widgets:Label (lv label)

提供: robot-jp wiki
ナビゲーションに移動検索に移動

https://docs.lvgl.io/8.2/widgets/core/arc.html

Label (lv_label)

Overview

英文 自動翻訳

A label is the basic object type that is used to display text.

ラベルは、テキストを表示するために使用される基本的なオブジェクトタイプです。
戻る : Previous


Parts and Styles

英文 自動翻訳
  • LV_PART_MAIN Uses all the typical background properties and the text properties. The padding values can be used to add space between the text and the background.
  • LV_PART_SCROLLBAR The scrollbar that is shown when the text is larger than the widget's size.
  • LV_PART_SELECTED Tells the style of the selected text. Only text_color and bg_color style properties can be used.
  • LV_PART_MAIN 一般的な背景プロパティとテキストプロパティをすべて使用します。paddingの値を使用すると、テキストと背景の間にスペースを追加することができます。
  • LV_PART_SCROLLBAR テキストがウィジェットのサイズより大きいときに表示されるスクロールバーです。
  • LV_PART_SELECTED 選択されたテキストのスタイルを指定します。text_colorbg_color のスタイルプロパティのみ使用可能です。
戻る : Previous


Usage

Set text

英文 自動翻訳

You can set the text on a label at runtime with lv_label_set_text(label, "New text").

This will allocate a buffer dynamically, and the provided string will be copied into that buffer.


Therefore, you don't need to keep the text you pass to lv_label_set_text in scope after that function returns.

With lv_label_set_text_fmt(label, "Value: %d", 15) printf formatting can be used to set the text.


Labels are able to show text from a static character buffer. To do so, use lv_label_set_text_static(label, "Text").

In this case, the text is not stored in the dynamic memory and the given buffer is used directly instead.


This means that the array can't be a local variable which goes out of scope when the function exits.


Constant strings are safe to use with lv_label_set_text_static (except when used with LV_LABEL_LONG_DOT, as it modifies the buffer in-place), as they are stored in ROM memory, which is always accessible.

lv_label_set_text(label, "New text")を使用すると、実行時にラベルのテキストを設定することができます。

これは、動的にバッファを確保し、提供された文字列は、そのバッファにコピーされます。


したがって、lv_label_set_textに渡した文字列は、この関数が戻った後もスコープに残しておく必要はありません。


lv_label_set_text_fmt(label, "Value: %d", 15) を使えば、printf フォーマットを使ってテキストを設定することができます。


ラベルは、静的な文字バッファからテキストを表示することができます。そのためには、lv_label_set_text_static(label, "Text")を使ってください。この場合、テキストはダイナミックメモリに保存されず、代わりに与えられたバッファが直接使用されます。


つまり、配列は、関数が終了したときにスコープ外に出てしまうようなローカル変数にはなりえません。


定数文字列は、常にアクセス可能な ROM メモリに格納されるため、 lv_label_set_text_static で使用しても安全です (LV_LABEL_LONG_DOT で使用すると、バッファがインプレースで変更されるため例外です)。

戻る : Previous


Newline

英文 自動翻訳

Newline characters are handled automatically by the label object.


You can use \n to make a line break.


For example: "line1\nline2\n\nline4"

改行文字はラベルオブジェクトによって自動的に処理されます。


改行するには、\nを使用します。


例えば "line1\nline2\n\nline4"

戻る : Previous


Long modes

英文 自動翻訳

By default, the width and height of the label is set to LV_SIZE_CONTENT.

Therefore, the size of the label is automatically expanded to the text size.


Otherwise, if the width or height are explicitly set (using e.g.lv_obj_set_width or a layout), the lines wider than the label's width can be manipulated according to several long mode policies.


Similarly, the policies can be applied if the height of the text is greater than the height of the label.

  • LV_LABEL_LONG_WRAP Wrap too long lines. If the height is LV_SIZE_CONTENT the label's height will be expanded, otherwise the text will be clipped. (Default)
  • LV_LABEL_LONG_DOT Replaces the last 3 characters from bottom right corner of the label with dots (.)
  • LV_LABEL_LONG_SCROLL If the text is wider than the label scroll it horizontally back and forth. If it's higher, scroll vertically. Only one direction is scrolled and horizontal scrolling has higher precedence.
  • LV_LABEL_LONG_SCROLL_CIRCULAR If the text is wider than the label scroll it horizontally continuously. If it's higher, scroll vertically. Only one direction is scrolled and horizontal scrolling has higher precedence.
  • LV_LABEL_LONG_CLIP Simply clip the parts of the text outside the label.


You can specify the long mode with lv_label_set_long_mode(label, LV_LABEL_LONG_...)

Note that LV_LABEL_LONG_DOT manipulates the text buffer in-place in order to add/remove the dots.


When lv_label_set_text or lv_label_set_array_text are used, a separate buffer is allocated and this implementation detail is unnoticed.


This is not the case with lv_label_set_text_static.

The buffer you pass to lv_label_set_text_static must be writable if you plan to use LV_LABEL_LONG_DOT.

デフォルトでは、ラベルの幅と高さはLV_SIZE_CONTENTに設定されています。

したがって、ラベルのサイズは、自動的にテキストサイズに拡大される。


そうでない場合、(例えば lv_obj_set_width やレイアウトを使って)幅や高さが明示的に設定されていれば、ラベルの幅より広い行はいくつかのロングモードポリシーに従って操作することができる。


同様に、テキストの高さがラベルの高さより大きい場合、ポリシーを適用することができます。

  • LV_LABEL_LONG_WRAP 長すぎる行を折り返す。高さがLV_SIZE_CONTENTの場合はラベルの高さが拡張され、それ以外の場合はテキストが切り取られる。(デフォルト)
  • LV_LABEL_LONG_DOT ラベルの右下隅から最後の3文字をドット (.)で置き換えます。
  • LV_LABEL_LONG_SCROLL文字の幅がラベルより大きい場合、水平方向に前後にスクロールさせます。それ以上の幅がある場合は、縦方向にスクロールします。一方向のみスクロールされ、水平方向のスクロールが優先されます。
  • LV_LABEL_LONG_SCROLL_CIRCULAR ラベルよりも文字幅が広い場合、水平方向に連続的にスクロールします。それ以上の場合は、縦にスクロールします。一方向のみスクロールされ、水平方向のスクロールが優先されます。
  • LV_LABEL_LONG_CLIP 単純にラベルの外側のテキスト部分をクリップします。


長いモードは lv_label_set_long_mode(label, LV_LABEL_LONG_...) で指定できる。


LV_LABEL_LONG_DOT はドットを追加/削除するためにインプレースでテキストバッファを操作することに注意してください。


lv_label_set_textlv_label_set_array_text を使用した場合、別のバッファが確保されるため、この実装の詳細には気付かれない。


lv_label_set_text_staticでは、このようなことはありません。

LV_LABEL_LONG_DOT を使用する場合、 lv_label_set_text_static に渡すバッファは書き込み可能でなければなりません。

戻る : Previous


Text recolor

英文 自動翻訳

In the text, you can use commands to recolor parts of the text. For example: "Write a #ff0000 red# word". This feature can be enabled individually for each label by lv_label_set_recolor() function.

テキストでは、コマンドを使用してテキストの一部を再カラー化することができます。例えば "Write a #ff0000 red# word"。この機能は、lv_label_set_recolor() 関数によって、ラベルごとに個別に有効にすることができます。
戻る : Previous


Text selection

英文 自動翻訳

If enabled by LV_LABEL_TEXT_SELECTION part of the text can be selected. It's similar to when you use your mouse on a PC to select a text.


The whole mechanism (click and select the text as you drag your finger/mouse) is implemented in Text area and the Label widget only allows manual text selection with lv_label_get_text_selection_start(label, start_char_index) and lv_label_get_text_selection_start(label, end_char_index).

LV_LABEL_TEXT_SELECTIONで有効にすると、テキストの一部を選択することができます。PCでマウスを使ってテキストを選択するのと同じような感じです。


全体の仕組み(指やマウスでドラッグしながらクリックで選択)はテキストエリアに実装されており、ラベルウィジェットでは lv_label_get_text_selection_start(label, start_char_index)lv_label_get_text_selection_start(label, end_char_index) によってのみ手動でテキスト選択が可能です。

戻る : Previous


Very long texts

英文 自動翻訳

LVGL can efficiently handle very long (e.g. > 40k characters) labels by saving some extra data (~12 bytes) to speed up drawing. To enable this feature, set LV_LABEL_LONG_TXT_HINT   1 in lv_conf.h.

LVGLは、非常に長い(例えば、40k文字以上)ラベルを効率的に処理するために、いくつかの余分なデータ(〜12バイト)を保存して描画を高速化します。この機能を有効にするには、lv_conf.hLV_LABEL_LONG_TXT_HINT1 に設定します。
戻る : Previous


Symbols

英文 自動翻訳

The labels can display symbols alongside letters (or on their own). Read the Font section to learn more about the symbols.

ラベルは、文字と一緒に(または単独で)記号を表示することができます。記号の詳細については、フォントのセクションをお読みください。
戻る : Previous


Events

英文 自動翻訳

No special events are sent by the Label.

See the events of the Base object too.

Learn more about Events.

Labelによって送信される特別なイベントはありません。

Baseオブジェクトのイベントも参照してください。

イベントの詳細を確認してください。

戻る : Previous


Keys

英文 自動翻訳

No Keys are processed by the object type.

Learn more about Keys.

オブジェクトタイプによって処理されるキーはありません。

キーの詳細を確認してください。

戻る : Previous


Example

英文 自動翻訳

Line wrap, recoloring and scrolling

LVGL docs example 081.png

Text shadow

LVGL docs example 082.png

Show LTR, RTL and Chinese texts

LVGL docs example 083.png

Draw label with gradient color

LVGL docs example 084.png

戻る : Previous


API

英文 自動翻訳

Typedefs

typedef uint8_t lv_label_long_mode_t

Enums

enum [anonymous]

Long mode behaviors. Used in 'lv_label_ext_t' Values:
enumerator LV_LABEL_LONG_WRAP
Keep the object width, wrap the too long lines and expand the object height
enumerator LV_LABEL_LONG_DOT
Keep the size and write dots at the end if the text is too long
enumerator LV_LABEL_LONG_SCROLL
Keep the size and roll the text back and forth
enumerator LV_LABEL_LONG_SCROLL_CIRCULAR
Keep the size and roll the text circularly
enumerator LV_LABEL_LONG_CLIP
Keep the size and clip the text out of it

Functions

LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM)

LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST)

LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SELECTION_OFF)

lv_obj_t *lv_label_create(lv_obj_t *parent)

Create a label object
Parameters
parent -- pointer to an object, it will be the parent of the new label.
Returns
pointer to the created button

void lv_label_set_text(lv_obj_t *obj, const char *text)

Set a new text for a label. Memory will be allocated to store the text by the label.
Parameters
  • obj -- pointer to a label object
  • text -- '\0' terminated character string. NULL to refresh with the current text.

void lv_label_set_text_fmt (lv_obj_t *obj, const char *fmt,...) LV_FORMAT_ATTRIBUTE(2

void void lv_label_set_text_static (lv_obj_t *obj, const char *text)

Set a static text. It will not be saved by the label so the 'text' variable has to be 'alive' while the label exists.
Parameters
  • obj -- pointer to a label object
  • text -- pointer to a text. NULL to refresh with the current text.

void lv_label_set_long_mode(lv_obj_t *obj, lv_label_long_mode_t long_mode)

Set the behavior of the label with longer text then the object size
Parameters
  • obj -- pointer to a label object
  • long_mode -- the new mode from 'lv_label_long_mode' enum. In LV_LONG_WRAP/DOT/SCROLL/SCROLL_CIRC the size of the label should be set AFTER this function

void lv_label_set_recolor(lv_obj_t *obj, bool en)

void lv_label_set_text_sel_start(lv_obj_t *obj, uint32_t index)

Set where text selection should start
Parameters
  • obj -- pointer to a label object
  • index -- character index from where selection should start. LV_LABEL_TEXT_SELECTION_OFF for no selection

void lv_label_set_text_sel_end(lv_obj_t *obj, uint32_t index)

Set where text selection should end
Parameters
  • obj -- pointer to a label object
  • index -- character index where selection should end. LV_LABEL_TEXT_SELECTION_OFF for no selection

char *lv_label_get_text(const lv_obj_t *obj)

Get the text of a label
Parameters
obj -- pointer to a label object
Returns
the text of the label

lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t *obj)

Get the long mode of a label
Parameters
obj -- pointer to a label object
Returns
the current long mode

bool lv_label_get_recolor(const lv_obj_t *obj)

Get the recoloring attribute
Parameters
obj -- pointer to a label object
Returns
true: recoloring is enabled, false: disable

void lv_label_get_letter_pos(const lv_obj_t *obj, uint32_t char_id, lv_point_t *pos)

Get the relative x and y coordinates of a letter
Parameters
  • obj -- pointer to a label object
  • index -- index of the character [0 ... text length - 1]. Expressed in character index, not byte index (different in UTF-8)
  • pos -- store the result here (E.g. index = 0 gives 0;0 coordinates if the text if aligned to the left)

uint32_t lv_label_get_letter_on(const lv_obj_t *obj, lv_point_t *pos_in)

Get the index of letter on a relative point of a label.
Parameters
  • obj -- pointer to label object
  • pos -- pointer to point with coordinates on a the label
Returns
The index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter if aligned to the left) Expressed in character index and not byte index (different in UTF-8)

bool lv_label_is_char_under_pos(const lv_obj_t *obj, lv_point_t *pos)

Check if a character is drawn under a point.
Parameters
  • obj -- pointer to a label object
  • pos -- Point to check for character under
Returns
whether a character is drawn under the point

uint32_t lv_label_get_text_selection_start(const lv_obj_t *obj)

Get the selection start index.
Parameters
obj -- pointer to a label object.
Returns
selection start index. LV_LABEL_TEXT_SELECTION_OFF if nothing is selected.

uint32_t lv_label_get_text_selection_end(const lv_obj_t *obj)

Get the selection end index.
Parameters
obj -- pointer to a label object.
Returns
selection end index. LV_LABEL_TXT_SEL_OFF if nothing is selected.

void lv_label_ins_text(lv_obj_t *obj, uint32_t pos, const char *txt)

Insert a text to a label. The label text can not be static.
Parameters
  • obj -- pointer to a label object
  • pos -- character index to insert. Expressed in character index and not byte index. 0: before first char. LV_LABEL_POS_LAST: after last char.
  • txt -- pointer to the text to insert

void lv_label_cut_text(lv_obj_t *obj, uint32_t pos, uint32_t cnt)

Delete characters from a label. The label text can not be static.
Parameters
  • obj -- pointer to a label object
  • pos -- character index from where to cut. Expressed in character index and not byte index. 0: start in from of the first character
  • cnt -- number of characters to cut

Variables

const lv_obj_class_t lv_label_class

struct lv_label_t

Public Members
lv_obj_t obj
char *text
char *tmp_ptr
char tmp[LV_LABEL_DOT_NUM + 1]
union lv_label_t::[anonymous] dot
uint32_t dot_end
lv_draw_label_hint_t hint
uint32_t sel_start
uint32_t sel_end
lv_point_t offset
lv_label_long_mode_t long_mode
uint8_t static_txt
uint8_t recolor
uint8_t expand
uint8_t dot_tmp_alloc


Typedef

typedef uint8_t lv_label_long_mode_t

列挙型

列挙型[匿名]

ロングモードの動作。'lv_label_ext_t' 値で使用:
列挙子LV_LABEL_LONG_WRAP
オブジェクトの幅を維持し、長すぎる線を折り返し、オブジェクトの高さを拡大します
列挙子LV_LABEL_LONG_DOT
テキストが長すぎる場合は、サイズを維持し、最後にドットを書き込みます
列挙子LV_LABEL_LONG_SCROLL
サイズを維持し、テキストを前後に回転させます
列挙子LV_LABEL_LONG_SCROLL_CIRCULAR
サイズを維持し、テキストを円形にロールします
列挙子LV_LABEL_LONG_CLIP
サイズを維持し、テキストを切り取ります

機能

LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM)

LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST)

LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SELECTION_OFF)

lv_obj_t * lv_label_create(lv_obj_t * parent)

ラベルオブジェクトを作成する
パラメーター
parent-オブジェクトへのポインタ。新しいラベルの親になります。
戻り値
作成されたボタンへのポインタ

void lv_label_set_text(lv_obj_t * obj、const char * text)

ラベルに新しいテキストを設定します。ラベルごとにテキストを保存するためのメモリが割り当てられます。
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • text-'\0'終了した文字列。現在のテキストで更新するにはNULL。

void lv_label_set_text_fmt(lv_obj_t * obj、const char * fmt、...)LV_FORMAT_ATTRIBUTE(2

void void lv_label_set_text_static(lv_obj_t * obj、const char * text)

静的テキストを設定します。ラベルによって保存されないため、ラベルが存在する間、「text」変数は「alive」である必要があります。
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • text-テキストへのポインタ。現在のテキストで更新するにはNULL。

void lv_label_set_long_mode(lv_obj_t * obj、lv_label_long_mode_t long_mode)

オブジェクトサイズよりも長いテキストでラベルの動作を設定します
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • long_mode-'lv_label_long_mode'列挙型からの新しいモード。LV_LONG_WRAP / DOT / SCROLL / SCROLL_CIRCでは、この関数の後にラベルのサイズを設定する必要があります

void lv_label_set_recolor(lv_obj_t * obj、bool en)

void lv_label_set_text_sel_start(lv_obj_t * obj、uint32_t index)

テキスト選択を開始する場所を設定します
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • index-選択を開始する文字インデックス。LV_LABEL_TEXT_SELECTION_OFF選択なし

void lv_label_set_text_sel_end(lv_obj_t * obj、uint32_t index)

テキスト選択を終了する場所を設定します
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • index-選択を終了する文字インデックス。LV_LABEL_TEXT_SELECTION_OFF選択なし

char * lv_label_get_text(const lv_obj_t * obj)

ラベルのテキストを取得する
パラメーター
obj-ラベルオブジェクトへのポインタ
戻り値
ラベルのテキスト

lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * obj)

ラベルのロングモードを取得する
パラメーター
obj-ラベルオブジェクトへのポインタ
戻り値
現在のロングモード

bool lv_label_get_recolor(const lv_obj_t * obj)

色変更属性を取得します
パラメーター
obj-ラベルオブジェクトへのポインタ
戻り値
true:色の変更が有効、false:無効

void lv_label_get_letter_pos(const lv_obj_t * obj、uint32_t char_id、lv_point_t * pos)

文字の相対的なx座標とy座標を取得します
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • index-文字のインデックス[0...テキストの長さ-1]。バイトインデックスではなく文字インデックスで表されます(UTF-8では異なります)
  • pos-結果をここに保存します(たとえば、テキストが左揃えの場合、インデックス= 0は0;0の座標を示します)

uint32_t lv_label_get_letter_on(const lv_obj_t * obj、lv_point_t * pos_in)

ラベルの相対点にある文字のインデックスを取得します。
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • pos-ラベル上の座標を指すポインタ
戻り値
'pos_p'ポイントの文字のインデックス(たとえば、0; 0は0です。左揃えの場合は文字)バイトインデックスではなく文字インデックスで表されます(UTF-8では異なります)

bool lv_label_is_char_under_pos(const lv_obj_t * obj、lv_point_t * pos)

ポイントの下に文字が描かれているか確認してください。
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • pos-下の文字をチェックするポイント
戻り値
ポイントの下に文字が描かれているかどうか

uint32_t lv_label_get_text_selection_start(const lv_obj_t * obj)

選択開始インデックスを取得します。
パラメーター
obj-ラベルオブジェクトへのポインタ。
戻り値
選択開始インデックス。LV_LABEL_TEXT_SELECTION_OFF何も選択されていない場合。

uint32_t lv_label_get_text_selection_end(const lv_obj_t * obj)

選択終了インデックスを取得します。
パラメーター
obj-ラベルオブジェクトへのポインタ。
戻り値
選択終了インデックス。LV_LABEL_TXT_SEL_OFF何も選択されていない場合。

void lv_label_ins_text(lv_obj_t * obj、uint32_t pos、const char * txt)

ラベルにテキストを挿入します。ラベルテキストを静的にすることはできません。
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • pos--挿入する文字インデックス。バイトインデックスではなく、文字インデックスで表されます。0:最初の文字の前。LV_LABEL_POS_LAST:最後の文字の後。
  • txt-挿入するテキストへのポインタ

void lv_label_cut_text(lv_obj_t * obj、uint32_t pos、uint32_t cnt)

ラベルから文字を削除します。ラベルテキストを静的にすることはできません。
パラメーター
  • obj-ラベルオブジェクトへのポインタ
  • pos--カットする場所からの文字インデックス。バイトインデックスではなく、文字インデックスで表されます。0:最初の文字から開始
  • cnt-カットする文字数

変数

const lv_obj_class_t lv_label_class

struct lv_label_t

パブリックメンバー
lv_obj_t obj
char * text
char * tmp_ptr
char tmp [LV_LABEL_DOT_NUM + 1]
ユニオンlv_label_t::[匿名]ドット
uint32_t dot_end
lv_draw_label_hint_tヒント
uint32_t sel_start
uint32_t sel_end
lv_point_tオフセット
lv_label_long_mode_t long_mode
uint8_t static_txt
uint8_tの色を変更します
uint8_tエキスパンド
uint8_t dot_tmp_alloc



戻る : Previous