mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
Allow adding dropdown and tooltip elements at a specified index
This commit is contained in:
parent
435042e1f5
commit
5a1b31e8a3
3 changed files with 20 additions and 13 deletions
|
@ -24,6 +24,7 @@ Improvements
|
||||||
- Started using SpriteBatchContext for Draw and DrawTransformed methods
|
- Started using SpriteBatchContext for Draw and DrawTransformed methods
|
||||||
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
|
- 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 Tooltip to manage more than one paragraph and make it easier to add new lines
|
||||||
|
- Allow adding dropdown elements at a specified index
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
||||||
|
|
|
@ -55,8 +55,9 @@ namespace MLEM.Ui.Elements {
|
||||||
/// Adds an element to this dropdown's <see cref="Panel"/>
|
/// Adds an element to this dropdown's <see cref="Panel"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="element">The element to add</param>
|
/// <param name="element">The element to add</param>
|
||||||
public void AddElement(Element 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>
|
||||||
this.Panel.AddChild(element);
|
public void AddElement(Element element, int index = -1) {
|
||||||
|
this.Panel.AddChild(element, index);
|
||||||
// Since the dropdown causes elements to be over each other,
|
// Since the dropdown causes elements to be over each other,
|
||||||
// usual gamepad code doesn't apply
|
// usual gamepad code doesn't apply
|
||||||
element.GetGamepadNextElement = (dir, usualNext) => {
|
element.GetGamepadNextElement = (dir, usualNext) => {
|
||||||
|
@ -77,8 +78,9 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to display</param>
|
/// <param name="text">The text to display</param>
|
||||||
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
|
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</param>
|
||||||
public Element AddElement(string 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>
|
||||||
return this.AddElement(p => text, pressed);
|
public Element AddElement(string text, GenericCallback pressed = null, int index = -1) {
|
||||||
|
return this.AddElement(p => text, pressed, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -87,7 +89,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to display</param>
|
/// <param name="text">The text to display</param>
|
||||||
/// <param name="pressed">The resulting paragraph's <see cref="Element.OnPressed"/> event</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) {
|
var paragraph = new Paragraph(Anchor.AutoLeft, 1, text) {
|
||||||
CanBeMoused = true,
|
CanBeMoused = true,
|
||||||
CanBeSelected = true,
|
CanBeSelected = true,
|
||||||
|
@ -97,7 +100,7 @@ namespace MLEM.Ui.Elements {
|
||||||
paragraph.OnPressed += pressed;
|
paragraph.OnPressed += pressed;
|
||||||
paragraph.OnMouseEnter += e => paragraph.TextColor = Color.LightGray;
|
paragraph.OnMouseEnter += e => paragraph.TextColor = Color.LightGray;
|
||||||
paragraph.OnMouseExit += e => paragraph.TextColor = Color.White;
|
paragraph.OnMouseExit += e => paragraph.TextColor = Color.White;
|
||||||
this.AddElement(paragraph);
|
this.AddElement(paragraph, index);
|
||||||
return paragraph;
|
return paragraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of <see cref="Elements.Paragraph"/> objects that this tooltip automatically manages.
|
/// 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.
|
/// 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>
|
/// </summary>
|
||||||
public readonly List<Paragraph> Paragraphs = new List<Paragraph>();
|
public readonly List<Paragraph> Paragraphs = new List<Paragraph>();
|
||||||
|
|
||||||
|
@ -132,9 +132,10 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="paragraph">The paragraph to add</param>
|
/// <param name="paragraph">The paragraph to add</param>
|
||||||
/// <returns>The added paragraph, for chaining</returns>
|
/// <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.Paragraphs.Add(paragraph);
|
||||||
this.AddChild(paragraph);
|
this.AddChild(paragraph, index);
|
||||||
if (this.Style.HasValue())
|
if (this.Style.HasValue())
|
||||||
SetParagraphStyle(paragraph, this.Style);
|
SetParagraphStyle(paragraph, this.Style);
|
||||||
return paragraph;
|
return paragraph;
|
||||||
|
@ -146,8 +147,9 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text that the paragraph should display</param>
|
/// <param name="text">The text that the paragraph should display</param>
|
||||||
/// <returns>The created paragraph, for chaining</returns>
|
/// <returns>The created paragraph, for chaining</returns>
|
||||||
public Paragraph AddParagraph(Paragraph.TextCallback 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>
|
||||||
return this.AddParagraph(new Paragraph(Anchor.AutoLeft, 0, text));
|
public Paragraph AddParagraph(Paragraph.TextCallback text, int index = -1) {
|
||||||
|
return this.AddParagraph(new Paragraph(Anchor.AutoLeft, 0, text), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -156,8 +158,9 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text that the paragraph should display</param>
|
/// <param name="text">The text that the paragraph should display</param>
|
||||||
/// <returns>The created paragraph, for chaining</returns>
|
/// <returns>The created paragraph, for chaining</returns>
|
||||||
public Paragraph AddParagraph(string 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>
|
||||||
return this.AddParagraph(p => text);
|
public Paragraph AddParagraph(string text, int index = -1) {
|
||||||
|
return this.AddParagraph(p => text, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue