Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for more label styling #2229

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions OpenDreamClient/Interface/Controls/ControlLabel.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
using System.Globalization;
using OpenDreamClient.Interface.Descriptors;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

namespace OpenDreamClient.Interface.Controls;

internal sealed class ControlLabel : InterfaceControl {
private Label _label;

public ControlLabel(ControlDescriptor controlDescriptor, ControlWindow window) : base(controlDescriptor, window) { }
internal sealed class ControlLabel(ControlDescriptor controlDescriptor, ControlWindow window) : InterfaceControl(controlDescriptor, window) {
private Label _label = default!;

protected override Control CreateUIElement() {
_label = new Label() {
HorizontalAlignment = Control.HAlignment.Center,
VerticalAlignment = Control.VAlignment.Center,
_label = new Label {
HorizontalExpand = true,
VerticalExpand = true
};

return _label;
var container = new PanelContainer();
container.AddChild(_label);

return container;
}

protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

ControlDescriptorLabel controlDescriptor = (ControlDescriptorLabel)ElementDescriptor;
_label.Text = controlDescriptor.Text.AsRaw();
_label.FontColorOverride = (ControlDescriptor.TextColor.Value != Color.Transparent)
? ControlDescriptor.TextColor.Value
: null;

(_label.Align, _label.VAlign) = controlDescriptor.Align.AsRaw().ToLower(CultureInfo.InvariantCulture) switch {
"center" => (Label.AlignMode.Center, Label.VAlignMode.Center),
"left" => (Label.AlignMode.Left, Label.VAlignMode.Center),
"right" => (Label.AlignMode.Right, Label.VAlignMode.Center),
"top" => (Label.AlignMode.Center, Label.VAlignMode.Top),
"bottom" => (Label.AlignMode.Center, Label.VAlignMode.Bottom),
"top-left" => (Label.AlignMode.Left, Label.VAlignMode.Top),
"top-right" => (Label.AlignMode.Right, Label.VAlignMode.Top),
"bottom-left" => (Label.AlignMode.Left, Label.VAlignMode.Bottom),
"bottom-right" => (Label.AlignMode.Right, Label.VAlignMode.Bottom),
_ => (Label.AlignMode.Center, Label.VAlignMode.Center)
// TODO: This can also take DM direction flags like WEST, or 0 for center
};
}
}
Loading