Scroll selected room into view on selection

This commit is contained in:
Dean Herbert
2020-07-09 17:28:22 +09:00
parent 69062a3ed1
commit 80f6f87e01

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -20,21 +21,23 @@ namespace osu.Game.Screens.Multi.Lounge
{ {
public override string Title => "Lounge"; public override string Title => "Lounge";
protected readonly FilterControl Filter; protected FilterControl Filter;
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>(); private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
private readonly Container content; private Container content;
private readonly LoadingLayer loadingLayer; private LoadingLayer loadingLayer;
[Resolved] [Resolved]
private Bindable<Room> selectedRoom { get; set; } private Bindable<Room> selectedRoom { get; set; }
private bool joiningRoom; private bool joiningRoom;
public LoungeSubScreen() [BackgroundDependencyLoader]
private void load()
{ {
RoomsContainer roomsContainer; RoomsContainer roomsContainer;
OsuScrollContainer scrollContainer;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
@ -50,7 +53,7 @@ namespace osu.Game.Screens.Multi.Lounge
Width = 0.55f, Width = 0.55f,
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuScrollContainer scrollContainer = new OsuScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false, ScrollbarOverlapsContent = false,
@ -70,6 +73,14 @@ namespace osu.Game.Screens.Multi.Lounge
}, },
}, },
}; };
// scroll selected room into view on selection.
selectedRoom.BindValueChanged(val =>
{
var drawable = roomsContainer.Rooms.FirstOrDefault(r => r.Room == val.NewValue);
if (drawable != null)
scrollContainer.ScrollIntoView(drawable);
});
} }
protected override void LoadComplete() protected override void LoadComplete()