core/component/text
텍스트 컴포넌트. (노드 content_size 영역 안에 정렬해 글자를 그린다)
- 한 줄, 그리고 줄바꿈 문자나 word_wrap_width 가 있으면 여러 줄로 그린다.
- 나눈 줄과 줄 폭은 글, 폰트 문자열, 줄바꿈 폭, 등록된 글꼴이 바뀔 때만 다시 센다.
- 화면 밖 거르기는 정렬, 넘침, 줄바꿈 결과로 셈한 글 사각형으로 판정한다. (원본도 Text.calculateDrawnRect 로 거른다)
- 밑줄 / 취소선은 원본처럼 글자 색 선을 긋는다. (두께 max(1, 글자 크기 / 16), 자리는 원본 computeUnderlineOffsetY / computeStrikethroughOffsetY)
- 줄바꿈 방식(set_wrap_mode): Word 는 공백 단위로 채우고, 넘치는 조각에 낱말이 여럿이면(공백 없이 쓰는 한중일, 태국어 등) 낱말 사이에서, 그래도 넘치는 낱말은 글자 묶음 단위로 나눈다. Character 는 처음부터 글자 묶음 단위. (원본 "word" / "char", 셈의 차례가 원본과 같다) 글자 묶음은 UAX #29(unicode-segmentation), 낱말은 ICU 사전(icu_segmenter)으로 찾는다. 원본 Intl.Segmenter 도 ICU(ICU4C)의 같은 규칙과 사전이다. 한중일은 ICU4X 가 가장 긴 낱말부터 고르고 ICU4C 는 낱말 값의 합이 가장 작은 나누기를 골라 달라서, 데스크탑은 ICU4C 의 셈을 옮겨 같은 사전(cjdict)으로 나눈다.
- 기울임은 폰트 문자열에 italic 을 넣는다. 기울인 얼굴이 없으면 글자 캐시가 브라우저와 같은 가짜 기울임(기울기 1/4)으로 굽는다.
- 글자 방향(set_text_direction, 원본 setTextDirection): Inherit 면 그리는 때의 Graphic 방향을 따른다. 정렬 Start / End 가 그 방향으로 풀리고, 글자 캐시가 그 문단 방향으로 양방향 정렬과 모양 짓기(아랍어 글자 잇기)를 한다.
- 글자 수만큼 보이기(set_visible_character_count, 타자기 연출)는 앞에서부터 글자 묶음 단위로 자른다. (받침, 결합 부호, 이모지 묶음이 쪼개지지 않는다) 여러 줄이면 줄마다 남은 수만큼 그리고, 남은 수가 0 이 되면 다음 줄부터 그리지 않는다.
- 한 줄 글을 너비에 맞추기(set_fit_width): 원본처럼 넘치면 처음 크기에서 최소 비율까지 0.1 단위로 줄여 그린다. 줄인 크기는 줄을 나눌 때(update_layout) 재므로 Graphic 이 있어야 안다. (get_fitted_font_size 는 마지막으로 잰 값, calculate_fitted_font_size 는 그 자리에서 잰다) 그리는 사각형은 줄인 글의 너비를 따른다.
Text component. (draws text aligned within the node's content_size area)
- Draws a single line, or multiple lines if there are newline characters or a word_wrap_width.
- The split lines and line widths are recomputed only when the text, font string, wrap width or registered fonts change.
- Off-screen culling is judged by the text rectangle computed from alignment, overflow and wrapping results. (the original also culls with Text.calculateDrawnRect)
- Underline / strikethrough draw lines in the text color, as in the original. (thickness max(1, font size / 16), position from the original computeUnderlineOffsetY / computeStrikethroughOffsetY)
- Wrap mode (set_wrap_mode): Word fills by whitespace units, and if an overflowing piece holds several words (CJK, Thai and other scripts written without spaces) it breaks between words, and words that still overflow are split by grapheme clusters. Character uses grapheme clusters from the start. (the original "word" / "char", the calculation order matches the original) Grapheme clusters are found with UAX #29 (unicode-segmentation), words with the ICU dictionary (icu_segmenter). The original's Intl.Segmenter also uses the same ICU (ICU4C) rules and dictionary. For CJK, ICU4X picks the longest word first while ICU4C picks the split with the smallest sum of word costs, so they differ, and desktop ports ICU4C's calculation and splits with the same dictionary (cjdict).
- Italic adds italic to the font string. If there is no italic face, the text cache bakes it with a synthetic slant like the browser's (slope 1/4).
- Text direction (set_text_direction, the original setTextDirection): Inherit follows the Graphic's direction at draw time. Alignment Start / End resolves in that direction, and the text cache does bidirectional ordering and shaping (Arabic letter joining) in that paragraph direction.
- Showing a number of characters (set_visible_character_count, typewriter effect) cuts by grapheme clusters from the front. (Hangul syllables, combining marks and emoji sequences are not split) With multiple lines, each line draws as many as remain, and once the remaining count reaches 0 the following lines are not drawn.
- Fitting single-line text to a width (set_fit_width): as in the original, if it overflows it shrinks from the initial size down to the minimum ratio in steps of 0.1. The shrunk size is measured when splitting lines (update_layout), so a Graphic is needed to know it. (get_fitted_font_size is the last measured value, calculate_fitted_font_size measures on the spot) The drawn rectangle follows the width of the shrunk text.
use vanilla::{count_graphemes, slice_graphemes, split_graphemes};
let text = "e\u{301}xy";
assert_eq!(text.chars().count(), 4);
assert_eq!(count_graphemes(text), 3);
assert_eq!(split_graphemes(text), vec!["e\u{301}", "x", "y"]);
assert_eq!(slice_graphemes(text, 2), "e\u{301}x");
assert_eq!(slice_graphemes(text, 9), text);TextWrappedSizestruct traits Clone, Copy, Debug, Default, PartialEq
줄바꿈 반영 크기. (원본 measureWrappedSize 의 { width, height, lineCount })
Size with wrapping applied. ({ width, height, lineCount } of the original measureWrappedSize)
use vanilla::{Graphic, Text, TextWrappedSize};
fn measure_description(graphic: &mut Graphic) -> TextWrappedSize {
let mut text = Text::create_with_text("A long description that wraps", 20.0);
text.set_word_wrap_width(240.0);
let wrapped_size = text.measure_wrapped_size(graphic);
assert_eq!(wrapped_size.height, wrapped_size.line_count as f64 * 20.0 * text.get_line_spacing());
wrapped_size
}높이. (줄 수 * 글자 크기 * 줄 간격)
Height. (line count * font size * line spacing)
반환Returnsf64
Textstruct traits Default, Component, TypewriterTarget
텍스트 컴포넌트. (원본 Text, 노드 content_size 영역 안에 정렬해 글자를 그린다)
Text component. (the original Text, draws text aligned within the node's content_size area)
use vanilla::{Colors, NodeTree, Text, TextAlign, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let label_id = node_tree.create_child(root_id, "label");
node_tree[label_id].set_content_size(Vector2::create(300.0, 60.0));
let text = node_tree.add_component(label_id, Text::create_with_text("Hello", 24.0)).expect("text");
text.set_text_color(Colors::VANILLA);
text.set_text_align(TextAlign::Left);
text.set_stroke_width(2.0);
assert_eq!(text.get_text(), "Hello");
assert_eq!(text.build_font_string(), "24px default");생성. (기본값은 원본과 같다: 32px, 흰색, 가운데 정렬, 가운데 기준선, 줄 간격 1.25)
Constructor. (defaults are the same as the original: 32px, white, center alignment, middle baseline, line spacing 1.25)
반환ReturnsText 빈 글의 텍스트 컴포넌트. (폰트 이름 default, Word 줄바꿈, 외곽선 없음)Text component with empty text. (font name default, Word wrapping, no outline)
짝Counterpart: vanilla.js Text.constructor
글과 크기로 생성.
Constructor with text and size.
- text&str
- 처음 글.Initial text.
- font_sizef64
- 글자 크기. (픽셀)Font size. (pixels)
반환ReturnsText 컴포넌트. (그 밖은 new 와 같다)Component. (otherwise the same as new)
글이 차지하는 영역. (원본 Text.calculateTextBounds: 굵게, 기울임 없이 잰 너비와 실제 글리프의 위아래 높이)
Area occupied by the text. (the original Text.calculateTextBounds: the width measured without bold or italic, and the actual glyph height from top to bottom)
- graphic&Graphic
- 잴 Graphic.Graphic to measure with.
- text_component&Text
- 잴 컴포넌트. (폰트 이름, 글자 크기, 글을 쓴다)Component to measure. (uses the font name, font size and text)
반환ReturnsRect (0, 0, 너비, 위아래 높이) 사각형. (픽셀)The (0, 0, width, top to bottom height) rectangle. (pixels)
짝Counterpart: vanilla.js Text.calculateTextBounds
Canvas2D font 꼴 문자열 만들기.
Builds a string in Canvas2D font form.
반환ReturnsString 폰트 문자열. (예: italic bold 32px default, 기울임과 굵게는 켰을 때만 든다)Font string. (e.g. italic bold 32px default, italic and bold are included only when on)
크기를 주어 Canvas2D font 꼴 문자열 만들기. (이 글자의 폰트 이름, 굵게, 기울임으로)
Builds a string in Canvas2D font form with the given size. (with this text's font name, bold and italic)
- font_sizef64
- 글자 크기. (픽셀)Font size. (pixels)
반환ReturnsString 폰트 문자열.Font string.
use vanilla::Text;
let mut text = Text::new();
text.set_bold(true);
text.set_italic(true);
text.set_font_family("GameFont");
assert_eq!(text.build_font_string(), "italic bold 32px GameFont");
assert_eq!(text.build_font_string_with_size(12.5), "italic bold 12.5px GameFont");pub fn wrap_text_to_lines(&self, graphic: &Graphic, text: &str, maximum_width: f64) -> Vec<String>#폭에 맞춰 줄 나누기. (원본 wrapTextToLines, 줄바꿈 문자는 늘 지킨다, 재는 폰트는 Graphic 의 현재 폰트 문자열)
- Word: 공백 단위로 채운다. 넘치는 조각에 낱말이 여럿이면(공백 없이 쓰는 글) 낱말 사이에서 나눠 지금 줄의 남은 자리부터 채우고, 한 낱말이 폭을 넘으면 글자 묶음 단위로 나눈다. (공백 없는 한중일 문장도 낱말 사이에서 나뉜다)
- Character: 처음부터 글자 묶음 단위로 나눈다.
Splits lines to fit a width. (the original wrapTextToLines, newline characters are always kept, measured with the Graphic's current font string)
- Word: fills by whitespace units. If an overflowing piece holds several words (text written without spaces), it splits between words and fills from the space left on the current line, and if a single word exceeds the width, it splits by grapheme clusters. (CJK sentences without spaces are also split between words)
- Character: splits by grapheme clusters from the start.
- graphic&Graphic
- 잴 Graphic. (지금 폰트 문자열로 잰다)Graphic to measure with. (measures with the current font string)
- text&str
- 나눌 글.Text to split.
- maximum_widthf64
- 줄 최대 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)Maximum line width. (pixels, if 0 or less, splits only at newline characters)
반환ReturnsVec<String> 줄 목록. (빈 문단은 빈 줄)List of lines. (an empty paragraph is an empty line)
짝Counterpart: vanilla.js Text.wrapTextToLines
use vanilla::{Graphic, Text};
fn wrap_description(graphic: &mut Graphic, text: &Text) -> Vec<String> {
graphic.set_font_string(&text.build_font_string());
text.wrap_text_to_lines(graphic, text.get_text(), 200.0)
}pub fn wrap_text_to_lines_with(&self, text: &str, maximum_width: f64, measure_width: &dyn Fn(&str) -> f64) -> Vec<String>#폭에 맞춰 줄 나누기. (재는 함수를 받는다. wrap_text_to_lines 의 셈, Graphic 없이 시험하거나 다른 글꼴로 잴 때)
Splits lines to fit a width. (takes a measuring function. The calculation of wrap_text_to_lines, for testing without a Graphic or measuring with another font)
- text&str
- 나눌 글.Text to split.
- maximum_widthf64
- 줄 최대 폭. (measure_width 와 같은 단위, 0 이하면 줄바꿈 문자로만 나눈다)Maximum line width. (same unit as measure_width, if 0 or less, splits only at newline characters)
- measure_width&dyn Fn(&str) -> f64
- 글을 받아 너비를 돌려주는 함수.Function that takes text and returns its width.
반환ReturnsVec<String> 줄 목록. (빈 문단은 빈 줄)List of lines. (an empty paragraph is an empty line)
use vanilla::{Text, TextWrapMode};
let measure_width = |line_text: &str| -> f64 {
line_text.chars().count() as f64 * 10.0
};
let mut text = Text::new();
assert_eq!(text.wrap_text_to_lines_with("aaa bbb ccc", 75.0, &measure_width), vec!["aaa bbb", "ccc"]);
assert_eq!(text.wrap_text_to_lines_with("a\n\nb", 0.0, &measure_width), vec!["a", "", "b"]);
text.set_wrap_mode(TextWrapMode::Character);
assert_eq!(text.wrap_text_to_lines_with("abcdef", 25.0, &measure_width), vec!["ab", "cd", "ef"]);Graphic 없이 나눈 줄 목록. (지금 글과 폰트 문자열, 폭으로 나눈다, 글꼴이 없어 잴 수 없으면 None)
- 그리기 전에 줄 수가 필요한 레이아웃(창의 내용 놓기 같은)이 쓴다. (textstringtexturecache::measure_text_without_graphic)
List of lines split without a Graphic. (split by the current text, font string and width, None if it cannot measure because there is no font)
- Used by layouts that need the line count before drawing (such as placing window contents). (textstringtexturecache::measure_text_without_graphic)
- maximum_widthf64
- 줄 최대 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)Maximum line width. (pixels, if 0 or less, splits only at newline characters)
반환ReturnsOption<Vec<String>> 줄 목록. 데스크탑에서 이 스레드에 글꼴을 등록한 글자 캐시가 없거나 고를 얼굴이 없으면 None.List of lines. None on desktop if there is no text cache with fonts registered on this thread or no face to choose.
짝Counterpart: vanilla.js Text.wrapLinesWithoutGraphic
use vanilla::core::textstringtexturecache::TextStringTextureCache;
use vanilla::platform::find_fallback_font_file;
use vanilla::Text;
let text = Text::create_with_text("one two three four five", 20.0);
assert!(text.wrap_lines_without_graphic(100.0).is_none());
if let Some(source) = find_fallback_font_file("A", 400, false, false) {
let mut text_string_texture_cache = TextStringTextureCache::new();
text_string_texture_cache.set_default_font(false, std::fs::read(&source.path).expect("font file")).expect("font");
let line_list = text.wrap_lines_without_graphic(100.0).expect("lines");
assert!(line_list.len() > 1);
}줄바꿈 반영 크기 재기. (원본 measureWrappedSize, 레이아웃 용. 줄바꿈 폭이 없으면 줄바꿈 문자로만 나눈다)
Measures the size with wrapping applied. (the original measureWrappedSize, for layout. Without a wrap width it splits only at newline characters)
- graphic&mut Graphic
- 잴 Graphic. (상태는 되돌려 둔다)Graphic to measure with. (its state is restored)
반환ReturnsTextWrappedSize 크기. (글이 비었으면 모두 0)Size. (all 0 if the text is empty)
짝Counterpart: vanilla.js Text.measureWrappedSize
글의 자연 크기. (원본 getIntrinsicContentSize: 한 줄 너비와 글자 크기, 글이 없으면 (0, 글자 크기), 꺼져 있으면 (-1, -1))
Intrinsic size of the text. (the original getIntrinsicContentSize: single-line width and font size, (0, font size) if there is no text, (-1, -1) if disabled)
- graphic&Graphic
- 잴 Graphic.Graphic to measure with.
반환ReturnsVector2 (너비, 글자 크기). (픽셀)(width, font size). (pixels)
한 줄 글을 너비에 맞추기 설정. (넘치면 처음 크기에서 최소 비율까지 줄여 그린다, 원본 setFitWidth)
- 칸을 넓힐 수 없는 곳(단추, 줄 이름, 제목)에서 언어마다 길이가 다른 글이 넘칠 때 쓴다.
- 정한 크기(get_font_size)는 그대로 두고 그릴 때의 크기만 줄인다. 최소 비율로도 넘치면 넘친 채로 그리고, 화면 밖 거르기도 넘친 너비까지 본다.
- 줄을 바꾸는 글은 맞추지 않는다. width 가 0 이하면 맞추지 않는다. (기본) minimum_ratio 는 0 ~ 1 (원본 기본 0.55)
Sets fitting single-line text to a width. (if it overflows, shrinks from the initial size down to the minimum ratio, the original setFitWidth)
- Used where the box cannot be widened (buttons, row names, titles) and text whose length differs by language overflows.
- The set size (get_font_size) stays as is, only the size at draw time shrinks. If it still overflows at the minimum ratio it draws overflowing, and off-screen culling also considers the overflowing width.
- Wrapping text is not fitted. Not fitted if width is 0 or less. (default) minimum_ratio is 0 ~ 1 (the original default 0.55)
- widthf64
- 맞출 너비. (픽셀, 음수는 0)Width to fit. (pixels, 0 if negative)
- minimum_ratiof64
- 줄이는 가장 작은 비율. (0 ~ 1 로 자른다)Smallest ratio to shrink to. (clamped to 0 ~ 1)
짝Counterpart: vanilla.js Text.setFitWidth
use vanilla::{Graphic, Text};
fn fit_button_label(graphic: &mut Graphic) {
let mut text = Text::create_with_text("Start a new adventure", 32.0);
text.set_fit_width(200.0, 0.55);
let fitted_font_size = text.calculate_fitted_font_size(graphic);
assert!(fitted_font_size <= 32.0);
assert_eq!(text.get_font_size(), 32.0);
}맞출 너비 반환. (0 이면 맞추지 않는다)
Returns the width to fit. (no fitting if 0)
반환Returnsf64 맞출 너비. (픽셀)Width to fit. (pixels)
짝Counterpart: vanilla.js Text.getFitWidth
맞출 때 줄이는 가장 작은 비율 반환.
Returns the minimum ratio to shrink to when fitting.
반환Returnsf64 비율. (0 ~ 1, 기본 0.55)Ratio. (0 ~ 1, default 0.55)
짝Counterpart: vanilla.js Text.getFitMinimumRatio
그릴 때의 크기 반환. (마지막으로 그리거나 잰 때의 값, 맞춰 줄였으면 줄인 크기)
Returns the size at draw time. (the value from the last draw or measure, the shrunk size if it was fitted)
반환Returnsf64 크기. (픽셀, 줄을 다시 셀 일이 남았으면 정한 크기)Size. (pixels, the set size if lines still need to be recomputed)
짝Counterpart: vanilla.js Text.getFittedFontSize
마지막으로 나눈 줄의 수. (그린 뒤 글, 폰트, 줄바꿈 폭이 그대로일 때만, 아니면 None)
- 줄은 그릴 때 Graphic 의 글꼴로 나눈다. Graphic 이 없는 레이아웃(창의 내용 놓기 같은)이 그린 결과를 읽어 다시 놓을 때 쓴다.
- 줄바꿈 폭(set_word_wrap_width)을 주지 않은 여러 줄 글은 노드 폭으로 나누므로 None 이다.
Number of lines from the last split. (only while the text, font and wrap width are unchanged since drawing, otherwise None)
- Lines are split at draw time with the Graphic's font. Used by layouts without a Graphic (such as placing window contents) to read the drawn result and place again.
- Multi-line text without a wrap width (set_word_wrap_width) is split by the node width, so it is None.
반환ReturnsOption<usize> 줄 수. 아직 나누지 않았거나, 그 뒤 바뀌었거나, 노드 폭으로 나눈 글이면 None.Line count. None if not split yet, changed since, or split by the node width.
짝Counterpart: vanilla.js Text.getMeasuredLineCount
폰트 이름 설정. (Graphic 에 등록한 이름, 없으면 기본 폰트)
Sets the font name. (a name registered in the Graphic, the default font if missing)
- font_family&str
- 폰트 이름.Font name.
폰트 이름 반환.
Returns the font name.
반환Returns&str 폰트 이름. (기본 default)Font name. (default is default)
줄바꿈 폭 설정. (0 이면 줄바꿈 문자로만 나눈다)
Sets the wrap width. (if 0, splits only at newline characters)
- 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
그릴 때의 크기를 그 자리에서 재어 반환. (맞출 너비를 넘치면 줄인 크기)
Measures and returns the size at draw time on the spot. (the shrunk size if it exceeds the fit width)
- graphic&mut Graphic
- 잴 Graphic.Graphic to measure with.
반환Returnsf64 크기. (픽셀)Size. (pixels)
짝Counterpart: vanilla.js Text.calculateFittedFontSize
글의 너비 재기. (이 글자의 폰트 이름, 굵게, 기울임과 주어진 크기로, 원본 measureText)
- 글자 캐시가 폰트 문자열과 글이 같으면 다시 재지 않는다. (TextStringTextureCache.measure_text)
Measures the text width. (with this text's font name, bold, italic and the given size, the original measureText)
- The text cache does not measure again if the font string and text are the same. (TextStringTextureCache.measure_text)
- graphic&Graphic
- 잴 Graphic.Graphic to measure with.
- text&str
- 잴 글.Text to measure.
- font_sizef64
- 잴 크기. (픽셀)Size to measure at. (pixels)
반환Returnsf64 너비. (픽셀, 빈 글은 0)Width. (pixels, 0 for empty text)
짝Counterpart: vanilla.js Text.measureText
줄바꿈 방식 설정. (기본 Word)
Sets the wrap mode. (default Word)
- wrap_modeTextWrapMode
- 줄바꿈 방식.Wrap mode.
짝Counterpart: vanilla.js Text.setWrapMode
줄바꿈 방식 반환.
Returns the wrap mode.
반환ReturnsTextWrapMode 줄바꿈 방식.Wrap mode.
짝Counterpart: vanilla.js Text.getWrapMode
줄 간격 설정. (글자 크기의 배수)
Sets the line spacing. (multiple of the font size)
- line_spacingf64
- 줄 간격. (글자 크기의 배수, 기본 1.25)Line spacing. (multiple of the font size, default 1.25)
짝Counterpart: vanilla.js Text.setLineSpacing
줄 간격 반환.
Returns the line spacing.
반환Returnsf64 줄 간격. (글자 크기의 배수)Line spacing. (multiple of the font size)
짝Counterpart: vanilla.js Text.getLineSpacing
글자 간격 설정. (CSS letter-spacing, 언리얼 UMG 글자 간격과 같은 뜻. 원본 setLetterSpacing)
Sets the letter spacing. (same meaning as CSS letter-spacing and Unreal UMG letter spacing. original setLetterSpacing)
- letter_spacingf64
- 글자 묶음마다 뒤에 더하는 간격. (픽셀, 음수는 좁힘, 기본 0)Spacing added after each grapheme cluster. (pixels, negative narrows, default 0)
짝Counterpart: vanilla.js Text.setLetterSpacing
use vanilla::Text;
let mut text = Text::new();
assert_eq!(text.get_letter_spacing(), 0.0);
text.set_letter_spacing(2.5);
assert_eq!(text.get_letter_spacing(), 2.5);글자 간격 반환.
Returns the letter spacing.
반환Returnsf64 글자 간격. (픽셀, 기본 0)Letter spacing. (pixels, default 0)
짝Counterpart: vanilla.js Text.getLetterSpacing
보일 글자 수 설정. (-1 이면 전체, 타자기 연출용. -1 아래는 -1 로 맞춘다)
Sets the visible character count. (-1 for all, for typewriter effects. Values below -1 are set to -1)
- 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
글 설정.
Sets the text.
- text&str
- 글. (줄바꿈 문자로 여러 줄)Text. (multiple lines with newline characters)
짝Counterpart: vanilla.js Text.setText
글자 크기 설정. (픽셀)
Sets the font size. (pixels)
- font_sizef64
- 글자 크기. (픽셀, 기본 32)Font size. (pixels, default 32)
짝Counterpart: vanilla.js Text.setFontSize
글자 크기 반환.
Returns the font size.
반환Returnsf64 글자 크기. (픽셀, 맞춰 줄인 크기가 아니라 정한 크기)Font size. (pixels, the set size, not the size shrunk to fit)
짝Counterpart: vanilla.js Text.getFontSize
글자 색 설정.
Sets the text color.
- colorimpl Into<Color>
- 글자 색. (기본 흰색)Text color. (default white)
짝Counterpart: vanilla.js Text.setTextColor
글자 색 반환.
Returns the text color.
반환ReturnsColor 글자 색.Text color.
짝Counterpart: vanilla.js Text.getTextColor
외곽선 색 설정.
Sets the outline color.
- colorimpl Into<Color>
- 외곽선 색. (기본 흰색)Outline color. (default white)
짝Counterpart: vanilla.js Text.setStrokeColor
외곽선 색 반환.
Returns the outline color.
반환ReturnsColor 외곽선 색.Stroke color.
짝Counterpart: vanilla.js Text.getStrokeColor
외곽선 두께 설정. (0 이면 외곽선 없음)
Sets the outline thickness. (no outline if 0)
- stroke_widthf64
- 외곽선 두께. (픽셀, 기본 0)Outline thickness. (pixels, default 0)
짝Counterpart: vanilla.js Text.setStrokeWidth
외곽선 두께 반환.
Returns the outline thickness.
반환Returnsf64 외곽선 두께. (픽셀)Outline thickness. (pixels)
짝Counterpart: vanilla.js Text.getStrokeWidth
기울임 설정. (폰트 문자열에 italic 을 넣는다)
Sets italic. (adds italic to the font string)
- is_italicbool
- true 면 기울임.If true, italic.
짝Counterpart: vanilla.js Text.setItalic
기울임 여부.
Whether italic.
반환Returnsbool 기울임이면 true.true if italic.
짝Counterpart: vanilla.js Text.isItalic
밑줄 설정.
Sets underline.
- 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
취소선 설정.
Sets strikethrough.
- 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 horizontal alignment.
- text_alignTextAlign
- 가로 정렬. (기본 Center)Horizontal alignment. (default Center)
짝Counterpart: vanilla.js Text.setTextAlign
가로 정렬 반환.
Returns the horizontal alignment.
반환ReturnsTextAlign 가로 정렬.Horizontal alignment.
짝Counterpart: vanilla.js Text.getTextAlign
글자 방향 설정. (Inherit | Ltr | Rtl | Auto, 원본 setTextDirection)
- Inherit 면 그리는 때의 Graphic 방향을 따른다. (기본)
- 정렬 Start / End 가 이 방향에 따라 왼쪽, 오른쪽이 된다. (오른쪽에서 왼쪽 언어의 화면은 Rtl 과 Start)
Sets the text direction. (Inherit | Ltr | Rtl | Auto, the original setTextDirection)
- Inherit follows the Graphic's direction at draw time. (default)
- Alignment Start / End becomes left or right according to this direction. (screens in right to left languages use Rtl and Start)
- text_directionTextDirection
- 글자 방향.Text direction.
짝Counterpart: vanilla.js Text.setTextDirection
글자 방향 반환.
Returns the text direction.
반환ReturnsTextDirection 글자 방향. (기본 Inherit)Text direction. (default Inherit)
짝Counterpart: vanilla.js Text.getTextDirection
세로 기준선 설정.
Sets the vertical baseline.
- text_baselineTextBaseline
- 세로 기준선. (기본 Middle)Vertical baseline. (default Middle)
짝Counterpart: vanilla.js Text.setTextBaseline
세로 기준선 반환.
Returns the vertical baseline.
반환ReturnsTextBaseline 세로 기준선.Vertical baseline.
짝Counterpart: vanilla.js Text.getTextBaseline
함수Functions
글자 묶음으로 나누기. (원본 splitGraphemes, UAX #29 확장 글자 묶음: 받침, 성조, 결합 부호, 이모지 묶음이 앞 글자에서 떨어지지 않는다)
Splits into grapheme clusters. (the original splitGraphemes, UAX #29 extended grapheme clusters: Hangul final consonants, tone marks, combining marks and emoji sequences are not separated from the preceding character)
- text&str
- 나눌 글.Text to split.
반환ReturnsVec<&str> 글자 묶음 목록. (text 를 빌린 조각)List of grapheme clusters. (slices borrowing text)
짝Counterpart: vanilla.js splitGraphemes
글자 묶음 수. (표시 글자 수가 세는 단위)
Number of grapheme clusters. (the unit counted by the visible character count)
- text&str
- 셀 글.Text to count.
반환Returnsusize 글자 묶음 수.Number of graphemes.
짝Counterpart: vanilla.js countGraphemes
앞에서 글자 묶음 count 개까지의 글. (원본 sliceGraphemes, 글이 짧으면 글 전체)
Text up to the first count grapheme clusters. (the original sliceGraphemes, the whole text if it is shorter)
- text&str
- 글.Text.
- countusize
- 남길 글자 묶음 수.Number of graphemes to keep.
반환Returns&str 앞 조각. (text 를 빌린다)Front slice. (borrows text)
짝Counterpart: vanilla.js sliceGraphemes
앞에서 글자 묶음 count 개까지의 바이트 길이. (글이 짧으면 글 전체 길이)
Byte length up to the first count grapheme clusters. (the whole text length if it is shorter)
- text&str
- 글.Text.
- countusize
- 글자 묶음 수.Number of graphemes.
반환Returnsusize 바이트 길이.Byte length.
낱말로 나누기. (원본 splitWords, 줄바꿈 용)
- 태국어, 라오어, 크메르어, 버마어, 한중일처럼 공백 없이 쓰는 글자도 낱말 사이를 찾는다. (ICU4X 사전 낱말 나누기, 한중일 덩어리는 크롬의 ICU4C CjkBreakEngine 과 같은 셈으로 다시 나눈다) 브라우저(ICU4C)처럼 한글이 이어진 덩어리는 따로 한 낱말로 본다. ("Rust로" → "Rust", "로". ICU4X 는 한글과 라틴 글자를 한 낱말로 잇는다) 웹은 원본처럼 브라우저의 Intl.Segmenter 로 나눈다. (없는 브라우저면 원본처럼 통째로 한 조각)
- 문장 부호처럼 낱말이 아닌 조각은 앞 낱말에 붙인다. (줄 맨 앞에 문장 부호가 오지 않게) 맨 앞의 것은 첫 낱말 앞에 붙인다.
- 줄바꿈 없는 빈칸(U+00A0)으로 이은 낱말 사이는 나누지 않는다. (이름과 값, 숫자와 단위처럼 함께 있어야 하는 것)
Splits into words. (the original splitWords, for wrapping)
- Also finds word boundaries in scripts written without spaces, such as Thai, Lao, Khmer, Burmese and CJK. (ICU4X dictionary word segmentation, CJK runs are split again with the same calculation as Chrome's ICU4C CjkBreakEngine) Like the browser (ICU4C), a run of consecutive Hangul is treated as a separate word. (Rust followed by a Hangul particle splits into "Rust" and the particle. ICU4X joins Hangul and Latin letters into one word) On the web, as in the original, it splits with the browser's Intl.Segmenter. (in browsers without it, the whole text is one piece as in the original)
- Non-word pieces such as punctuation are attached to the preceding word. (so punctuation does not start a line) A leading one is attached before the first word.
- Words joined by a no-break space (U+00A0) are not split. (things that must stay together, such as a name and value, or a number and unit)
- text&str
- 나눌 글.Text to split.
반환ReturnsVec<String> 낱말 조각 목록. (조각을 이으면 원래 글이다)List of word pieces. (joining the pieces gives the original text)
짝Counterpart: vanilla.js splitWords
use vanilla::split_words;
assert_eq!(split_words("Hello, world!"), vec!["Hello, ", "world!"]);
assert_eq!(split_words("HP\u{00A0}100 MP"), vec!["HP\u{00A0}100 ", "MP"]);낱말 조각으로 나누기. ((조각, 낱말인지) 목록, ICU 낱말 경계에 한글 덩어리 경계를 더한다)
Splits into word pieces. (a list of (piece, whether it is a word), Hangul run boundaries added to the ICU word boundaries)
- text&str
- 나눌 글.Text to split.
반환ReturnsVec<(&str, bool)> (조각, 낱말인지) 목록. (조각을 이으면 원래 글이다)List of (piece, whether it is a word). (joining the pieces gives the original text)
TextWrapModeenum traits Clone, Copy, Debug, PartialEq, Eq
줄바꿈 방식. (원본 wrapMode "word" / "char")
Wrap mode. (the original wrapMode "word" / "char")
| 이름Name | 설명Description |
|---|---|
Word | 공백 단위로 채우고, 한 단어가 폭을 넘으면 글자 단위로 나눈다. (공백 없는 한중일 문장은 통째로 한 단어라 글자 단위가 된다)Fills by whitespace units, and if a single word exceeds the width, splits by characters. (a CJK sentence without spaces is one whole word, so it becomes character units) |
Character | 처음부터 글자 단위로 나눈다.Splits by characters from the start. |