Skip to content

Commit

Permalink
Add automatic resizing for the timeline track preview values for bett…
Browse files Browse the repository at this point in the history
…er readability

#519
  • Loading branch information
mafiesto4 committed Jul 30, 2021
1 parent 429223c commit 9012397
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs
Expand Up @@ -15,6 +15,8 @@ namespace FlaxEditor.GUI.Timeline.Tracks
/// <seealso cref="FlaxEditor.GUI.Timeline.Track" />
public abstract class MemberTrack : Track
{
private float _previewValueLeft;

/// <summary>
/// The member value data size (in bytes).
/// </summary>
Expand Down Expand Up @@ -163,7 +165,8 @@ protected MemberTrack(ref TrackCreateOptions options, bool useNavigationButtons
if (useValuePreview)
{
// Value preview
var previewWidth = 100.0f;
var previewWidth = 160.0f;
_previewValueLeft = uiLeft;
_previewValue = new Label
{
AutoFocus = true,
Expand All @@ -174,6 +177,7 @@ protected MemberTrack(ref TrackCreateOptions options, bool useNavigationButtons
AutoFitText = true,
TextColor = Style.Current.ForegroundGrey,
Margin = new Margin(1),
HorizontalAlignment = TextAlignment.Far,
Parent = this
};
}
Expand Down Expand Up @@ -324,6 +328,27 @@ public override void Update(float deltaTime)
TitleTintColor = p != null ? Color.White : Color.Red;
}

/// <inheritdoc />
protected override void PerformLayoutBeforeChildren()
{
if (_previewValue != null)
{
// Based on Track.Draw for track text placement
var left = _xOffset + 16 + Style.Current.FontSmall.MeasureText(Title ?? Name).X;
if (Icon.IsValid)
left += 18;
if (IsExpanded)
left = 2;

// Limit preview value size to fit before the track text
var previewWidth = Mathf.Min(200.0f, Width - left + _previewValueLeft - 12);
_previewValue.Offsets = new Margin(-previewWidth - 2 + _previewValueLeft, previewWidth, TextBox.DefaultHeight * -0.5f, TextBox.DefaultHeight);
_previewValue.Visible = Timeline.ShowPreviewValues && previewWidth > 10;
}

base.PerformLayoutBeforeChildren();
}

/// <inheritdoc />
public override void OnDestroy()
{
Expand Down

0 comments on commit 9012397

Please sign in to comment.