mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-24 01:09:23 +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
|
||||
- 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue