Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DevTools): Startup Screen #6074

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
{
StartupScreen = 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 number where the DevTools window will be displayed.
/// </summary>
public int? StartupScreen { get; set; }
workgroupengineering marked this conversation as resolved.
Show resolved Hide resolved
}
}
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.StartupScreen;
}
}
}
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 < 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);
}
}