Skip to content

Commit

Permalink
Fix ZoomableScrollContainer not updating on parent size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Jun 2, 2022
1 parent 588151f commit 2138565
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Graphics.Containers;
Expand Down Expand Up @@ -40,10 +41,14 @@ public class ZoomableScrollContainer : OsuScrollContainer
[Resolved(canBeNull: true)]
private IFrameBasedClock editorClock { get; set; }

private readonly LayoutValue zoomedContentWidthCache = new LayoutValue(Invalidation.DrawSize);

public ZoomableScrollContainer()
: base(Direction.Horizontal)
{
base.Content.Add(zoomedContent = new Container { RelativeSizeAxes = Axes.Y });

AddLayout(zoomedContentWidthCache);
}

private float minZoom = 1;
Expand Down Expand Up @@ -103,12 +108,12 @@ public float Zoom
}
}

protected override void LoadComplete()
protected override void Update()
{
base.LoadComplete();
base.Update();

// This width only gets updated on the application of a transform, so this needs to be initialized here.
updateZoomedContentWidth();
if (!zoomedContentWidthCache.IsValid)
updateZoomedContentWidth();
}

protected override bool OnScroll(ScrollEvent e)
Expand All @@ -128,7 +133,11 @@ protected override bool OnScroll(ScrollEvent e)
return base.OnScroll(e);
}

private void updateZoomedContentWidth() => zoomedContent.Width = DrawWidth * currentZoom;
private void updateZoomedContentWidth()
{
zoomedContent.Width = DrawWidth * currentZoom;
zoomedContentWidthCache.Validate();
}

private float zoomTarget = 1;

Expand Down Expand Up @@ -199,8 +208,8 @@ protected override void Apply(ZoomableScrollContainer d, double time)
float targetOffset = expectedWidth * (focusPoint / contentSize) - focusOffset;

d.currentZoom = newZoom;

d.updateZoomedContentWidth();

// Temporarily here to make sure ScrollTo gets the correct DrawSize for scrollable area.
// TODO: Make sure draw size gets invalidated properly on the framework side, and remove this once it is.
d.Invalidate(Invalidation.DrawSize);
Expand Down

0 comments on commit 2138565

Please sign in to comment.