// Copyright (c) Wojciech Figat. All rights reserved. using System.Collections.Generic; using System.ComponentModel; namespace FlaxEngine.GUI { /// /// Rich text box control which can gather text input from the user and present text in highly formatted and stylized way. /// [ActorToolbox("GUI")] public partial class RichTextBox : RichTextBoxBase { private TextBlockStyle _textStyle; private TextWrapping _wrapping = TextWrapping.NoWrap; private float _baseLinesGapScale = 1.0f; /// /// The default text style applied to the whole text. /// [EditorOrder(20)] public TextBlockStyle TextStyle { get => _textStyle; set { _textStyle = value; UpdateTextBlocks(); } } /// /// Gets or sets the text wrapping within the control bounds. /// [DefaultValue(TextWrapping.NoWrap)] [EditorOrder(30), Tooltip("The text wrapping within the control bounds.")] public TextWrapping Wrapping { get => _wrapping; set { if (_wrapping == value) return; _wrapping = value; UpdateTextBlocks(); } } /// /// Gets or sets the gap between lines when wrapping and more than a single line is displayed. /// [DefaultValue(1.0f)] [EditorOrder(40), Tooltip("The gap between lines when wrapping and more than a single line is displayed."), Limit(0f, 100.0f, 0.01f)] public float BaseLinesGapScale { get => _baseLinesGapScale; set { if (Mathf.NearEqual(_baseLinesGapScale, value)) return; _baseLinesGapScale = value; UpdateTextBlocks(); } } /// /// The collection of custom text styles to apply (named). /// [EditorOrder(50)] public Dictionary Styles = new Dictionary(); /// /// The collection of custom images/sprites that can be inlined in text (named). /// [EditorOrder(60)] public Dictionary Images = new Dictionary(); /// /// Initializes a new instance of the class. /// public RichTextBox() { var style = Style.Current; _textStyle = new TextBlockStyle { Font = new FontReference(style.FontMedium), Color = style.Foreground, BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected), }; } /// protected override void OnSizeChanged() { base.OnSizeChanged(); // Refresh textblocks since those might depend on control size (eg. align right) UpdateTextBlocks(); } } }