Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add stylebox to multiline input #5496

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 36 additions & 7 deletions Robust.Client/UserInterface/Controls/TextEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public sealed class TextEdit : Control
[Dependency] private readonly IClipboardManager _clipboard = null!;
[Dependency] private readonly IClyde _clyde = null!;

public const string StylePropertyStyleBox = "stylebox";
public StyleBox? StyleBoxOverride { get; set; }

// @formatter:off
public const string StylePropertyCursorColor = "cursor-color";
public const string StylePropertySelectionColor = "selection-color";
Expand Down Expand Up @@ -784,15 +787,16 @@ private void AbortIme(bool delete = true)

protected override Vector2 ArrangeOverride(Vector2 finalSize)
{
var size = base.ArrangeOverride(finalSize);
var style = _getStyleBox();
var box = UIBox2.FromDimensions(Vector2.Zero, finalSize);
_renderBox.Arrange(style.GetContentBox(box, 1));

var renderBoxSize = _renderBox.Size;

_scrollBar.Page = renderBoxSize.Y * UIScale;

UpdateLineBreaks((int)(renderBoxSize.X * UIScale));

return size;
return finalSize;
}
Comment on lines 788 to 800
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're no longer arranging the vertical scroll bar here.


protected override void FrameUpdate(FrameEventArgs args)
Expand All @@ -805,12 +809,12 @@ protected override void FrameUpdate(FrameEventArgs args)

if (_mouseSelectingText)
{
var contentBox = PixelSizeBox;
var style = _getStyleBox();
var contentBox = style.GetContentBox(PixelSizeBox, UIScale);

var index = GetIndexAtPos(_lastMouseSelectPos);

_cursorPosition = index;

// Only move scrollbar when the cursor is dragging above/below the text control.
if (_lastMouseSelectPos.Y < contentBox.Top)
{
Expand Down Expand Up @@ -947,7 +951,8 @@ private CursorPos GetIndexAtHorizontalPos(int line, float horizontalPos)
if (IsPlaceholderVisible)
return default;

var contentBox = PixelSizeBox;
var style = _getStyleBox();
var contentBox = style.GetContentBox(PixelSizeBox, UIScale);
var font = GetFont();
var uiScale = UIScale;
horizontalPos *= uiScale;
Expand Down Expand Up @@ -1179,7 +1184,29 @@ private void UpdatePseudoClass()
AddStylePseudoClass(StylePseudoClassNotEditable);
}

protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);

_getStyleBox().Draw(handle, PixelSizeBox, UIScale);
}

[Pure]
private StyleBox _getStyleBox()
{
if (StyleBoxOverride != null)
{
return StyleBoxOverride;
}

if (TryGetStyleProperty<StyleBox>(StylePropertyStyleBox, out var box))
{
return box;
}

return UserInterfaceManager.ThemeDefaults.LineEditBox;
}

/// <summary>
/// Sub-control responsible for doing the actual rendering work.
/// </summary>
Expand Down Expand Up @@ -1216,6 +1243,8 @@ public RenderBox(TextEdit master)

protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);

CursorPos? drawIndexDebug = null;
if (_master.DebugOverlay && _master._lastDebugMousePos is { } mouse)
{
Expand Down
Loading