Skip to content

Commit

Permalink
Appease codefactor for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 11, 2025
1 parent 870cecd commit 862a68d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,60 +90,60 @@ private void scrollIntoView(int index)
AddStep($"scroll {index} into view", () => scrollContainer.ScrollIntoView(scrollContainer.ChildrenOfType<BoxWithDouble>().Skip(index).First()));
AddUntilStep($"{index} is visible", () => !scrollContainer.ChildrenOfType<BoxWithDouble>().Skip(index).First().IsMaskedAway);
}
}

public partial class DoubleScrollContainer : BasicScrollContainer
{
private readonly Container<BoxWithDouble> layoutContent;

public override void Add(Drawable drawable)
public partial class DoubleScrollContainer : BasicScrollContainer
{
if (drawable is not BoxWithDouble boxWithDouble)
throw new InvalidOperationException();
private readonly Container<BoxWithDouble> layoutContent;

Add(boxWithDouble);
}
public override void Add(Drawable drawable)
{
if (drawable is not BoxWithDouble boxWithDouble)
throw new InvalidOperationException();

public void Add(BoxWithDouble drawable)
{
if (drawable is not BoxWithDouble boxWithDouble)
throw new InvalidOperationException();
Add(boxWithDouble);
}

layoutContent.Height = (float)Math.Max(layoutContent.Height, boxWithDouble.DoubleLocation + boxWithDouble.DrawHeight);
layoutContent.Add(drawable);
}
public void Add(BoxWithDouble drawable)
{
if (drawable is not BoxWithDouble boxWithDouble)
throw new InvalidOperationException();

public DoubleScrollContainer()
{
// Managing our own custom layout within ScrollContent causes feedback with internal ScrollContainer calculations,
// so we must maintain one level of separation from ScrollContent.
base.Add(layoutContent = new Container<BoxWithDouble>
layoutContent.Height = (float)Math.Max(layoutContent.Height, boxWithDouble.DoubleLocation + boxWithDouble.DrawHeight);
layoutContent.Add(drawable);
}

public DoubleScrollContainer()
{
RelativeSizeAxes = Axes.X,
});
}
// Managing our own custom layout within ScrollContent causes feedback with internal ScrollContainer calculations,
// so we must maintain one level of separation from ScrollContent.
base.Add(layoutContent = new Container<BoxWithDouble>
{
RelativeSizeAxes = Axes.X,
});
}

public override double GetChildPosInContent(Drawable d, Vector2 offset)
{
if (d is not BoxWithDouble boxWithDouble)
return base.GetChildPosInContent(d, offset);
public override double GetChildPosInContent(Drawable d, Vector2 offset)
{
if (d is not BoxWithDouble boxWithDouble)
return base.GetChildPosInContent(d, offset);

return boxWithDouble.DoubleLocation + offset.X;
}
return boxWithDouble.DoubleLocation + offset.X;
}

protected override void ApplyCurrentToContent()
{
Debug.Assert(ScrollDirection == Direction.Vertical);
protected override void ApplyCurrentToContent()
{
Debug.Assert(ScrollDirection == Direction.Vertical);

double scrollableExtent = -Current + ScrollableExtent * ScrollContent.RelativeAnchorPosition.Y;
double scrollableExtent = -Current + ScrollableExtent * ScrollContent.RelativeAnchorPosition.Y;

foreach (var d in layoutContent)
d.Y = (float)(d.DoubleLocation + scrollableExtent);
foreach (var d in layoutContent)
d.Y = (float)(d.DoubleLocation + scrollableExtent);
}
}
}

public partial class BoxWithDouble : Box
{
public double DoubleLocation { get; set; }
public partial class BoxWithDouble : Box
{
public double DoubleLocation { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/Containers/ScrollContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,9 @@ protected override void UpdateAfterChildren()
protected virtual void ApplyCurrentToContent()
{
if (ScrollDirection == Direction.Horizontal)
ScrollContent.X = (float)(-Current + ScrollableExtent * ScrollContent.RelativeAnchorPosition.X);
ScrollContent.X = (float)(-Current + (ScrollableExtent * ScrollContent.RelativeAnchorPosition.X));
else
ScrollContent.Y = (float)(-Current + ScrollableExtent * ScrollContent.RelativeAnchorPosition.Y);
ScrollContent.Y = (float)(-Current + (ScrollableExtent * ScrollContent.RelativeAnchorPosition.Y));
}

/// <summary>
Expand Down

0 comments on commit 862a68d

Please sign in to comment.