1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Allow adding dropdown and tooltip elements at a specified index

This commit is contained in:
Ell 2022-05-03 19:07:53 +02:00
parent 435042e1f5
commit 5a1b31e8a3
3 changed files with 20 additions and 13 deletions

View file

@ -24,6 +24,7 @@ Improvements
- Started using SpriteBatchContext for Draw and DrawTransformed methods
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
- Allow Tooltip to manage more than one paragraph and make it easier to add new lines
- Allow adding dropdown elements at a specified index
Fixes
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode

View file

@ -55,8 +55,9 @@ namespace MLEM.Ui.Elements {
/// Adds an element to this dropdown's <see cref="Panel"/>
/// </summary>
/// <param name="element">The element to add</param>
public void AddElement(Element element) {
this.Panel.AddChild(element);
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
public void AddElement(Element element, int index = -1) {
this.Panel.AddChild(element, index);
// Since the dropdown causes elements to be over each other,
// usual gamepad code doesn't apply
element.GetGamepadNextElement = (dir, usualNext) => {
@ -77,8 +78,9 @@ namespace MLEM.Ui.Elements {
/// </summary>
/// <param name="text">The text to display</param>
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
public Element AddElement(string text, GenericCallback pressed = null) {
return this.AddElement(p => text, pressed);
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
public Element AddElement(string text, GenericCallback pressed = null, int index = -1) {
return this.AddElement(p => text, pressed, index);
}
/// <summary>
@ -87,7 +89,8 @@ namespace MLEM.Ui.Elements {
/// </summary>
/// <param name="text">The text to display</param>
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
public Element AddElement(Paragraph.TextCallback text, GenericCallback pressed = null) {
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
public Element AddElement(Paragraph.TextCallback text, GenericCallback pressed = null, int index = -1) {
var paragraph = new Paragraph(Anchor.AutoLeft, 1, text) {
CanBeMoused = true,
CanBeSelected = true,
@ -97,7 +100,7 @@ namespace MLEM.Ui.Elements {
paragraph.OnPressed += pressed;
paragraph.OnMouseEnter += e => paragraph.TextColor = Color.LightGray;
paragraph.OnMouseExit += e => paragraph.TextColor = Color.White;
this.AddElement(paragraph);
this.AddElement(paragraph, index);
return paragraph;
}

View file

@ -15,7 +15,7 @@ namespace MLEM.Ui.Elements {
/// <summary>
/// A list of <see cref="Elements.Paragraph"/> objects that this tooltip automatically manages.
/// A paragraph that is contained in this list will automatically have the <see cref="UiStyle.TooltipTextWidth"/> and <see cref="UiStyle.TooltipTextColor"/> applied.
/// To add a paragraph to both this list and to <see cref="Element.Children"/>, use <see cref="AddParagraph(Elements.Paragraph)"/>.
/// To add a paragraph to both this list and to <see cref="Element.Children"/>, use <see cref="AddParagraph(Elements.Paragraph,int)"/>.
/// </summary>
public readonly List<Paragraph> Paragraphs = new List<Paragraph>();
@ -132,9 +132,10 @@ namespace MLEM.Ui.Elements {
/// </summary>
/// <param name="paragraph">The paragraph to add</param>
/// <returns>The added paragraph, for chaining</returns>
public Paragraph AddParagraph(Paragraph paragraph) {
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
public Paragraph AddParagraph(Paragraph paragraph, int index = -1) {
this.Paragraphs.Add(paragraph);
this.AddChild(paragraph);
this.AddChild(paragraph, index);
if (this.Style.HasValue())
SetParagraphStyle(paragraph, this.Style);
return paragraph;
@ -146,8 +147,9 @@ namespace MLEM.Ui.Elements {
/// </summary>
/// <param name="text">The text that the paragraph should display</param>
/// <returns>The created paragraph, for chaining</returns>
public Paragraph AddParagraph(Paragraph.TextCallback text) {
return this.AddParagraph(new Paragraph(Anchor.AutoLeft, 0, text));
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
public Paragraph AddParagraph(Paragraph.TextCallback text, int index = -1) {
return this.AddParagraph(new Paragraph(Anchor.AutoLeft, 0, text), index);
}
/// <summary>
@ -156,8 +158,9 @@ namespace MLEM.Ui.Elements {
/// </summary>
/// <param name="text">The text that the paragraph should display</param>
/// <returns>The created paragraph, for chaining</returns>
public Paragraph AddParagraph(string text) {
return this.AddParagraph(p => text);
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Element.Children"/> list</param>
public Paragraph AddParagraph(string text, int index = -1) {
return this.AddParagraph(p => text, index);
}
/// <summary>