mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
* Add grid tile to Vector2 methods Avoids me having to do it on content. * Release note * Engine * Collapsible * Add entitylookup methods for parent / map Content's done it a bunch so make it reusable. * Add MaxDimension property to Box2 Sometimes I want to pretend it's a circle radius. * Add GetLocalPosition to controls In my case I want the mouse's position inside of the control to show something under it unless there's a better way. * Add global rectangles for controls Like my other PR used to check if mouse is inbounds on the control without doing some skrunkly caching with mousemove. * Add dotted line drawing to screen handle Probably needs anti-aliasing but idk an easy way to do it. * weh * weh * a * weh * weh * Optimise ChunkEnumerator It never unioned the AABB passed in with the grid's AABB so it might inadvertantly iterate a lot more dummy chunks than it needs to. This helps speedup FindGridsIntersecting. * weh * Add DrawPrimitives overload for List<Vector2> Storing ValueList in a field seems sussy so this is the next best thing. * weh * Bump pool size * oop wrong method * Add drawing methods for lists Content may be using it over a valuelist for whatever reason. * Add more ValueList conveniences * Add more CollectionExtension methods Maybe array.resize is bad for sandbox coin, in which case I'd also settle for changing it to a list instead. * Add ToMapCoordinates method for NetCoordinates * fr * mraow * Release notes
143 lines
3.6 KiB
C#
143 lines
3.6 KiB
C#
using System;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Client.UserInterface.Controls
|
|
{
|
|
[Virtual]
|
|
public class Collapsible : BoxContainer
|
|
{
|
|
public BaseButton? Heading { get; private set; }
|
|
public Control? Body { get; private set; }
|
|
|
|
private bool _initialized = false;
|
|
|
|
private bool _bodyVisible;
|
|
public bool BodyVisible
|
|
{
|
|
get => _bodyVisible;
|
|
set
|
|
{
|
|
_bodyVisible = value;
|
|
|
|
if (Heading != null && Body != null)
|
|
{
|
|
Heading.Pressed = value;
|
|
Body.Visible = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Collapsible()
|
|
{
|
|
Orientation = LayoutOrientation.Vertical;
|
|
}
|
|
|
|
public Collapsible(CollapsibleHeading header, CollapsibleBody body) : this()
|
|
{
|
|
AddChild(header);
|
|
AddChild(body);
|
|
|
|
Initialize();
|
|
}
|
|
|
|
public Collapsible(string title, CollapsibleBody body) : this(new CollapsibleHeading(title), body)
|
|
{
|
|
|
|
}
|
|
|
|
protected internal override void Draw(DrawingHandleScreen handle)
|
|
{
|
|
if (!_initialized) Initialize();
|
|
|
|
base.Draw(handle);
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
using var enumerator = Children.GetEnumerator();
|
|
enumerator.MoveNext();
|
|
|
|
// downcast
|
|
if (enumerator.Current is not BaseButton heading
|
|
|| !heading.ToggleMode)
|
|
throw new ArgumentException("No toggle button defined in Collapsible, or title is missing");
|
|
|
|
Heading = heading;
|
|
|
|
if (!enumerator.MoveNext())
|
|
throw new ArgumentException("Not enough children in Collapsible");
|
|
|
|
Body = enumerator.Current;
|
|
BodyVisible = _bodyVisible;
|
|
Heading.Pressed = _bodyVisible;
|
|
|
|
if (enumerator.MoveNext())
|
|
throw new ArgumentException("Too many children in Collapsible");
|
|
|
|
Heading.OnToggled += args => BodyVisible = args.Pressed;
|
|
|
|
_initialized = true;
|
|
}
|
|
}
|
|
|
|
[Virtual]
|
|
public class CollapsibleHeading : ContainerButton
|
|
{
|
|
private TextureRect _chevron = new TextureRect
|
|
{
|
|
StyleClasses = { OptionButton.StyleClassOptionTriangle },
|
|
Margin = new Thickness(2, 0),
|
|
HorizontalAlignment = HAlignment.Center,
|
|
VerticalAlignment = VAlignment.Center,
|
|
};
|
|
|
|
public bool ChevronVisible
|
|
{
|
|
get => _chevron.Visible;
|
|
set => _chevron.Visible = value;
|
|
}
|
|
|
|
public Thickness ChevronMargin
|
|
{
|
|
get => _chevron.Margin;
|
|
set => _chevron.Margin = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Exposes the label for this heading.
|
|
/// </summary>
|
|
public Label Label { get; }
|
|
|
|
public string? Title
|
|
{
|
|
get => Label.Text;
|
|
set => Label.Text = value;
|
|
}
|
|
|
|
public CollapsibleHeading()
|
|
{
|
|
ToggleMode = true;
|
|
var box = new BoxContainer();
|
|
AddChild(box);
|
|
box.AddChild(_chevron);
|
|
Label = new Label();
|
|
box.AddChild(Label);
|
|
}
|
|
|
|
public CollapsibleHeading(string title) : this()
|
|
{
|
|
Title = title;
|
|
}
|
|
}
|
|
|
|
[Virtual]
|
|
public class CollapsibleBody : Container
|
|
{
|
|
public CollapsibleBody()
|
|
{
|
|
this.Visible = false;
|
|
}
|
|
}
|
|
}
|