protected override void Update() { base.Update(); float currentScroll = scrollContainer.Current; if (currentScroll != lastKnownScroll) { lastKnownScroll = currentScroll; OptionsSection bestCandidate = null; float bestDistance = float.MaxValue; foreach (OptionsSection section in sections) { float distance = Math.Abs(scrollContainer.GetChildYInContent(section) - currentScroll); if (distance < bestDistance) { bestDistance = distance; bestCandidate = section; } } var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); var next = sidebarButtons.SingleOrDefault(sb => sb.Section == bestCandidate); if (next != null) { previous.Selected = false; next.Selected = true; } } }
public OptionsOverlay() { var sections = new OptionsSection[] { new GeneralSection(), new GraphicsSection(), new GameplaySection(), new AudioSection(), new SkinSection(), new InputSection(), new EditorSection(), new OnlineSection(), new MaintenanceSection(), }; RelativeSizeAxes = Axes.Y; AutoSizeAxes = Axes.X; Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.Black, Alpha = 0.6f, }, scrollContainer = new ScrollContainer { ScrollbarOverlapsContent = false, ScrollDraggerAnchor = Anchor.TopLeft, RelativeSizeAxes = Axes.Y, Width = width, Margin = new MarginPadding { Left = sidebar_width }, Children = new[] { new FlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, Direction = FlowDirection.VerticalOnly, Children = new Drawable[] { new SpriteText { Text = "settings", TextSize = 40, Margin = new MarginPadding { Left = CONTENT_MARGINS, Top = 30 }, }, new SpriteText { Colour = new Color4(235, 117, 139, 255), Text = "Change the way osu! behaves", TextSize = 18, Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 }, }, new FlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, Direction = FlowDirection.VerticalOnly, Children = sections, } } } } }, sidebar = new OptionsSidebar { Width = sidebar_width, Children = sections.Select(section => new OptionsSidebar.SidebarButton { Icon = section.Icon, Header = section.Header, Action = () => scrollContainer.ScrollIntoView(section), } ) } }; }