vanilladocs
vanillapunch.com
API / core/component/richtext

core/component/richtext

리치텍스트 컴포넌트. (원본 core/component/richtext.js 의 RichText, parse_markup_to_segments)

  • 마크업(Unity TMP 와 같은 꼴)을 풀어 조각(segment)마다 폰트, 크기, 색, 굵게, 기울임, 밑줄, 취소선을 달리해 한 줄로 잇는다. 지원 태그: <b>, <i>, <u>, <s>, <color=#RRGGBB[AA]>, <color=이름>, <size=N>. 모르는 태그는 글 그대로 보인다.
  • 원본은 Text 를 상속한다. 러스트 판은 Text 를 품고(UILabel 이 Text 를 품는 것과 같은 꼴) 세터를 넘긴다. 마크업이 없으면 품은 Text 의 draw 로 그린다. (여러 줄, 줄바꿈 폭 그대로) 조각의 정하지 않은 속성은 Text 의 값을 쓴다.
  • 조각 배치(layout_segments)는 Graphic 없이 재는 함수를 받아 한다. draw 는 글자 텍스처 캐시(textstringtexturecache)의 measure_text 로 잰다.
  • 원본과 다른 것:
  • 조각 속성 fontFace(FontFace / FontAsset) 는 font_family(등록한 폰트 이름) 다.
  • 조각의 밑줄, 취소선, 기울임은 원본처럼 조각 속성이 없으면 Text 의 값(set_underline, set_strikethrough, set_italic)을 쓴다.
  • 잘못된 #색(16진수가 아닌 글자)은 흰색이다. (원본은 NaN 색)
  • getIntrinsicContentSize 는 재는 함수를 받는 calculate_intrinsic_content_size 다.
  • 글자 방향: 조각을 이은 글로 문단 방향을 정하고(품은 Text 의 방향, Inherit 면 Graphic 의 방향), 오른쪽에서 왼쪽이면 조각을 오른쪽부터 놓는다. 조각마다 그 방향으로 모양 짓고, 정렬 Start / End 도 그 방향으로 푼다. (원본도 같다)

Rich text component. (RichText and parse_markup_to_segments in the original core/component/richtext.js)

  • Parses markup (the same form as Unity TMP) and joins segments into one line, each with its own font, size, color, bold, italic, underline and strikethrough. Supported tags: <b>, <i>, <u>, <s>, <color=#RRGGBB[AA]>, <color=name>, <size=N>. Unknown tags show up as plain text.
  • The original inherits Text. The Rust version contains a Text (the same shape as UILabel containing a Text) and forwards the setters. Without markup it draws with the contained Text's draw. (multiple lines and wrap width as is) Properties a segment does not set use the Text's values.
  • Segment layout (layout_segments) takes a measuring function instead of a Graphic. draw measures with measure_text of the text texture cache (textstringtexturecache).
  • Differences from the original:
  • The segment property fontFace (FontFace / FontAsset) is font_family (a registered font name).
  • As in the original, a segment's underline, strikethrough and italic use the Text's values (set_underline, set_strikethrough, set_italic) when the segment property is absent.
  • An invalid #color (non-hexadecimal characters) is white. (the original gives a NaN color)
  • getIntrinsicContentSize is calculate_intrinsic_content_size, which takes a measuring function.
  • Text direction: the paragraph direction is decided from the joined segment text (the contained Text's direction, the Graphic's direction if Inherit), and right to left places segments from the right. Each segment is shaped in that direction, and alignment Start / End is resolved in that direction too. (the original is the same)

RichTextAttributesstruct traits Clone, Debug, Default, PartialEq

소스source

조각 속성. (None / false 면 Text 의 값을 쓴다)

Segment properties. (None / false uses the Text's value)

예제Example코드로 조각 쌓기Build segments in code
use vanilla::{Color, RichText, RichTextAttributes};

let mut warning_attributes = RichTextAttributes::new();
warning_attributes.text_color = Some(Color::create_from_hex("#ff0000"));
warning_attributes.font_size = Some(28.0);
warning_attributes.is_bold = true;
let mut rich_text = RichText::new();
rich_text.append_segment("HP ", RichTextAttributes::new()).append_segment("5", warning_attributes);
assert!(rich_text.has_segments());
assert_eq!(rich_text.get_segments()[0].attributes, RichTextAttributes::new());
assert_eq!(rich_text.get_segments()[1].attributes.font_size, Some(28.0));
생성자constructorpub fn new() -> RichTextAttributes#0.3.2 부터since 0.3.2소스source

생성. (아무것도 정하지 않음)

Constructor. (nothing set)

반환ReturnsRichTextAttributes 아무것도 정하지 않은 속성. (default 와 같다)Properties with nothing set. (same as default)

필드fieldpub text_color: Option<Color>#0.3.2 부터since 0.3.2소스source

글자 색. (None 이면 Text 의 글자 색)

Text color. (the Text's text color if None)

반환ReturnsOption<Color>

필드fieldpub font_size: Option<f64>#0.3.2 부터since 0.3.2소스source

글자 크기. (픽셀, None 이면 Text 의 글자 크기)

Font size. (pixels, the Text's font size if None)

반환ReturnsOption<f64>

필드fieldpub font_family: Option<String>#0.3.2 부터since 0.3.2소스source

폰트 이름. (None 이면 Text 의 폰트 이름)

Font name. (the Text's font name if None)

반환ReturnsOption<String>

필드fieldpub stroke_color: Option<Color>#0.3.2 부터since 0.3.2소스source

외곽선 색. (None 이면 Text 의 외곽선 색)

Outline color. (the Text's outline color if None)

반환ReturnsOption<Color>

필드fieldpub stroke_width: Option<f64>#0.3.2 부터since 0.3.2소스source

외곽선 두께. (픽셀, None 이면 Text 의 외곽선 두께)

Outline thickness. (pixels, the Text's outline thickness if None)

반환ReturnsOption<f64>

필드fieldpub is_bold: bool#0.3.2 부터since 0.3.2소스source

굵게. (false 면 Text 의 값을 따른다)

Bold. (false follows the Text's value)

반환Returnsbool

필드fieldpub is_italic: bool#0.3.2 부터since 0.3.2소스source

기울임. (false 면 Text 의 값을 따른다)

Italic. (false follows the Text's value)

반환Returnsbool

필드fieldpub is_underline: bool#0.3.2 부터since 0.3.2소스source

밑줄. (false 면 Text 의 값을 따른다)

Underline. (false follows the Text's value)

반환Returnsbool

필드fieldpub is_strikethrough: bool#0.3.2 부터since 0.3.2소스source

취소선. (false 면 Text 의 값을 따른다)

Strikethrough. (false follows the Text's value)

반환Returnsbool

RichTextSegmentstruct traits Clone, Debug, PartialEq

소스source

조각. (글 + 속성)

Segment. (text + properties)

예제Example겹친 태그는 속성을 합친다Nested tags combine their properties
use vanilla::core::component::richtext::parse_markup_to_segments;
use vanilla::Color;

let segment_list = parse_markup_to_segments("A<b>B<color=red>C</color></b>").expect("segments");
assert_eq!(segment_list.len(), 3);
assert_eq!(segment_list[0].text, "A");
assert!(!segment_list[0].attributes.is_bold);
assert!(segment_list[2].attributes.is_bold);
assert_eq!(segment_list[2].attributes.text_color, Some(Color::create_from_hex("#ff0000")));
필드fieldpub text: String#0.3.2 부터since 0.3.2소스source

조각 글. (태그를 뺀 글)

Segment text. (text with the tags removed)

반환ReturnsString

필드fieldpub attributes: RichTextAttributes#0.3.2 부터since 0.3.2소스source

조각 속성. (겹친 태그를 합친 것)

Segment properties. (nested tags combined)

반환ReturnsRichTextAttributes

RichTextRunstruct traits Clone, Debug, PartialEq

소스source

배치된 조각 하나. (그릴 자리와 모든 속성을 푼 값)

One laid out segment. (the draw position and all properties resolved)

예제Example조각에 정하지 않은 속성은 Text 의 값으로 푼다Properties a segment does not set resolve to the Text's values
use vanilla::{Color, RichText, TextDirection, Vector2};

let mut measure_width = |_font_string: &str, text: &str| -> f64 {
	text.chars().count() as f64 * 10.0
};
let mut rich_text = RichText::create_with_text("ab<size=40><u>cd</u></size>", 20.0);
rich_text.set_text_color("#00ff00");
let layout = rich_text.layout_segments(Vector2::create(200.0, 60.0), TextDirection::Ltr, &mut measure_width);
let first_run = &layout.run_list[0];
let second_run = &layout.run_list[1];
assert_eq!(first_run.font_string, "20px default");
assert_eq!(first_run.text_color, Color::create_from_hex("#00ff00"));
assert!(!first_run.is_underline);
assert_eq!(second_run.font_size, 40.0);
assert!(second_run.is_underline);
assert_eq!(second_run.x, first_run.x + first_run.width);
필드fieldpub text: String#0.3.2 부터since 0.3.2소스source

조각 글.

Segment text.

반환ReturnsString

필드fieldpub font_string: String#0.3.2 부터since 0.3.2소스source

폰트 문자열. (Canvas2D font 꼴)

Font string. (Canvas2D font form)

반환ReturnsString

필드fieldpub font_size: f64#0.3.2 부터since 0.3.2소스source

글자 크기. (픽셀)

Font size. (pixels)

반환Returnsf64

필드fieldpub x: f64#0.3.2 부터since 0.3.2소스source

그릴 왼쪽 x. (content 좌표, 정렬과 문단 방향을 반영한 값)

Left x to draw at. (content coordinates, reflecting alignment and paragraph direction)

반환Returnsf64

필드fieldpub width: f64#0.3.2 부터since 0.3.2소스source

잰 폭.

Measured width.

반환Returnsf64

필드fieldpub text_color: Color#0.3.2 부터since 0.3.2소스source

글자 색.

Text color.

반환ReturnsColor

필드fieldpub stroke_color: Color#0.3.2 부터since 0.3.2소스source

외곽선 색.

Stroke color.

반환ReturnsColor

필드fieldpub stroke_width: f64#0.3.2 부터since 0.3.2소스source

외곽선 두께. (0 이면 외곽선을 긋지 않는다)

Outline thickness. (0 draws no outline)

반환Returnsf64

필드fieldpub is_underline: bool#0.3.2 부터since 0.3.2소스source

밑줄을 긋는지.

Whether to draw an underline.

반환Returnsbool

필드fieldpub is_strikethrough: bool#0.3.2 부터since 0.3.2소스source

취소선을 긋는지.

Whether to draw a strikethrough.

반환Returnsbool

RichTextLayoutstruct traits Clone, Debug, PartialEq

소스source

조각 배치 결과.

Segment layout result.

예제Example가운데 정렬과 가운데 기준선Center alignment and middle baseline
use vanilla::{RichText, TextAlign, TextBaseline, TextDirection, Vector2};

let mut measure_width = |_font_string: &str, text: &str| -> f64 {
	text.chars().count() as f64 * 10.0
};
let mut rich_text = RichText::create_with_text("ab<size=40>cd</size>", 20.0);
rich_text.set_text_align(TextAlign::Center);
rich_text.set_text_baseline(TextBaseline::Middle);
let layout = rich_text.layout_segments(Vector2::create(200.0, 60.0), TextDirection::Ltr, &mut measure_width);
assert_eq!(layout.total_width, 40.0);
assert_eq!(layout.maximum_font_size, 40.0);
assert_eq!(layout.baseline_y, 30.0);
assert_eq!(layout.run_list[0].x, 80.0);
필드fieldpub run_list: Vec<RichTextRun>#0.3.2 부터since 0.3.2소스source

배치된 조각 목록. (글이 빈 조각은 빼고 조각 차례)

List of laid out segments. (in segment order, excluding segments with empty text)

반환ReturnsVec<RichTextRun>

필드fieldpub total_width: f64#0.3.2 부터since 0.3.2소스source

조각 폭의 합.

Sum of the segment widths.

반환Returnsf64

필드fieldpub maximum_font_size: f64#0.3.2 부터since 0.3.2소스source

가장 큰 글자 크기. (픽셀, 조각이 없으면 0)

Largest font size. (pixels, 0 if there are no segments)

반환Returnsf64

필드fieldpub baseline_y: f64#0.3.2 부터since 0.3.2소스source

기준선 y. (content 좌표, Top 과 Hanging 은 0, Middle 은 높이의 반, 그 밖은 높이)

Baseline y. (content coordinates, 0 for Top and Hanging, half the height for Middle, the height otherwise)

반환Returnsf64

RichTextstruct traits Default, Component

짝Counterpart: vanilla.js RichText소스source

리치텍스트 컴포넌트.

  • 원본처럼 조각은 한 줄로 잇는다. 마크업이 없으면 품은 Text 로 그린다.

Rich text component.

  • As in the original, segments are joined into one line. Without markup it draws with the contained Text.
예제Example마크업 글 넣기Set markup text
use vanilla::RichText;

let mut rich_text = RichText::create_with_text("Get <b>100</b> <color=yellow>gold</color>", 20.0);
assert!(rich_text.has_segments());
assert_eq!(rich_text.get_segments().len(), 4);
assert_eq!(rich_text.get_text(), "Get <b>100</b> <color=yellow>gold</color>");
rich_text.set_text("plain text");
assert!(!rich_text.has_segments());
생성자constructorpub fn new() -> RichText#0.3.2 부터since 0.3.2소스source

생성. (기본값은 Text 와 같다)

Constructor. (defaults are the same as Text)

반환ReturnsRichText 빈 글의 리치텍스트 컴포넌트.Rich text component with empty text.

짝Counterpart: vanilla.js RichText.constructor

정적staticpub fn create_with_text(text: &str, font_size: f64) -> RichText#0.3.2 부터since 0.3.2소스source

글과 크기로 생성.

Constructor with text and size.

text&str
처음 글. (마크업을 쓸 수 있다)Initial text. (markup allowed)
font_sizef64
기본 글자 크기. (픽셀)Default font size. (pixels)

반환ReturnsRichText 컴포넌트.Component.

메서드methodpub fn get_text_component(&self) -> &Text#0.3.2 부터since 0.3.2소스source

품은 글자 컴포넌트 반환. (전역 속성과 마크업이 없을 때의 그리기)

Returns the contained text component. (global properties and drawing when there is no markup)

반환Returns&Text 품은 Text.The contained Text.

메서드methodpub fn get_text_component_mut(&mut self) -> &mut Text#0.3.2 부터since 0.3.2소스source

품은 글자 컴포넌트 반환. (변경용)

Returns the contained text component. (mutable)

반환Returns&mut Text 품은 Text.The contained Text.

메서드methodpub fn set_text(&mut self, text: &str)#0.3.2 부터since 0.3.2소스source

글 설정. (마크업을 풀어 조각으로 둔다. 알려진 태그가 없으면 조각을 비우고 일반 글로 그린다)

Sets the text. (parses the markup into segments. If there are no known tags, clears the segments and draws as plain text)

text&str
글. (마크업을 쓸 수 있다)Text. (markup allowed)

짝Counterpart: vanilla.js RichText.setText

메서드methodpub fn get_text(&self) -> &str#0.3.2 부터since 0.3.2소스source

글 반환. (마크업이 든 원래 글)

Returns the text. (the original text containing the markup)

반환Returns&str 글.Text.

짝Counterpart: vanilla.js Text.getText

메서드methodpub fn append_segment(&mut self, text: &str, attributes: RichTextAttributes) -> &mut RichText#0.3.2 부터since 0.3.2소스source

조각 하나 더하기. (마크업 없이 코드로 조각을 쌓을 때)

Adds one segment. (for building segments in code without markup)

text&str
조각 글. (마크업을 풀지 않고 그대로 둔다)Segment text. (kept as is without parsing markup)
attributesRichTextAttributes
조각 속성.Segment properties.

반환Returns&mut RichText 이 컴포넌트. (이어 부를 수 있다)This component. (calls can be chained)

짝Counterpart: vanilla.js RichText.appendSegment

메서드methodpub fn clear_segments(&mut self)#0.3.2 부터since 0.3.2소스source

조각 모두 지우기.

Removes all segments.

짝Counterpart: vanilla.js RichText.clearSegments

메서드methodpub fn get_segments(&self) -> &[RichTextSegment]#0.3.2 부터since 0.3.2소스source

조각 목록.

List of segments.

반환Returns&[RichTextSegment] 조각 목록. (마크업이 없으면 비었다)List of segments. (empty if there is no markup)

짝Counterpart: vanilla.js RichText.getSegments

메서드methodpub fn has_segments(&self) -> bool#0.3.2 부터since 0.3.2소스source

글이 있는 조각이 하나라도 있는지.

Whether there is at least one segment with text.

반환Returnsbool 글이 있는 조각이 있으면 true.true if there is a segment with text.

짝Counterpart: vanilla.js RichText.hasSegments

메서드methodpub fn set_font_size(&mut self, font_size: f64)#0.3.2 부터since 0.3.2소스source

글자 크기 설정.

Sets the font size.

font_sizef64
기본 글자 크기. (픽셀, 크기를 정하지 않은 조각이 쓴다)Default font size. (pixels, used by segments that do not set a size)

짝Counterpart: vanilla.js Text.setFontSize

메서드methodpub fn get_font_size(&self) -> f64#0.3.2 부터since 0.3.2소스source

글자 크기 반환.

Returns the font size.

반환Returnsf64 기본 글자 크기. (픽셀)Default font size. (pixels)

짝Counterpart: vanilla.js Text.getFontSize

메서드methodpub fn set_font_family(&mut self, font_family: &str)#0.3.2 부터since 0.3.2소스source

폰트 이름 설정.

Sets the font name.

font_family&str
기본 폰트 이름.Default font name.
메서드methodpub fn get_font_family(&self) -> &str#0.3.2 부터since 0.3.2소스source

폰트 이름 반환.

Returns the font name.

반환Returns&str 기본 폰트 이름.Default font name.

메서드methodpub fn set_text_color(&mut self, color: impl Into<Color>)#0.3.2 부터since 0.3.2소스source

글자 색 설정.

Sets the text color.

colorimpl Into<Color>
기본 글자 색.Default text color.

짝Counterpart: vanilla.js Text.setTextColor

메서드methodpub fn get_text_color(&self) -> Color#0.3.2 부터since 0.3.2소스source

글자 색 반환.

Returns the text color.

반환ReturnsColor 기본 글자 색.Default text color.

짝Counterpart: vanilla.js Text.getTextColor

메서드methodpub fn set_stroke_color(&mut self, color: impl Into<Color>)#0.3.2 부터since 0.3.2소스source

외곽선 색 설정.

Sets the outline color.

colorimpl Into<Color>
기본 외곽선 색.Default outline color.

짝Counterpart: vanilla.js Text.setStrokeColor

메서드methodpub fn get_stroke_color(&self) -> Color#0.3.2 부터since 0.3.2소스source

외곽선 색 반환.

Returns the outline color.

반환ReturnsColor 기본 외곽선 색.Default outline color.

짝Counterpart: vanilla.js Text.getStrokeColor

메서드methodpub fn set_stroke_width(&mut self, stroke_width: f64)#0.3.2 부터since 0.3.2소스source

외곽선 두께 설정.

Sets the outline thickness.

stroke_widthf64
기본 외곽선 두께. (픽셀, 0 이면 없음)Default outline thickness. (pixels, none if 0)

짝Counterpart: vanilla.js Text.setStrokeWidth

메서드methodpub fn get_stroke_width(&self) -> f64#0.3.2 부터since 0.3.2소스source

외곽선 두께 반환.

Returns the outline thickness.

반환Returnsf64 기본 외곽선 두께. (픽셀)Default outline thickness. (pixels)

짝Counterpart: vanilla.js Text.getStrokeWidth

메서드methodpub fn set_bold(&mut self, is_bold: bool)#0.3.2 부터since 0.3.2소스source

굵게 설정.

Sets bold.

is_boldbool
true 면 모든 조각을 굵게.If true, all segments are bold.

짝Counterpart: vanilla.js Text.setBold

메서드methodpub fn is_bold(&self) -> bool#0.3.2 부터since 0.3.2소스source

굵게 여부.

Whether bold.

반환Returnsbool 굵게면 true.true if bold.

짝Counterpart: vanilla.js Text.isBold

메서드methodpub fn set_italic(&mut self, is_italic: bool)#0.3.2 부터since 0.3.2소스source

기울임 설정.

Sets italic.

is_italicbool
true 면 모든 조각을 기울임.If true, all segments are italic.

짝Counterpart: vanilla.js Text.setItalic

메서드methodpub fn is_italic(&self) -> bool#0.3.2 부터since 0.3.2소스source

기울임 여부.

Whether italic.

반환Returnsbool 기울임이면 true.true if italic.

짝Counterpart: vanilla.js Text.isItalic

메서드methodpub fn set_underline(&mut self, is_underline: bool)#0.4.0 부터since 0.4.0소스source

밑줄 설정. (조각에 <u> 가 없어도 모든 조각에 긋는다)

Sets the underline. (drawn on all segments even if a segment has no <u>)

is_underlinebool
true 면 밑줄을 긋는다.If true, draws an underline.

짝Counterpart: vanilla.js Text.setUnderline

메서드methodpub fn is_underline(&self) -> bool#0.4.0 부터since 0.4.0소스source

밑줄 여부.

Whether underlined.

반환Returnsbool 밑줄을 그으면 true.true if an underline is drawn.

짝Counterpart: vanilla.js Text.isUnderline

메서드methodpub fn set_strikethrough(&mut self, is_strikethrough: bool)#0.4.0 부터since 0.4.0소스source

취소선 설정. (조각에 <s> 가 없어도 모든 조각에 긋는다)

Sets the strikethrough. (drawn on all segments even if a segment has no <s>)

is_strikethroughbool
true 면 취소선을 긋는다.If true, draws a strikethrough.

짝Counterpart: vanilla.js Text.setStrikethrough

메서드methodpub fn is_strikethrough(&self) -> bool#0.4.0 부터since 0.4.0소스source

취소선 여부.

Whether strikethrough.

반환Returnsbool 취소선을 그으면 true.true if a strikethrough is drawn.

짝Counterpart: vanilla.js Text.isStrikethrough

메서드methodpub fn set_wrap_mode(&mut self, wrap_mode: TextWrapMode)#0.4.0 부터since 0.4.0소스source

줄바꿈 방식 설정. (마크업이 없을 때만 쓰인다. 조각은 원본처럼 한 줄)

Sets the wrap mode. (used only without markup. Segments are one line as in the original)

wrap_modeTextWrapMode
줄바꿈 방식.Wrap mode.

짝Counterpart: vanilla.js Text.setWrapMode

메서드methodpub fn get_wrap_mode(&self) -> TextWrapMode#0.4.0 부터since 0.4.0소스source

줄바꿈 방식 반환.

Returns the wrap mode.

반환ReturnsTextWrapMode 줄바꿈 방식.Wrap mode.

짝Counterpart: vanilla.js Text.getWrapMode

메서드methodpub fn set_text_align(&mut self, text_align: TextAlign)#0.3.2 부터since 0.3.2소스source

가로 정렬 설정.

Sets the horizontal alignment.

text_alignTextAlign
가로 정렬. (조각은 합친 폭으로 정렬한다)Horizontal alignment. (segments are aligned by their combined width)

짝Counterpart: vanilla.js Text.setTextAlign

메서드methodpub fn get_text_align(&self) -> TextAlign#0.3.2 부터since 0.3.2소스source

가로 정렬 반환.

Returns the horizontal alignment.

반환ReturnsTextAlign 가로 정렬.Horizontal alignment.

짝Counterpart: vanilla.js Text.getTextAlign

메서드methodpub fn set_text_baseline(&mut self, text_baseline: TextBaseline)#0.3.2 부터since 0.3.2소스source

세로 기준선 설정.

Sets the vertical baseline.

text_baselineTextBaseline
세로 기준선.Vertical baseline.

짝Counterpart: vanilla.js Text.setTextBaseline

메서드methodpub fn get_text_baseline(&self) -> TextBaseline#0.3.2 부터since 0.3.2소스source

세로 기준선 반환.

Returns the vertical baseline.

반환ReturnsTextBaseline 세로 기준선.Vertical baseline.

짝Counterpart: vanilla.js Text.getTextBaseline

메서드methodpub fn set_word_wrap_width(&mut self, word_wrap_width: f64)#0.3.2 부터since 0.3.2소스source

줄바꿈 폭 설정. (마크업이 없을 때만 쓰인다. 조각은 원본처럼 한 줄)

Sets the wrap width. (used only without markup. Segments are one line as in the original)

word_wrap_widthf64
줄바꿈 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)Wrap width. (pixels, if 0 or less, splits only at newline characters)

짝Counterpart: vanilla.js Text.setWordWrapWidth

메서드methodpub fn get_word_wrap_width(&self) -> f64#0.3.2 부터since 0.3.2소스source

줄바꿈 폭 반환.

Returns the wrap width.

반환Returnsf64 줄바꿈 폭. (픽셀)Wrap width. (pixels)

짝Counterpart: vanilla.js Text.getWordWrapWidth

메서드methodpub fn set_line_spacing(&mut self, line_spacing: f64)#0.3.2 부터since 0.3.2소스source

줄 간격 설정.

Sets the line spacing.

line_spacingf64
줄 간격. (글자 크기의 배수, 마크업이 없을 때만 쓰인다)Line spacing. (multiple of the font size, used only without markup)

짝Counterpart: vanilla.js Text.setLineSpacing

메서드methodpub fn get_line_spacing(&self) -> f64#0.3.2 부터since 0.3.2소스source

줄 간격 반환.

Returns the line spacing.

반환Returnsf64 줄 간격. (글자 크기의 배수)Line spacing. (multiple of the font size)

짝Counterpart: vanilla.js Text.getLineSpacing

메서드methodpub fn set_letter_spacing(&mut self, letter_spacing: f64)#0.4.0 부터since 0.4.0소스source

글자 간격 설정.

Sets the letter spacing.

letter_spacingf64
글자 묶음마다 뒤에 더하는 간격. (픽셀, 마크업이 없을 때만 쓰인다)Spacing added after each grapheme cluster. (pixels, used only when there is no markup)

짝Counterpart: vanilla.js Text.setLetterSpacing

메서드methodpub fn get_letter_spacing(&self) -> f64#0.4.0 부터since 0.4.0소스source

글자 간격 반환.

Returns the letter spacing.

반환Returnsf64 글자 간격. (픽셀)Letter spacing. (pixels)

짝Counterpart: vanilla.js Text.getLetterSpacing

메서드methodpub fn layout_segments(&self, content_size: Vector2, text_direction: TextDirection, measure_width: &mut dyn FnMut(&str, &str) -> f64) -> RichTextLayout#0.3.2 부터since 0.3.2소스source

조각 배치. (합친 폭과 가장 큰 글자 크기로 정렬, 기준선은 Text 와 같은 규칙. 원본 drawSegments 의 자리 계산)

  • measure_width(폰트 문자열, 글) 은 글 폭을 돌려준다.
  • text_direction 은 실제 문단 방향이다. (Ltr 또는 Rtl, Rtl 이면 조각을 오른쪽부터 놓고 Start 는 오른쪽 정렬)

Segment layout. (aligned using the combined width and the largest font size, baseline by the same rule as Text. The position calculation of the original drawSegments)

  • measure_width(font string, text) returns the text width.
  • text_direction is the actual paragraph direction. (Ltr or Rtl, Rtl places segments from the right and Start aligns right)
content_sizeVector2
노드 content 크기. (정렬과 기준선에 쓴다)Node content size. (used for alignment and baseline)
text_directionTextDirection
실제 문단 방향. (Rtl 밖은 모두 왼쪽에서 오른쪽으로 놓는다)Actual paragraph direction. (anything other than Rtl is placed left to right)
measure_width&mut dyn FnMut(&str, &str) -> f64
(폰트 문자열, 글) 을 받아 폭을 돌려주는 함수.Function that takes (font string, text) and returns the width.

반환ReturnsRichTextLayout 배치 결과.Layout result.

예제Example오른쪽에서 왼쪽 문단은 앞 조각이 오른쪽에 온다In a right to left paragraph the earlier segment comes on the right
use vanilla::{RichText, TextAlign, TextDirection, Vector2};

let mut measure_width = |_font_string: &str, text: &str| -> f64 {
	text.chars().count() as f64 * 10.0
};
let mut rich_text = RichText::create_with_text("ab<b>cd</b>", 20.0);
rich_text.set_text_align(TextAlign::Start);
let left_to_right_layout = rich_text.layout_segments(Vector2::create(200.0, 40.0), TextDirection::Ltr, &mut measure_width);
assert_eq!(left_to_right_layout.run_list[0].x, 0.0);
assert_eq!(left_to_right_layout.run_list[1].x, 20.0);
assert_eq!(left_to_right_layout.run_list[1].font_string, "bold 20px default");
let right_to_left_layout = rich_text.layout_segments(Vector2::create(200.0, 40.0), TextDirection::Rtl, &mut measure_width);
assert_eq!(right_to_left_layout.run_list[0].x, 180.0);
assert_eq!(right_to_left_layout.run_list[1].x, 160.0);
메서드methodpub fn calculate_intrinsic_content_size(&self, measure_width: &mut dyn FnMut(&str, &str) -> f64) -> Vector2#0.3.2 부터since 0.3.2소스source

글의 자연 크기. (조각이 있으면 합친 폭 x 가장 큰 글자 크기, 없으면 일반 글 폭 x 글자 크기. 원본 getIntrinsicContentSize)

Intrinsic size of the text. (with segments, combined width x largest font size, otherwise plain text width x font size. The original getIntrinsicContentSize)

measure_width&mut dyn FnMut(&str, &str) -> f64
(폰트 문자열, 글) 을 받아 폭을 돌려주는 함수.Function that takes (font string, text) and returns the width.

반환ReturnsVector2 (너비, 높이).(width, height).

예제Example조각이 있으면 합친 폭과 가장 큰 글자 크기With segments, the combined width and the largest font size
use vanilla::{RichText, Vector2};

let mut measure_width = |_font_string: &str, text: &str| -> f64 {
	text.chars().count() as f64 * 10.0
};
let mut rich_text = RichText::create_with_text("ab<size=40>cd</size>", 20.0);
assert_eq!(rich_text.calculate_intrinsic_content_size(&mut measure_width), Vector2::create(40.0, 40.0));
rich_text.set_text("plain");
assert_eq!(rich_text.calculate_intrinsic_content_size(&mut measure_width), Vector2::create(50.0, 20.0));
메서드methodpub fn resolve_segment_text_direction(&self, graphic: &Graphic) -> TextDirection#0.4.0 부터since 0.4.0소스source

조각을 이은 글의 실제 방향. (품은 Text 의 방향, Inherit 면 Graphic 의 방향. Auto 는 이은 글의 첫 강한 글자로)

Actual direction of the joined segment text. (the contained Text's direction, the Graphic's direction if Inherit. Auto uses the first strong character of the joined text)

graphic&Graphic
방향이 Inherit 일 때 볼 Graphic.Graphic to look at when the direction is Inherit.

반환ReturnsTextDirection Ltr 또는 Rtl.Ltr or Rtl.

메서드methodpub fn set_text_direction(&mut self, text_direction: TextDirection)#0.4.0 부터since 0.4.0소스source

글자 방향 설정. (품은 Text 에 넘긴다, 원본 setTextDirection)

Sets the text direction. (forwarded to the contained Text, the original setTextDirection)

text_directionTextDirection
글자 방향.Text direction.

짝Counterpart: vanilla.js Text.setTextDirection

메서드methodpub fn get_text_direction(&self) -> TextDirection#0.4.0 부터since 0.4.0소스source

글자 방향 반환.

Returns the text direction.

반환ReturnsTextDirection 글자 방향.Text direction.

짝Counterpart: vanilla.js Text.getTextDirection

메서드methodpub fn set_visible_character_count(&mut self, visible_character_count: i32)#0.4.0 부터since 0.4.0소스source

보일 글자 수 설정. (품은 Text 에 넘긴다, -1 이면 전체. 마크업이 있는 글은 원본처럼 자르지 않는다)

Sets the visible character count. (forwarded to the contained Text, -1 for all. Text with markup is not cut, as in the original)

visible_character_counti32
보일 글자 묶음 수. (-1 이면 전체)Number of visible character clusters. (-1 for all)

짝Counterpart: vanilla.js Text.setVisibleCharacterCount

메서드methodpub fn get_visible_character_count(&self) -> i32#0.4.0 부터since 0.4.0소스source

보일 글자 수 반환.

Returns the visible character count.

반환Returnsi32 보일 글자 묶음 수. (-1 이면 전체)Number of visible character clusters. (-1 for all)

짝Counterpart: vanilla.js Text.getVisibleCharacterCount

메서드methodpub fn draw_segments(&self, graphic: &mut Graphic, content_size: Vector2)#0.3.2 부터since 0.3.2소스source

조각 그리기. (원본 drawSegments)

Draws segments. (the original drawSegments)

graphic&mut Graphic
그릴 Graphic. (문단 방향, 정렬, 기준선, 폰트 문자열, 색을 바꿔 가며 그린다)Graphic to draw to. (draws while changing paragraph direction, alignment, baseline, font string and color)
content_sizeVector2
노드 content 크기.Node content size.

짝Counterpart: vanilla.js RichText.drawSegments

함수Functions

함수functionpub fn build_font_string(font_family: &str, font_size: f64, is_bold: bool, is_italic: bool) -> String#0.3.2 부터since 0.3.2소스source

Canvas2D font 꼴 문자열. (원본 text.js 의 build_font_string)

String in Canvas2D font form. (build_font_string in the original text.js)

font_family&str
폰트 이름.Font name.
font_sizef64
글자 크기. (픽셀)Font size. (pixels)
is_boldbool
true 면 bold 를 넣는다.If true, includes bold.
is_italicbool
true 면 italic 을 넣는다.If true, includes italic.

반환ReturnsString 폰트 문자열.Font string.

예제Example기울임, 굵게, 크기, 이름 차례In the order italic, bold, size, name
use vanilla::core::component::richtext::build_font_string;

assert_eq!(build_font_string("default", 20.0, false, false), "20px default");
assert_eq!(build_font_string("GameFont", 16.5, true, true), "italic bold 16.5px GameFont");
함수functionpub fn parse_markup_to_segments(input: &str) -> Option<Vec<RichTextSegment>>#0.3.2 부터since 0.3.2소스source

마크업 → 조각 목록. (알려진 태그가 하나도 없으면 None. 원본 parseMarkupToSegments)

  • 모르는 여는 태그는 글로 남긴다. 닫는 태그는 짝이 없어도 글에서 빠진다. (원본과 같음)

Markup → segment list. (None if there are no known tags at all. The original parseMarkupToSegments)

  • Unknown opening tags remain as text. Closing tags are removed from the text even without a match. (same as the original)
input&str
마크업 글.Markup text.

반환ReturnsOption<Vec<RichTextSegment>> 조각 목록. 알려진 태그가 하나도 없으면(빈 글, < 가 없는 글도) None.List of segments. None if there are no known tags at all (also for empty text and text without <).

예제Example모르는 태그는 글로 남는다Unknown tags remain as text
use vanilla::core::component::richtext::parse_markup_to_segments;

assert!(parse_markup_to_segments("plain text").is_none());
assert!(parse_markup_to_segments("a < b and <unknown>tag</unknown>").is_none());
let segment_list = parse_markup_to_segments("<u>x</u><foo>y").expect("segments");
let text_list: Vec<&str> = segment_list.iter().map(|segment| segment.text.as_str()).collect();
assert_eq!(text_list, vec!["x", "<foo>", "y"]);
assert!(segment_list[0].attributes.is_underline);