Browse Source

Merge pull request #6074 from workgroupengineering/features/DevTools/Startup_Screen

feat(DevTools): Startup Screen
pull/6092/head
Nikita Tsukanov 5 years ago
committed by GitHub
parent
commit
453610836f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      samples/ControlCatalog/MainWindow.xaml.cs
  2. 4
      src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
  3. 5
      src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs
  4. 9
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/MainViewModel.cs
  5. 20
      src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs

5
samples/ControlCatalog/MainWindow.xaml.cs

@ -17,7 +17,10 @@ namespace ControlCatalog
public MainWindow() public MainWindow()
{ {
this.InitializeComponent(); this.InitializeComponent();
this.AttachDevTools(); this.AttachDevTools(new Avalonia.Diagnostics.DevToolsOptions()
{
StartupScreenIndex = 1,
});
//Renderer.DrawFps = true; //Renderer.DrawFps = true;
//Renderer.DrawDirtyRects = Renderer.DrawFps = true; //Renderer.DrawDirtyRects = Renderer.DrawFps = true;

4
src/Avalonia.Diagnostics/Diagnostics/DevTools.cs

@ -10,7 +10,8 @@ namespace Avalonia.Diagnostics
{ {
public static class DevTools public static class DevTools
{ {
private static readonly Dictionary<TopLevel, Window> s_open = new Dictionary<TopLevel, Window>(); private static readonly Dictionary<TopLevel, MainWindow> s_open =
new Dictionary<TopLevel, MainWindow>();
public static IDisposable Attach(TopLevel root, KeyGesture gesture) public static IDisposable Attach(TopLevel root, KeyGesture gesture)
{ {
@ -52,6 +53,7 @@ namespace Avalonia.Diagnostics
Width = options.Size.Width, Width = options.Size.Width,
Height = options.Size.Height, Height = options.Size.Height,
}; };
window.SetOptions(options);
window.Closed += DevToolsClosed; window.Closed += DevToolsClosed;
s_open.Add(root, window); s_open.Add(root, window);

5
src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs

@ -22,5 +22,10 @@ namespace Avalonia.Diagnostics
/// Gets or sets the initial size of the DevTools window. The default value is 1280x720. /// Gets or sets the initial size of the DevTools window. The default value is 1280x720.
/// </summary> /// </summary>
public Size Size { get; set; } = new Size(1280, 720); public Size Size { get; set; } = new Size(1280, 720);
/// <summary>
/// Get or set the startup screen index where the DevTools window will be displayed.
/// </summary>
public int? StartupScreenIndex { get; set; }
} }
} }

9
src/Avalonia.Diagnostics/Diagnostics/ViewModels/MainViewModel.cs

@ -151,7 +151,7 @@ namespace Avalonia.Diagnostics.ViewModels
get { return _pointerOverElement; } get { return _pointerOverElement; }
private set { RaiseAndSetIfChanged(ref _pointerOverElement, value); } private set { RaiseAndSetIfChanged(ref _pointerOverElement, value); }
} }
private void UpdateConsoleContext(ConsoleContext context) private void UpdateConsoleContext(ConsoleContext context)
{ {
context.root = _root; context.root = _root;
@ -213,5 +213,12 @@ namespace Avalonia.Diagnostics.ViewModels
tree.SelectControl(control); tree.SelectControl(control);
} }
} }
public int? StartupScreenIndex { get; private set; } = default;
public void SetOptions(DevToolsOptions options)
{
StartupScreenIndex = options.StartupScreenIndex;
}
} }
} }

20
src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs

@ -24,6 +24,23 @@ namespace Avalonia.Diagnostics.Views
_keySubscription = InputManager.Instance.Process _keySubscription = InputManager.Instance.Process
.OfType<RawKeyEventArgs>() .OfType<RawKeyEventArgs>()
.Subscribe(RawKeyDown); .Subscribe(RawKeyDown);
EventHandler? lh = default;
lh = (s, e) =>
{
this.Opened -= lh;
if ((DataContext as MainViewModel)?.StartupScreenIndex is int index)
{
var screens = this.Screens;
if (index > -1 && index < screens.ScreenCount)
{
var screen = screens.All[index];
this.Position = screen.Bounds.TopLeft;
this.WindowState = WindowState.Maximized;
}
}
};
this.Opened += lh;
} }
public TopLevel? Root public TopLevel? Root
@ -115,5 +132,8 @@ namespace Avalonia.Diagnostics.Views
} }
private void RootClosed(object? sender, EventArgs e) => Close(); private void RootClosed(object? sender, EventArgs e) => Close();
public void SetOptions(DevToolsOptions options) =>
(DataContext as MainViewModel)?.SetOptions(options);
} }
} }

Loading…
Cancel
Save