Skip to content

Commit

Permalink
Merge pull request #6074 from workgroupengineering/features/DevTools/…
Browse files Browse the repository at this point in the history
…Startup_Screen

feat(DevTools): Startup Screen
  • Loading branch information
kekekeks authored and Dan Walmsley committed Jun 18, 2021
1 parent 6936072 commit 6bac166
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion samples/ControlCatalog/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public class MainWindow : Window
public MainWindow()
{
this.InitializeComponent();
this.AttachDevTools();
this.AttachDevTools(new Avalonia.Diagnostics.DevToolsOptions()
{
StartupScreenIndex = 1,
});
//Renderer.DrawFps = true;
//Renderer.DrawDirtyRects = Renderer.DrawFps = true;

Expand Down
4 changes: 3 additions & 1 deletion src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Avalonia.Diagnostics
{
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)
{
Expand Down Expand Up @@ -52,6 +53,7 @@ public static IDisposable Open(TopLevel root, DevToolsOptions options)
Width = options.Size.Width,
Height = options.Size.Height,
};
window.SetOptions(options);

window.Closed += DevToolsClosed;
s_open.Add(root, window);
Expand Down
5 changes: 5 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public class DevToolsOptions
/// Gets or sets the initial size of the DevTools window. The default value is 1280x720.
/// </summary>
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public int SelectedTab
get { return _pointerOverElement; }
private set { RaiseAndSetIfChanged(ref _pointerOverElement, value); }
}

private void UpdateConsoleContext(ConsoleContext context)
{
context.root = _root;
Expand Down Expand Up @@ -213,5 +213,12 @@ public void RequestTreeNavigateTo(IControl control, bool isVisualTree)
tree.SelectControl(control);
}
}

public int? StartupScreenIndex { get; private set; } = default;

public void SetOptions(DevToolsOptions options)
{
StartupScreenIndex = options.StartupScreenIndex;
}
}
}
20 changes: 20 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ public MainWindow()
_keySubscription = InputManager.Instance.Process
.OfType<RawKeyEventArgs>()
.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
Expand Down Expand Up @@ -115,5 +132,8 @@ private void RawKeyDown(RawKeyEventArgs e)
}

private void RootClosed(object? sender, EventArgs e) => Close();

public void SetOptions(DevToolsOptions options) =>
(DataContext as MainViewModel)?.SetOptions(options);
}
}

0 comments on commit 6bac166

Please sign in to comment.