/// <summary> /// Create the DropDown list. /// </summary> /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">Panel skin to use for this DropDown list and header.</param> public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) : base(size, anchor, offset, skin) { // create the panel and paragraph used to show selected value _selectedTextPanel = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft); _selectedTextParagraph = new Paragraph("", Anchor.CenterLeft, new Vector2(0, SelectedPanelHeight + 8)); _selectedTextParagraph.UseActualSizeForCollision = false; _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle); _selectedTextPanel.AddChild(_selectedTextParagraph, true); // create the arrow down icon Image arrow = new Image(Resources.ArrowDown, new Vector2(30, 30), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0)); _selectedTextPanel.AddChild(arrow, true); // setup the callback to show / hide the list when clicking the dropbox _selectedTextPanel.OnClick = (Entity self) => { _isListVisible = !_isListVisible; OnResize(); }; // update styles UpdateStyle(DefaultStyle); // make sure default state is without children, eg list is hidden ClearChildren(); }
/// <summary> /// Create the DropDown list. /// </summary> /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">Panel skin to use for this DropDown list and header.</param> /// <param name="listSkin">An optional skin to use for the dropdown list only (if you want a different skin for the list).</param> /// <param name="showArrow">If true, will show an up/down arrow next to the dropdown text.</param> public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground, PanelSkin?listSkin = null, bool showArrow = true) : base(size, anchor, offset) { // default padding of self is 0 Padding = Vector2.Zero; // to get collision right when list is opened UseActualSizeForCollision = true; if (!UserInterface.Active._isDeserializing) { // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed) _selectedTextPanel = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft); _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft); _selectedTextParagraph.UseActualSizeForCollision = false; _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle); _selectedTextParagraph.Identifier = "_selectedTextParagraph"; _selectedTextPanel.AddChild(_selectedTextParagraph, true); _selectedTextPanel._hiddenInternalEntity = true; _selectedTextPanel.Identifier = "_selectedTextPanel"; // create the arrow down icon _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0)); _selectedTextPanel.AddChild(_arrowDownImage, true); _arrowDownImage._hiddenInternalEntity = true; _arrowDownImage.Identifier = "_arrowDownImage"; _arrowDownImage.Visible = showArrow; // create the list component _selectList = new SelectList(new Vector2(0f, size.Y), Anchor.TopCenter, Vector2.Zero, listSkin ?? skin); // update list offset and space before _selectList.Offset = new Vector2(0, SelectedPanelHeight); _selectList.SpaceBefore = Vector2.Zero; _selectList._hiddenInternalEntity = true; _selectList.Identifier = "_selectList"; // add the header and select list as children AddChild(_selectedTextPanel); AddChild(_selectList); InitEvents(); } // if during serialization create just a temp placeholder else { _selectList = new SelectList(new Vector2(0f, size.Y), Anchor.TopCenter, Vector2.Zero, listSkin ?? skin); } }
/// <summary> /// Create the text input. /// </summary> /// <param name="multiline">If true, text input will accept multiple lines.</param> /// <param name="size">Input box size.</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">TextInput skin, eg which texture to use.</param> public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) : base(size, skin, anchor, offset) { // set multiline mode _multiLine = multiline; // special case - if multiline and asked for default height, make it heigher if (multiline && size.Y == -1) { _size.Y *= 4; } // update default style UpdateStyle(DefaultStyle); // set limit by size - default true in single-line, default false in multi-line LimitBySize = !_multiLine; // create paragraph to show current value TextParagraph = UserInterface.DefaultParagraph(string.Empty, _multiLine ? Anchor.TopLeft : Anchor.CenterLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); TextParagraph._hiddenInternalEntity = true; AddChild(TextParagraph, true); // create the placeholder paragraph PlaceholderParagraph = UserInterface.DefaultParagraph(string.Empty, _multiLine ? Anchor.TopLeft : Anchor.CenterLeft); PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle); PlaceholderParagraph._hiddenInternalEntity = true; AddChild(PlaceholderParagraph, true); // create the scrollbar if (_multiLine) { _scrollbar = new VerticalScrollbar(0, 0, Anchor.CenterRight, offset: new Vector2(-8, 0)); _scrollbar.Value = 0; _scrollbar.Visible = false; _scrollbar._hiddenInternalEntity = true; AddChild(_scrollbar, false); } // set word-wrap mode based on whether or not this text input is multiline TextParagraph.WrapWords = _multiLine; PlaceholderParagraph.WrapWords = _multiLine; // if the default paragraph type is multicolor, disable it for input MulticolorParagraph colorTextParagraph = TextParagraph as MulticolorParagraph; if (colorTextParagraph != null) { colorTextParagraph.EnableColorInstructions = false; } }
/// <summary> /// Create the button. /// </summary> /// <param name="text">Text for the button label.</param> /// <param name="skin">Button skin (texture to use).</param> /// <param name="anchor">Position anchor.</param> /// <param name="size">Button size (if not defined will use default size).</param> /// <param name="offset">Offset from anchor position.</param> public Button(string text, ButtonSkin skin = ButtonSkin.Default, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null) : base(size, anchor, offset) { // store style _skin = skin; // update styles UpdateStyle(DefaultStyle); // create and set button paragraph ButtonParagraph = new Paragraph(text, Anchor.Center); ButtonParagraph.UpdateStyle(DefaultParagraphStyle); AddChild(ButtonParagraph, true); }
/// <summary> /// Create a new checkbox entity. /// </summary> /// <param name="text">CheckBox label text.</param> /// <param name="anchor">Position anchor.</param> /// <param name="size">CheckBox size.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="isChecked">If true, this checkbox will be created as 'checked'.</param> public CheckBox(string text, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null, bool isChecked = false) : base(size, anchor, offset) { // update default style UpdateStyle(DefaultStyle); // create and set checkbox paragraph TextParagraph = new Paragraph(text, Anchor.CenterLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); AddChild(TextParagraph, true); // set value Checked = isChecked; }
/// <summary> /// Create the text input. /// </summary> /// <param name="multiline">If true, text input will accept multiple lines.</param> /// <param name="size">Input box size.</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">TextInput skin, eg which texture to use.</param> public GrowTextInput(UserInterface ui, bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground, bool growx = false) : base(ui, size, skin, anchor, offset) { // set multiline mode _multiLine = multiline; // update default style UpdateStyle(DefaultStyle); // default size of multiline text input is 4 times bigger if (multiline) { SetStyleProperty(StylePropertyIds.DefaultSize, new DataTypes.StyleProperty(EntityDefaultSize * new Vector2(1, 4))); } // set limit by size - default true in single-line, default false in multi-line LimitBySize = !_multiLine; if (!_userinterface.Active._isDeserializing) { // create paragraph to show current value TextParagraph = _userinterface.DefaultParagraph(string.Empty, Anchor.TopLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); TextParagraph._hiddenInternalEntity = true; TextParagraph.Identifier = "_TextParagraph"; AddChild(TextParagraph, true); // create the placeholder paragraph PlaceholderParagraph = _userinterface.DefaultParagraph(string.Empty, Anchor.TopLeft); PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle); PlaceholderParagraph._hiddenInternalEntity = true; PlaceholderParagraph.Identifier = "_PlaceholderParagraph"; AddChild(PlaceholderParagraph, true); // update multiline related stuff UpdateMultilineState(); // if the default paragraph type is multicolor, disable it for input RichParagraph colorTextParagraph = TextParagraph as RichParagraph; if (colorTextParagraph != null) { colorTextParagraph.EnableStyleInstructions = false; } if (growx) { GrowX = true; } } }
/// <summary> /// Create a new checkbox entity. /// </summary> /// <param name="text">CheckBox label text.</param> /// <param name="anchor">Position anchor.</param> /// <param name="size">CheckBox size.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="isChecked">If true, this checkbox will be created as 'checked'.</param> public CheckBox(string text, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null, bool isChecked = false) : base(size, anchor, offset) { // update default style UpdateStyle(DefaultStyle); // create and set checkbox paragraph TextParagraph = UserInterface.DefaultParagraph(text, Anchor.CenterLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); AddChild(TextParagraph, true); // checkboxes are promiscuous by default. PromiscuousClicksMode = true; // set value Checked = isChecked; }
/// <summary> /// Create the text input. /// </summary> /// <param name="multiline">If true, text input will accept multiple lines.</param> /// <param name="size">Input box size.</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">TextInput skin, eg which texture to use.</param> public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) : base(size, skin, anchor, offset) { // set multiline mode _multiLine = multiline; // special case - if multiline and asked for default height, make it heigher if (multiline && size.Y == -1) { _size.Y *= 4; } // update default style UpdateStyle(DefaultStyle); // set limit by size - default true in single-line, default false in multi-line LimitBySize = !_multiLine; if (!UserInterface.Active._isDeserializing) { // create paragraph to show current value TextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.TopLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); TextParagraph._hiddenInternalEntity = true; TextParagraph.Identifier = "_TextParagraph"; AddChild(TextParagraph, true); // create the placeholder paragraph PlaceholderParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.TopLeft); PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle); PlaceholderParagraph._hiddenInternalEntity = true; PlaceholderParagraph.Identifier = "_PlaceholderParagraph"; AddChild(PlaceholderParagraph, true); // update multiline related stuff UpdateMultilineState(); // if the default paragraph type is multicolor, disable it for input MulticolorParagraph colorTextParagraph = TextParagraph as MulticolorParagraph; if (colorTextParagraph != null) { colorTextParagraph.EnableColorInstructions = false; } } }
/// <summary> /// Create the button. /// </summary> /// <param name="text">Text for the button label.</param> /// <param name="skin">Button skin (texture to use).</param> /// <param name="anchor">Position anchor.</param> /// <param name="size">Button size (if not defined will use default size).</param> /// <param name="offset">Offset from anchor position.</param> public Button(string text, ButtonSkin skin = ButtonSkin.Default, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null) : base(size, anchor, offset) { // store style _skin = skin; // update styles UpdateStyle(DefaultStyle); if (!UserInterface.Active._isDeserializing) { // create and set button paragraph ButtonParagraph = UserInterface.DefaultParagraph(text, Anchor.Center); ButtonParagraph._hiddenInternalEntity = true; ButtonParagraph.UpdateStyle(DefaultParagraphStyle); ButtonParagraph.Identifier = "_button_caption"; AddChild(ButtonParagraph, true); } }
/// <summary> /// Create the text input. /// </summary> /// <param name="multiline">If true, text input will accept multiple lines.</param> /// <param name="size">Input box size.</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">TextInput skin, eg which texture to use.</param> public TextInput(bool multiline, Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) : base(size, skin, anchor, offset) { // set multiline mode _multiLine = multiline; // special case - if multiline and asked for default height, make it heigher if (multiline && size.Y == -1) { _size.Y *= 4; } // update default style UpdateStyle(DefaultStyle); // set limit by size - default true in single-line, default false in multi-line LimitBySize = !_multiLine; // create paragraph to show current value TextParagraph = new Paragraph("", _multiLine ? Anchor.TopLeft : Anchor.CenterLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); AddChild(TextParagraph, true); // create the placeholder paragraph PlaceholderParagraph = new Paragraph("", _multiLine ? Anchor.TopLeft : Anchor.CenterLeft); PlaceholderParagraph.UpdateStyle(DefaultPlaceholderStyle); AddChild(PlaceholderParagraph, true); // create the scrollbar if (_multiLine) { _scrollbar = new VerticalScrollbar(0, 0, Anchor.CenterRight, offset: new Vector2(-8, 0)); _scrollbar.Value = 0; _scrollbar.Visible = false; AddChild(_scrollbar, false); } // set word-wrap mode based on weather or not this text input is multiline TextParagraph.WrapWords = _multiLine; PlaceholderParagraph.WrapWords = _multiLine; }
/// <summary> /// Create a new checkbox entity. /// </summary> /// <param name="text">CheckBox label text.</param> /// <param name="anchor">Position anchor.</param> /// <param name="size">CheckBox size.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="isChecked">If true, this checkbox will be created as 'checked'.</param> public CheckBox(UserInterface ui, string text, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null, bool isChecked = false) : base(ui, size, anchor, offset) { // update default style UpdateStyle(DefaultStyle); // create and set checkbox paragraph if (!_userinterface.Active._isDeserializing) { TextParagraph = _userinterface.DefaultParagraph(text, Anchor.CenterLeft); TextParagraph.UpdateStyle(DefaultParagraphStyle); TextParagraph.Offset = new Vector2(25, 0); TextParagraph._hiddenInternalEntity = true; TextParagraph.Identifier = "_checkbox_text"; AddChild(TextParagraph, true); } // checkboxes are promiscuous by default. PromiscuousClicksMode = true; // set value Checked = isChecked; }
/// <summary> /// When list is resized (also called on init), create the labels to show item values and init graphical stuff. /// </summary> /// <param name="recalcDestRect">If true, will also recalculate destination rectangle.</param> protected virtual void OnResize(bool recalcDestRect = true) { // store current size _prevSize = _size; // remove all children before re-creating them ClearChildren(); // remove previous paragraphs list _paragraphs.Clear(); // calculate self destination rect if (recalcDestRect) { _destRect = CalcDestRect(); } // calculate paragraphs quantity int i = 0; while (true) { // create and add new paragraph Paragraph paragraph = new Paragraph(".", Anchor.Auto, new Vector2(0, 40)); // note: we set negative padding for the selected mark size so it won't be negative size paragraph.WrapWords = false; paragraph.UpdateStyle(DefaultParagraphStyle); paragraph.Scale = paragraph.Scale * ItemsScale; paragraph.SpaceAfter = paragraph.SpaceAfter + new Vector2(0, ExtraSpaceBetweenLines); paragraph.AttachedData = new ParagraphData(this, i++); paragraph.UseActualSizeForCollision = false; AddChild(paragraph); _paragraphs.Add(paragraph); OnCreatedListParagraph(paragraph); // add callback to selection paragraph.OnClick = (Entity entity) => { ParagraphData data = (ParagraphData)entity.AttachedData; if (!data.list.LockSelection) { data.list.Select(data.relativeIndex, true); } }; // to calculate paragraph actual bottom paragraph.CalcDestRect(); paragraph.PrepareForDraw(); // if out of list bounderies remove this paragraph and stop if ((paragraph.GetActualDestRect().Bottom > _destRect.Bottom - Padding.Y) || i > _list.Count) { RemoveChild(paragraph); _paragraphs.Remove(paragraph); break; } } // add scrollbar last, but only if needed if (_paragraphs.Count < _list.Count) { // add scrollbar to list AddChild(_scrollbar, false); // calc max scroll value _scrollbar.Max = (uint)(_list.Count - _paragraphs.Count); if (_scrollbar.Max < 2) { _scrollbar.Max = 2; } _scrollbar.StepsCount = _scrollbar.Max; _scrollbar.Visible = true; } // if no scrollbar is needed, hide it else { _scrollbar.Visible = false; if (_scrollbar.Value > 0) { _scrollbar.Value = 0; } } }
/// <summary> /// Create the DropDown list. /// </summary> /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">Panel skin to use for this DropDown list and header.</param> /// <param name="listSkin">An optional skin to use for the dropdown list only (if you want a different skin for the list).</param> /// <param name="showArrow">If true, will show an up/down arrow next to the dropdown text.</param> public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground, PanelSkin?listSkin = null, bool showArrow = true) : base(size, anchor, offset) { // default padding of self is 0 Padding = Vector2.Zero; // to get collision right when list is opened UseActualSizeForCollision = true; // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed) _selectedTextPanel = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft); _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft); _selectedTextParagraph.UseActualSizeForCollision = false; _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle); _selectedTextPanel.AddChild(_selectedTextParagraph, true); _selectedTextPanel._hiddenInternalEntity = true; // create the arrow down icon _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0)); _selectedTextPanel.AddChild(_arrowDownImage, true); _arrowDownImage._hiddenInternalEntity = true; _arrowDownImage.Visible = showArrow; // create the list component _selectList = new SelectList(new Vector2(0f, size.Y), Anchor.TopCenter, Vector2.Zero, listSkin ?? skin); // update list offset and space before _selectList.SetOffset(new Vector2(0, SelectedPanelHeight)); _selectList.SpaceBefore = Vector2.Zero; _selectList._hiddenInternalEntity = true; // add the header and select list as children AddChild(_selectedTextPanel); AddChild(_selectList); // add callback on list value change _selectList.OnValueChange = (Entity entity) => { // hide list ListVisible = false; // set selected text _selectedTextParagraph.Text = (SelectedValue ?? DefaultText); }; // on click, always hide the selectlist _selectList.OnClick = (Entity entity) => { ListVisible = false; }; // hide the list by default _selectList.Visible = false; // setup the callback to show / hide the list when clicking the dropbox _selectedTextPanel.OnClick = (Entity self) => { // change visibility ListVisible = !ListVisible; }; // set starting text _selectedTextParagraph.Text = (SelectedValue ?? DefaultText); // update styles _selectList.UpdateStyle(DefaultStyle); // make the list events trigger the dropdown events _selectList.PropagateEventsTo(this); // make the selected value panel trigger the dropdown events _selectedTextPanel.PropagateEventsTo(this); }
/// <summary> /// When list is resized (also called on init), create the labels to show item values and init graphical stuff. /// </summary> protected virtual void OnResize() { // if not visible, skip if (!IsVisible()) { _hadResizeWhileNotVisible = true; return; } // clear the _hadResizeWhileNotVisible flag _hadResizeWhileNotVisible = false; // remove all children before re-creating them ClearChildren(); // remove previous paragraphs list _paragraphs.Clear(); // make sure destination rect is up-to-date UpdateDestinationRects(); // calculate paragraphs quantity int i = 0; while (true) { // create and add new paragraph Paragraph paragraph = UserInterface.DefaultParagraph(".", Anchor.Auto); paragraph.PromiscuousClicksMode = true; paragraph.WrapWords = false; paragraph.UpdateStyle(DefaultParagraphStyle); paragraph.Scale = paragraph.Scale * ItemsScale; paragraph.SpaceAfter = paragraph.SpaceAfter + new Vector2(0, ExtraSpaceBetweenLines - 2); paragraph.ExtraMargin.Y = ExtraSpaceBetweenLines / 2 + 3; paragraph.AttachedData = new ParagraphData(this, i++); paragraph.UseActualSizeForCollision = false; paragraph.Size = new Vector2(0, paragraph.GetCharacterActualSize().Y + ExtraSpaceBetweenLines); paragraph.BackgroundColorPadding = new Point((int)Padding.X, 5); paragraph.BackgroundColorUseBoxSize = true; paragraph._hiddenInternalEntity = true; paragraph.PropagateEventsTo(this); AddChild(paragraph); // call the callback whenever a new paragraph is created OnCreatedListParagraph(paragraph); // add to paragraphs list _paragraphs.Add(paragraph); // add callback to selection paragraph.OnClick += (Entity entity) => { ParagraphData data = (ParagraphData)entity.AttachedData; if (!data.list.LockSelection) { data.list.Select(data.relativeIndex, true); } }; // to calculate paragraph actual bottom paragraph.UpdateDestinationRects(); // if out of list bounderies remove this paragraph and stop if ((paragraph.GetActualDestRect().Bottom > _destRect.Bottom - _scaledPadding.Y) || i > _list.Count) { RemoveChild(paragraph); _paragraphs.Remove(paragraph); break; } } // add scrollbar last, but only if needed if (_paragraphs.Count > 0 && _paragraphs.Count < _list.Count) { // add scrollbar to list AddChild(_scrollbar, false); // calc max scroll value _scrollbar.Max = (uint)(_list.Count - _paragraphs.Count); if (_scrollbar.Max < 2) { _scrollbar.Max = 2; } _scrollbar.StepsCount = _scrollbar.Max; _scrollbar.Visible = true; } // if no scrollbar is needed, hide it else { _scrollbar.Visible = false; if (_scrollbar.Value > 0) { _scrollbar.Value = 0; } } }
/// <summary> /// Called for every new paragraph entity created as part of the list, to allow children classes /// to add extra processing etc to list labels. /// </summary> /// <param name="paragraph">The newly created paragraph once ready (after added to list container).</param> protected override void OnCreatedListParagraph(Paragraph paragraph) { paragraph.UpdateStyle(DefaultParagraphStyle); }
/// <summary> /// Create the DropDown list. /// </summary> /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">Panel skin to use for this DropDown list and header.</param> public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) : base(size, anchor, offset) { // default padding of self is 0 Padding = Vector2.Zero; // to get collision right when list is opened UseActualSizeForCollision = true; // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed) _selectedTextPanel = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft); _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft); _selectedTextParagraph.UseActualSizeForCollision = false; _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle); _selectedTextPanel.AddChild(_selectedTextParagraph, true); // create the arrow down icon _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0)); _selectedTextPanel.AddChild(_arrowDownImage, true); // create the list component _selectList = new SelectList(size, Anchor.TopCenter, Vector2.Zero, skin); // update list offset and space before _selectList.SetOffset(new Vector2(0, SelectedPanelHeight)); _selectList.SpaceBefore = Vector2.Zero; // add the header and select list as children AddChild(_selectedTextPanel); AddChild(_selectList); // add callback on list value change _selectList.OnValueChange = (Entity entity) => { // hide list ListVisible = false; // set selected text _selectedTextParagraph.Text = (SelectedValue ?? DefaultText); }; // hide the list by default _selectList.Visible = false; // setup the callback to show / hide the list when clicking the dropbox _selectedTextPanel.OnClick = (Entity self) => { // change visibility ListVisible = !ListVisible; }; // set starting text _selectedTextParagraph.Text = (SelectedValue ?? DefaultText); // update styles _selectList.UpdateStyle(DefaultStyle); // make the list events trigger the dropdown events _selectList.OnListChange += (Entity entity) => { OnListChange?.Invoke(this); }; _selectList.OnMouseDown += (Entity entity) => { OnMouseDown?.Invoke(this); }; _selectList.OnMouseReleased += (Entity entity) => { OnMouseReleased?.Invoke(this); }; _selectList.WhileMouseDown += (Entity entity) => { WhileMouseDown?.Invoke(this); }; _selectList.WhileMouseHover += (Entity entity) => { WhileMouseHover?.Invoke(this); }; _selectList.OnClick += (Entity entity) => { OnClick?.Invoke(this); }; _selectList.OnValueChange += (Entity entity) => { OnValueChange?.Invoke(this); }; _selectList.OnMouseEnter += (Entity entity) => { OnMouseEnter?.Invoke(this); }; _selectList.OnMouseLeave += (Entity entity) => { OnMouseLeave?.Invoke(this); }; _selectList.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); }; _selectList.OnStartDrag += (Entity entity) => { OnStartDrag?.Invoke(this); }; _selectList.OnStopDrag += (Entity entity) => { OnStopDrag?.Invoke(this); }; _selectList.WhileDragging += (Entity entity) => { WhileDragging?.Invoke(this); }; _selectList.BeforeDraw += (Entity entity) => { BeforeDraw?.Invoke(this); }; _selectList.AfterDraw += (Entity entity) => { AfterDraw?.Invoke(this); }; _selectList.BeforeUpdate += (Entity entity) => { BeforeUpdate?.Invoke(this); }; _selectList.AfterUpdate += (Entity entity) => { AfterUpdate?.Invoke(this); }; // make the selected value panel trigger the dropdown events _selectedTextPanel.OnMouseDown += (Entity entity) => { OnMouseDown?.Invoke(this); }; _selectedTextPanel.OnMouseReleased += (Entity entity) => { OnMouseReleased?.Invoke(this); }; _selectedTextPanel.WhileMouseDown += (Entity entity) => { WhileMouseDown?.Invoke(this); }; _selectedTextPanel.WhileMouseHover += (Entity entity) => { WhileMouseHover?.Invoke(this); }; _selectedTextPanel.OnClick += (Entity entity) => { OnClick?.Invoke(this); }; _selectedTextPanel.OnValueChange += (Entity entity) => { OnValueChange?.Invoke(this); }; _selectedTextPanel.OnMouseEnter += (Entity entity) => { OnMouseEnter?.Invoke(this); }; _selectedTextPanel.OnMouseLeave += (Entity entity) => { OnMouseLeave?.Invoke(this); }; _selectedTextPanel.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); }; _selectedTextPanel.OnStartDrag += (Entity entity) => { OnStartDrag?.Invoke(this); }; _selectedTextPanel.OnStopDrag += (Entity entity) => { OnStopDrag?.Invoke(this); }; _selectedTextPanel.WhileDragging += (Entity entity) => { WhileDragging?.Invoke(this); }; _selectedTextPanel.BeforeDraw += (Entity entity) => { BeforeDraw?.Invoke(this); }; _selectedTextPanel.AfterDraw += (Entity entity) => { AfterDraw?.Invoke(this); }; _selectedTextPanel.BeforeUpdate += (Entity entity) => { BeforeUpdate?.Invoke(this); }; _selectedTextPanel.AfterUpdate += (Entity entity) => { AfterUpdate?.Invoke(this); }; }