public EditorToolBar(HudParentBase parent = null) : base(parent) { var background = new TexturedBox(this) { DimAlignment = DimAlignments.Both, Color = new Color(41, 54, 62), }; // Font selection fontList = new EditorDropdown <IFontMin>() { Height = 24f, Width = 140f, }; foreach (IFontMin font in FontManager.Fonts) { fontList.Add(new RichText(font.Name, GlyphFormat.White.WithFont(font.Regular)), font); } // Text size sizeList = new EditorDropdown <float>() { Height = 24f, Width = 60f, }; for (int n = 0; n < textSizes.Length; n++) { sizeList.Add(textSizes[n].ToString(), textSizes[n]); } // Builder mode textBuilderModes = new EditorDropdown <TextBuilderModes>() { Height = 24f, Width = 140f, }; textBuilderModes.Add("Unlined", TextBuilderModes.Unlined); textBuilderModes.Add("Lined", TextBuilderModes.Lined); textBuilderModes.Add("Wrapped", TextBuilderModes.Wrapped); // Font style toggle IFontMin abhaya = FontManager.GetFont("AbhayaLibreMedium"); GlyphFormat buttonFormat = new GlyphFormat(Color.White, TextAlignment.Center, 1.0f, abhaya.Regular); boldToggle = new EditorToggleButton() { Format = buttonFormat, Text = "B", }; underlineToggle = new EditorToggleButton() { Format = buttonFormat.WithStyle(FontStyles.Underline), Text = "U", }; italicToggle = new EditorToggleButton() { Format = buttonFormat.WithStyle(FontStyles.Italic), Text = "I", }; /* HudChain is useful for organizing collections of elements into straight lines with regular spacing, * either vertically horizontally. In this case, I'm organizing elements horizontally from left to right * in the same order indicated by the collection initializer below. * * HudChain and its related types, like ScrollBox and the SelectionBox types, are powerful tools for * organizing UI elements, especially when used in conjunction with oneanother. */ layout = new HudChain(false, this) // Set to alignVertical false to align the elements horizontally { // Automatically resize the height of the elements to match that of the chain and allow the chain to be // wider than the total size of the members SizingMode = HudChainSizingModes.FitMembersOffAxis | HudChainSizingModes.ClampChainAlignAxis, // Match the height of the chain and its children to the toolbar DimAlignment = DimAlignments.Height | DimAlignments.IgnorePadding, // The width of the parent could very well be greater than the width of the controls. ParentAlignment = ParentAlignments.Left | ParentAlignments.InnerH | ParentAlignments.UsePadding, // The order the elements will appear on the toolbar from left to right. CollectionContainer = { fontList, sizeList, boldToggle, underlineToggle, italicToggle, textBuilderModes } }; fontList.SelectionChanged += UpdateFormat; sizeList.SelectionChanged += UpdateFormat; boldToggle.MouseInput.LeftClicked += UpdateFormat; underlineToggle.MouseInput.LeftClicked += UpdateFormat; italicToggle.MouseInput.LeftClicked += UpdateFormat; Height = 30f; Padding = new Vector2(16f, 0f); _format = GlyphFormat.White; }
void Awake() { EditorToggleButton.Shared = this; }