Skip to content

Commit

Permalink
make window resize dynamically on font size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Dec 6, 2018
1 parent e3dcbed commit 088920f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/condo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
xmlns:local="clr-namespace:condo"
mc:Ignorable="d"
Title="MainWindow" SizeToContent="WidthAndHeight">
<Grid>
<ScrollViewer Name="scrollViewer" CanContentScroll="true" IsDeferredScrollingEnabled="true" Focusable="False">
<Grid Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer Name="scrollViewer" Grid.Column="0" Grid.Row="0"
CanContentScroll="true" IsDeferredScrollingEnabled="true" Focusable="False">
<local:Screen x:Name="screen" />
</ScrollViewer>
</Grid>
Expand Down
22 changes: 20 additions & 2 deletions src/condo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace condo
{
using System;
using System.ComponentModel;
using System.Security;
using System.Windows;
Expand Down Expand Up @@ -36,7 +37,6 @@ private bool IsOSVersionSupported()
public MainWindow()
{
this.InitializeComponent();
this.Loaded += this.OnLoaded;

// XXX: lazy dark but not painfully bright palette
this.mellowPalette = new XtermPalette();
Expand All @@ -56,8 +56,9 @@ public MainWindow()
this.mellowPalette[13] = new Character.ColorInfo { R = 0xb2, G = 0x94, B = 0xbb };
this.mellowPalette[14] = new Character.ColorInfo { R = 0x8a, G = 0xbe, B = 0xb7 };
this.mellowPalette[15] = new Character.ColorInfo { R = 0xc5, G = 0xc8, B = 0xc6 };

this.screen.Palette = this.mellowPalette;

this.Loaded += this.OnLoaded;
}

private void OnLoaded(object sender, RoutedEventArgs e)
Expand All @@ -74,6 +75,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
return;
}

this.InitializeWindowSizeHandling();
this.console = TerminalManager.Instance.GetOrCreate(0, "wsl.exe");
this.keyHandler = new KeyHandler(this.console);

Expand Down Expand Up @@ -122,6 +124,22 @@ private void OnLoaded(object sender, RoutedEventArgs e)
this.Closing += this.HandleClosing;
}

private double windowFrameWidth, windowFrameHeight;
private void InitializeWindowSizeHandling()
{
this.windowFrameWidth = this.ActualWidth - this.grid.ActualWidth;
this.windowFrameHeight = this.ActualHeight - this.grid.ActualHeight;

this.MinWidth = this.ActualWidth;
this.MinHeight = this.ActualHeight;

this.scrollViewer.SizeChanged += (_, args) =>
{
this.MinWidth = this.windowFrameWidth + args.NewSize.Width;
this.MinHeight = this.windowFrameHeight + args.NewSize.Height;
};
}

private void HandleClosing(object sender, CancelEventArgs e)
{
this.screen.Close();
Expand Down
4 changes: 2 additions & 2 deletions src/condo/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private void ForceFullRedraw()
this.shouldRedraw = 1;
}

#region IScrollInfo
#region IScrollInfo
public bool CanVerticallyScroll { get; set; }
public bool CanHorizontallyScroll { get; set; }

Expand Down Expand Up @@ -465,6 +465,6 @@ public Rect MakeVisible(Visual visual, Rect rectangle)
{
throw new NotImplementedException();
}
#endregion
#endregion
}
}

0 comments on commit 088920f

Please sign in to comment.