Skip to content

Commit

Permalink
Upgrade to Microsoft.UI.Xaml 2.2 (#3027)
Browse files Browse the repository at this point in the history
* We had to move to the final API:
   * Items -> TabItems
   * Items.VectorChanged -> TabItemsChanged
   * TabClose -> TabCloseRequested
   * TabViewItem.Icon -> TabViewItem.IconSource
* TabRowControl has been converted to a ContentPresenter, which
  simplifies its logic a little bit.
* TerminalPage now differentiates MUX and WUX a little better
* Because of the change from Icon to IconSource in TabViewItem,
  Utils::GetColoredIcon needed to be augmented to support MUX IconSources.
  It was still necessary to use for WUX, so it's been templatized.
* I moved us from WUX SplitButton to MUX SplitButton and brought the
  style in line with the one typically provided by TabView.
* Some of our local controls have had their backgrounds removed so
  they're more amenable to being placed on other surfaces.
* I'm suppressing the TabView's padding.
* I removed a number of apparently dead methods from App.
* I've simplified the dragbar's sizing logic and eventing.
* The winmd harvester needed to be taught to not try to copy winmds for
  framework packages.
* We now only initialize the terminal once we know the size

Closes #1896.
Closes #444.
Closes #857.
Closes #771.
Closes #760.
  • Loading branch information
DHowett authored Oct 15, 2019
1 parent 5d17557 commit df26c67
Show file tree
Hide file tree
Showing 27 changed files with 238 additions and 172 deletions.
2 changes: 1 addition & 1 deletion build/rules/GenerateSxsManifestsFromWinmds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Target Name="_ConsoleMapWinmdsToManifestFiles" DependsOnTargets="ResolveAssemblyReferences">
<ItemGroup>
<!-- For each non-system .winmd file in References, generate a .manifest in IntDir for it. -->
<_ConsoleWinmdManifest Include="@(ReferencePath->'$(IntDir)\%(FileName).manifest')" Condition="'%(ReferencePath.IsSystemReference)' != 'true' and '%(ReferencePath.WinMDFile)' == 'true' and '%(ReferencePath.ReferenceSourceTarget)' == 'ResolveAssemblyReference'">
<_ConsoleWinmdManifest Include="@(ReferencePath->'$(IntDir)\%(FileName).manifest')" Condition="'%(ReferencePath.IsSystemReference)' != 'true' and '%(ReferencePath.WinMDFile)' == 'true' and '%(ReferencePath.ReferenceSourceTarget)' == 'ResolveAssemblyReference' and '%(ReferencePath.Implementation)' != ''">
<WinMDPath>%(ReferencePath.FullPath)</WinMDPath>
<Implementation>%(ReferencePath.Implementation)</Implementation>
</_ConsoleWinmdManifest>
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/CascadiaPackage/CascadiaPackage.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,13 @@
</ItemGroup>
</Target>

<!-- This is required to get the package dependency in the AppXManifest. -->
<Import Project="..\..\..\packages\Microsoft.UI.Xaml.2.2.190917002\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('..\..\..\packages\Microsoft.UI.Xaml.2.2.190917002\build\native\Microsoft.UI.Xaml.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\Microsoft.UI.Xaml.2.2.190917002\build\native\Microsoft.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.UI.Xaml.2.2.190917002\build\native\Microsoft.UI.Xaml.targets'))" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@
<!-- From Microsoft.UI.Xaml.targets -->
<Native-Platform Condition="'$(Platform)' == 'Win32'">x86</Native-Platform>
<Native-Platform Condition="'$(Platform)' != 'Win32'">$(Platform)</Native-Platform>
<_MUXBinRoot>&quot;$(OpenConsoleDir)packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\runtimes\win10-$(Native-Platform)\native\&quot;</_MUXBinRoot>
<_MUXBinRoot>&quot;$(OpenConsoleDir)packages\Microsoft.UI.Xaml.2.2.190917002\runtimes\win10-$(Native-Platform)\native\&quot;</_MUXBinRoot>
</PropertyGroup>

<!-- We actually can just straight up reference MUX here, it's fine -->
<Import Project="..\..\..\packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('..\..\..\packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\build\native\Microsoft.UI.Xaml.targets')" />
<Import Project="..\..\..\packages\Microsoft.UI.Xaml.2.2.190917002\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('..\..\..\packages\Microsoft.UI.Xaml.2.2.190917002\build\native\Microsoft.UI.Xaml.targets')" />
<Import Project="..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets" Condition="Exists('..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets')" />

<!-- This project will generate individual sxs manifests for each of our winrt libraries -->
Expand Down
10 changes: 0 additions & 10 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,11 @@ namespace winrt::TerminalApp::implementation
void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);

[[nodiscard]] HRESULT _TryLoadSettings() noexcept;
void _LoadSettings();
void _RegisterSettingsChange();
fire_and_forget _DispatchReloadSettings();
void _ReloadSettings();

void _ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme);

static Windows::UI::Xaml::Controls::IconElement _GetIconFromProfile(const ::TerminalApp::Profile& profile);

winrt::Microsoft::Terminal::TerminalControl::TermControl _GetFocusedControl();

void _CopyToClipboardHandler(const IInspectable& sender, const winrt::Microsoft::Terminal::TerminalControl::CopyToClipboardEventArgs& copiedData);
void _PasteFromClipboardHandler(const IInspectable& sender, const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs& eventArgs);

static void _SetAcceleratorForMenuItem(Windows::UI::Xaml::Controls::MenuFlyoutItem& menuItem, const winrt::Microsoft::Terminal::Settings::KeyChord& keyChord);
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,24 @@ the MIT License. See LICENSE in the project root for license information. -->
is unfortunately static. -->
<SolidColorBrush x:Name="ErrorTextBrush" Color="{ThemeResource SystemErrorTextColor}" />

<!-- Suppress all padding around the tabs. The TabView looks far better like this. -->
<Thickness x:Key="TabViewHeaderPadding">0,0,0,0</Thickness>

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<!-- Define resources for Dark mode here -->
<!-- The TabViewBackground is used on a control (DragBar, TitleBarControl) whose color is propagated to GDI.
The default background is black or white with an alpha component, as it's intended to be layered on top of
another control. Unfortunately, GDI cannot handle this: we need to either render the XAML to a surface and
sample the pixels out of it, or premultiply the alpha into the background. For obvious reasons, we've chosen
the latter. -->
<SolidColorBrush x:Key="TabViewBackground" Color="#FF333333" />
</ResourceDictionary>

<ResourceDictionary x:Key="Light">
<!-- Define resources for Light mode here -->
<!-- See note about premultiplication above. -->
<SolidColorBrush x:Key="TabViewBackground" Color="#FFCCCCCC" />
</ResourceDictionary>

</ResourceDictionary.ThemeDictionaries>
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/MinMaxCloseControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ the MIT License. See LICENSE in the project root for license information. -->
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource SystemChromeLowColor}"
Background="Transparent"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Orientation="Horizontal"
Expand Down
12 changes: 7 additions & 5 deletions src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ using namespace winrt::Windows::UI::Core;
using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::Microsoft::Terminal::TerminalControl;

static const int TabViewFontSize = 12;
namespace winrt
{
namespace MUX = Microsoft::UI::Xaml;
}

Tab::Tab(const GUID& profile, const TermControl& control)
{
Expand All @@ -25,8 +28,7 @@ Tab::Tab(const GUID& profile, const TermControl& control)

void Tab::_MakeTabViewItem()
{
_tabViewItem = ::winrt::Microsoft::UI::Xaml::Controls::TabViewItem{};
_tabViewItem.FontSize(TabViewFontSize);
_tabViewItem = ::winrt::MUX::Controls::TabViewItem{};
}

UIElement Tab::GetRootElement()
Expand All @@ -50,7 +52,7 @@ TermControl Tab::GetFocusedTerminalControl()
return _rootPane->GetFocusedTerminalControl();
}

winrt::Microsoft::UI::Xaml::Controls::TabViewItem Tab::GetTabViewItem()
winrt::MUX::Controls::TabViewItem Tab::GetTabViewItem()
{
return _tabViewItem;
}
Expand Down Expand Up @@ -154,7 +156,7 @@ void Tab::UpdateIcon(const winrt::hstring iconPath)
_lastIconPath = iconPath;

_tabViewItem.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [this]() {
_tabViewItem.Icon(GetColoredIcon(_lastIconPath));
_tabViewItem.IconSource(GetColoredIcon<winrt::MUX::Controls::IconSource>(_lastIconPath));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TabRowControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "TabRowControl.g.cpp"

using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace winrt::Microsoft::UI::Xaml;

namespace winrt::TerminalApp::implementation
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TabRowControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace winrt::TerminalApp::implementation
{
TabRowControl();

void OnNewTabButtonClick(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Controls::SplitButtonClickEventArgs const& args);
void OnNewTabButtonClick(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Controls::SplitButtonClickEventArgs const& args);
};
}

Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalApp/TabRowControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

namespace TerminalApp
{
[default_interface] runtimeclass TabRowControl : Windows.UI.Xaml.Controls.Grid
[default_interface] runtimeclass TabRowControl : Windows.UI.Xaml.Controls.ContentPresenter
{
TabRowControl();
Windows.UI.Xaml.Controls.SplitButton NewTabButton { get; };
Microsoft.UI.Xaml.Controls.TabView TabView { get; };
}
}
65 changes: 52 additions & 13 deletions src/cascadia/TerminalApp/TabRowControl.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
the MIT License. See LICENSE in the project root for license information. -->
<Grid
<ContentPresenter
x:Class="TerminalApp.TabRowControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -10,22 +10,61 @@ the MIT License. See LICENSE in the project root for license information. -->
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<mux:TabView x:Name="TabView" VerticalAlignment="Bottom">
<mux:TabView x:Name="TabView"
VerticalAlignment="Bottom"
HorizontalContentAlignment="Stretch"
IsAddTabButtonVisible="false"
TabWidthMode="SizeToContent"
CanReorderTabs="False"
CanDragTabs="False"
AllowDropTabs="False">

<mux:TabView.RightCustomContent>
<SplitButton
<mux:TabView.TabStripFooter>
<mux:SplitButton
x:Name="NewTabButton"
Click="OnNewTabButtonClick"
Background="{ThemeResource SystemChromeLowColor}"
VerticalAlignment="Stretch"
HorizontalAlignment="Left">
<Viewbox MaxHeight="13"
MaxWidth="13">
<SymbolIcon Symbol="Add" />
</Viewbox>
</SplitButton>
</mux:TabView.RightCustomContent>
HorizontalAlignment="Left"
Content="&#xE710;"
UseLayoutRounding="true"
FontFamily="Segoe MDL2 Assets"
FontWeight="SemiLight"
FontSize="12">
<!-- U+E710 is the fancy plus icon. -->
<mux:SplitButton.Resources>
<!-- Override the SplitButton* resources to match the tab view's button's styles. -->
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<StaticResource x:Key="SplitButtonBackground" ResourceKey="TabViewItemHeaderBackground" />
<StaticResource x:Key="SplitButtonForeground" ResourceKey="SystemControlBackgroundBaseMediumBrush" />
<StaticResource x:Key="SplitButtonBackgroundPressed" ResourceKey="TabViewItemHeaderBackgroundPressed" />
<StaticResource x:Key="SplitButtonForegroundPressed" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
<StaticResource x:Key="SplitButtonBackgroundPointerOver" ResourceKey="TabViewItemHeaderBackgroundPointerOver" />
<StaticResource x:Key="SplitButtonForegroundPointerOver" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<StaticResource x:Key="SplitButtonBackground" ResourceKey="TabViewItemHeaderBackground" />
<StaticResource x:Key="SplitButtonForeground" ResourceKey="SystemControlBackgroundBaseMediumBrush" />
<StaticResource x:Key="SplitButtonBackgroundPressed" ResourceKey="TabViewItemHeaderBackgroundPressed" />
<StaticResource x:Key="SplitButtonForegroundPressed" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
<StaticResource x:Key="SplitButtonBackgroundPointerOver" ResourceKey="TabViewItemHeaderBackgroundPointerOver" />
<StaticResource x:Key="SplitButtonForegroundPointerOver" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<StaticResource x:Key="SplitButtonBackground" ResourceKey="TabViewItemHeaderBackground" />
<StaticResource x:Key="SplitButtonForeground" ResourceKey="SystemControlBackgroundBaseMediumBrush" />
<StaticResource x:Key="SplitButtonBackgroundPressed" ResourceKey="TabViewItemHeaderBackgroundPressed" />
<StaticResource x:Key="SplitButtonForegroundPressed" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
<StaticResource x:Key="SplitButtonBackgroundPointerOver" ResourceKey="TabViewItemHeaderBackgroundPointerOver" />
<StaticResource x:Key="SplitButtonForegroundPointerOver" ResourceKey="SystemControlBackgroundBaseMediumHighBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</mux:SplitButton.Resources>
</mux:SplitButton>
</mux:TabView.TabStripFooter>

</mux:TabView>

</Grid>
</ContentPresenter>
Loading

0 comments on commit df26c67

Please sign in to comment.