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
조각 속성. (None / false 면 Text 의 값을 쓴다)
Segment properties. (None / false uses the Text's value)
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));생성. (아무것도 정하지 않음)
Constructor. (nothing set)
반환ReturnsRichTextAttributes 아무것도 정하지 않은 속성. (default 와 같다)Properties with nothing set. (same as default)
글자 색. (None 이면 Text 의 글자 색)
Text color. (the Text's text color if None)
반환ReturnsOption<Color>
글자 크기. (픽셀, None 이면 Text 의 글자 크기)
Font size. (pixels, the Text's font size if None)
반환ReturnsOption<f64>
폰트 이름. (None 이면 Text 의 폰트 이름)
Font name. (the Text's font name if None)
반환ReturnsOption<String>
외곽선 색. (None 이면 Text 의 외곽선 색)
Outline color. (the Text's outline color if None)
반환ReturnsOption<Color>
외곽선 두께. (픽셀, None 이면 Text 의 외곽선 두께)
Outline thickness. (pixels, the Text's outline thickness if None)
반환ReturnsOption<f64>
굵게. (false 면 Text 의 값을 따른다)
Bold. (false follows the Text's value)
반환Returnsbool
기울임. (false 면 Text 의 값을 따른다)
Italic. (false follows the Text's value)
반환Returnsbool
밑줄. (false 면 Text 의 값을 따른다)
Underline. (false follows the Text's value)
반환Returnsbool
취소선. (false 면 Text 의 값을 따른다)
Strikethrough. (false follows the Text's value)
반환Returnsbool
RichTextSegmentstruct traits Clone, Debug, PartialEq
조각. (글 + 속성)
Segment. (text + 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")));조각 속성. (겹친 태그를 합친 것)
Segment properties. (nested tags combined)
반환ReturnsRichTextAttributes
RichTextRunstruct traits Clone, Debug, PartialEq
배치된 조각 하나. (그릴 자리와 모든 속성을 푼 값)
One laid out segment. (the draw position and all properties resolved)
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);폰트 문자열. (Canvas2D font 꼴)
Font string. (Canvas2D font form)
반환ReturnsString
그릴 왼쪽 x. (content 좌표, 정렬과 문단 방향을 반영한 값)
Left x to draw at. (content coordinates, reflecting alignment and paragraph direction)
반환Returnsf64
외곽선 두께. (0 이면 외곽선을 긋지 않는다)
Outline thickness. (0 draws no outline)
반환Returnsf64
RichTextLayoutstruct traits Clone, Debug, PartialEq
조각 배치 결과.
Segment layout result.
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);배치된 조각 목록. (글이 빈 조각은 빼고 조각 차례)
List of laid out segments. (in segment order, excluding segments with empty text)
반환ReturnsVec<RichTextRun>
가장 큰 글자 크기. (픽셀, 조각이 없으면 0)
Largest font size. (pixels, 0 if there are no segments)
반환Returnsf64
기준선 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
리치텍스트 컴포넌트.
- 원본처럼 조각은 한 줄로 잇는다. 마크업이 없으면 품은 Text 로 그린다.
Rich text component.
- As in the original, segments are joined into one line. Without markup it draws with the contained 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());생성. (기본값은 Text 와 같다)
Constructor. (defaults are the same as Text)
반환ReturnsRichText 빈 글의 리치텍스트 컴포넌트.Rich text component with empty text.
짝Counterpart: vanilla.js RichText.constructor
글과 크기로 생성.
Constructor with text and size.
- text&str
- 처음 글. (마크업을 쓸 수 있다)Initial text. (markup allowed)
- font_sizef64
- 기본 글자 크기. (픽셀)Default font size. (pixels)
반환ReturnsRichText 컴포넌트.Component.
품은 글자 컴포넌트 반환. (전역 속성과 마크업이 없을 때의 그리기)
Returns the contained text component. (global properties and drawing when there is no markup)
반환Returns&Text 품은 Text.The contained Text.
품은 글자 컴포넌트 반환. (변경용)
Returns the contained text component. (mutable)
반환Returns&mut Text 품은 Text.The contained Text.
글 설정. (마크업을 풀어 조각으로 둔다. 알려진 태그가 없으면 조각을 비우고 일반 글로 그린다)
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
글 반환. (마크업이 든 원래 글)
Returns the text. (the original text containing the markup)
반환Returns&str 글.Text.
짝Counterpart: vanilla.js Text.getText
pub fn append_segment(&mut self, text: &str, attributes: RichTextAttributes) -> &mut RichText#조각 하나 더하기. (마크업 없이 코드로 조각을 쌓을 때)
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
조각 모두 지우기.
Removes all segments.
짝Counterpart: vanilla.js RichText.clearSegments
조각 목록.
List of segments.
반환Returns&[RichTextSegment] 조각 목록. (마크업이 없으면 비었다)List of segments. (empty if there is no markup)
짝Counterpart: vanilla.js RichText.getSegments
글이 있는 조각이 하나라도 있는지.
Whether there is at least one segment with text.
반환Returnsbool 글이 있는 조각이 있으면 true.true if there is a segment with text.
짝Counterpart: vanilla.js RichText.hasSegments
글자 크기 설정.
Sets the font size.
- font_sizef64
- 기본 글자 크기. (픽셀, 크기를 정하지 않은 조각이 쓴다)Default font size. (pixels, used by segments that do not set a size)
짝Counterpart: vanilla.js Text.setFontSize
글자 크기 반환.
Returns the font size.
반환Returnsf64 기본 글자 크기. (픽셀)Default font size. (pixels)
짝Counterpart: vanilla.js Text.getFontSize
폰트 이름 설정.
Sets the font name.
- font_family&str
- 기본 폰트 이름.Default font name.
폰트 이름 반환.
Returns the font name.
반환Returns&str 기본 폰트 이름.Default font name.
글자 색 설정.
Sets the text color.
- colorimpl Into<Color>
- 기본 글자 색.Default text color.
짝Counterpart: vanilla.js Text.setTextColor
글자 색 반환.
Returns the text color.
반환ReturnsColor 기본 글자 색.Default text color.
짝Counterpart: vanilla.js Text.getTextColor
외곽선 색 설정.
Sets the outline color.
- colorimpl Into<Color>
- 기본 외곽선 색.Default outline color.
짝Counterpart: vanilla.js Text.setStrokeColor
외곽선 색 반환.
Returns the outline color.
반환ReturnsColor 기본 외곽선 색.Default outline color.
짝Counterpart: vanilla.js Text.getStrokeColor
외곽선 두께 설정.
Sets the outline thickness.
- stroke_widthf64
- 기본 외곽선 두께. (픽셀, 0 이면 없음)Default outline thickness. (pixels, none if 0)
짝Counterpart: vanilla.js Text.setStrokeWidth
외곽선 두께 반환.
Returns the outline thickness.
반환Returnsf64 기본 외곽선 두께. (픽셀)Default outline thickness. (pixels)
짝Counterpart: vanilla.js Text.getStrokeWidth
굵게 설정.
Sets bold.
- is_boldbool
- true 면 모든 조각을 굵게.If true, all segments are bold.
짝Counterpart: vanilla.js Text.setBold
기울임 설정.
Sets italic.
- is_italicbool
- true 면 모든 조각을 기울임.If true, all segments are italic.
짝Counterpart: vanilla.js Text.setItalic
기울임 여부.
Whether italic.
반환Returnsbool 기울임이면 true.true if italic.
짝Counterpart: vanilla.js Text.isItalic
밑줄 설정. (조각에 <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
밑줄 여부.
Whether underlined.
반환Returnsbool 밑줄을 그으면 true.true if an underline is drawn.
짝Counterpart: vanilla.js Text.isUnderline
취소선 설정. (조각에 <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
취소선 여부.
Whether strikethrough.
반환Returnsbool 취소선을 그으면 true.true if a strikethrough is drawn.
짝Counterpart: vanilla.js Text.isStrikethrough
줄바꿈 방식 설정. (마크업이 없을 때만 쓰인다. 조각은 원본처럼 한 줄)
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
줄바꿈 방식 반환.
Returns the wrap mode.
반환ReturnsTextWrapMode 줄바꿈 방식.Wrap mode.
짝Counterpart: vanilla.js Text.getWrapMode
가로 정렬 설정.
Sets the horizontal alignment.
- text_alignTextAlign
- 가로 정렬. (조각은 합친 폭으로 정렬한다)Horizontal alignment. (segments are aligned by their combined width)
짝Counterpart: vanilla.js Text.setTextAlign
가로 정렬 반환.
Returns the horizontal alignment.
반환ReturnsTextAlign 가로 정렬.Horizontal alignment.
짝Counterpart: vanilla.js Text.getTextAlign
세로 기준선 설정.
Sets the vertical baseline.
- text_baselineTextBaseline
- 세로 기준선.Vertical baseline.
짝Counterpart: vanilla.js Text.setTextBaseline
세로 기준선 반환.
Returns the vertical baseline.
반환ReturnsTextBaseline 세로 기준선.Vertical baseline.
짝Counterpart: vanilla.js Text.getTextBaseline
줄바꿈 폭 설정. (마크업이 없을 때만 쓰인다. 조각은 원본처럼 한 줄)
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
줄바꿈 폭 반환.
Returns the wrap width.
반환Returnsf64 줄바꿈 폭. (픽셀)Wrap width. (pixels)
짝Counterpart: vanilla.js Text.getWordWrapWidth
줄 간격 설정.
Sets the line spacing.
- line_spacingf64
- 줄 간격. (글자 크기의 배수, 마크업이 없을 때만 쓰인다)Line spacing. (multiple of the font size, used only without markup)
짝Counterpart: vanilla.js Text.setLineSpacing
줄 간격 반환.
Returns the line spacing.
반환Returnsf64 줄 간격. (글자 크기의 배수)Line spacing. (multiple of the font size)
짝Counterpart: vanilla.js Text.getLineSpacing
글자 간격 설정.
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
글자 간격 반환.
Returns the letter spacing.
반환Returnsf64 글자 간격. (픽셀)Letter spacing. (pixels)
짝Counterpart: vanilla.js Text.getLetterSpacing
pub fn layout_segments(&self, content_size: Vector2, text_direction: TextDirection, measure_width: &mut dyn FnMut(&str, &str) -> f64) -> RichTextLayout#조각 배치. (합친 폭과 가장 큰 글자 크기로 정렬, 기준선은 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.
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);pub fn calculate_intrinsic_content_size(&self, measure_width: &mut dyn FnMut(&str, &str) -> f64) -> Vector2#글의 자연 크기. (조각이 있으면 합친 폭 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).
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));조각을 이은 글의 실제 방향. (품은 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.
글자 방향 설정. (품은 Text 에 넘긴다, 원본 setTextDirection)
Sets the text direction. (forwarded to the contained Text, the original setTextDirection)
- text_directionTextDirection
- 글자 방향.Text direction.
짝Counterpart: vanilla.js Text.setTextDirection
글자 방향 반환.
Returns the text direction.
반환ReturnsTextDirection 글자 방향.Text direction.
짝Counterpart: vanilla.js Text.getTextDirection
보일 글자 수 설정. (품은 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
보일 글자 수 반환.
Returns the visible character count.
반환Returnsi32 보일 글자 묶음 수. (-1 이면 전체)Number of visible character clusters. (-1 for all)
짝Counterpart: vanilla.js Text.getVisibleCharacterCount
조각 그리기. (원본 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
pub fn build_font_string(font_family: &str, font_size: f64, is_bold: bool, is_italic: bool) -> String#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.
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");마크업 → 조각 목록. (알려진 태그가 하나도 없으면 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 <).
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);