using System;
using Robust.Client.Graphics;
using Robust.Shared;
namespace Robust.Client.UserInterface.Controls
{
public sealed class WindowRoot : UIRoot
{
private PopupContainer? _modalRoot;
private LayoutContainer? _popupRoot;
internal WindowRoot(IClydeWindow window)
{
Window = window;
}
public override float UIScale => UIScaleSet;
internal float UIScaleSet { get; set; }
///
/// Set after the window is resized, to batch up UI scale updates on window resizes.
///
internal bool UIScaleUpdateNeeded { get; set; }
public override IClydeWindow Window { get; }
///
/// Disable automatic scaling of window based on resolution.
///
///
///
/// Disabled by default for non-main windows as those most likely are smaller popup windows,
/// that won't make sense with the default parameters.
///
///
///
public bool DisableAutoScaling { get; set; } = true;
public override PopupContainer ModalRoot => _modalRoot ?? throw new InvalidOperationException(
$"Tried to access root controls without calling {nameof(CreateRootControls)}!");
public override LayoutContainer PopupRoot => _popupRoot ?? throw new InvalidOperationException(
$"Tried to access root controls without calling {nameof(CreateRootControls)}!");
///
/// Creates root controls (e.g. ) that are necessary for the UI system to
/// fully function.
///
///
/// This should be called *after* inserting the main content into this instance,
/// so that the created root controls (e.g. popups) correctly stay on top.
///
public void CreateRootControls()
{
if (_modalRoot != null)
throw new InvalidOperationException("We've already created root controls!");
_modalRoot = new PopupContainer
{
Name = nameof(ModalRoot),
MouseFilter = MouseFilterMode.Ignore,
};
AddChild(_modalRoot);
_popupRoot = new LayoutContainer
{
Name = nameof(PopupRoot),
MouseFilter = MouseFilterMode.Ignore
};
AddChild(_popupRoot);
}
}
}