Skip to content

Commit

Permalink
Implement MVVM for the Rendering page (#13391)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request
Implements a `RenderingViewModel` for the Rendering page in the SUI

## PR Checklist
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

## Validation Steps Performed
Rendering page still works
  • Loading branch information
PankajBhojwani authored Jul 8, 2022
1 parent 238b5c2 commit bbc570d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Launch.h"
#include "Interaction.h"
#include "Rendering.h"
#include "RenderingViewModel.h"
#include "Actions.h"
#include "Profiles.h"
#include "GlobalAppearance.h"
Expand Down Expand Up @@ -352,7 +353,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
else if (clickedItemTag == renderingTag)
{
contentFrame().Navigate(xaml_typename<Editor::Rendering>(), winrt::make<RenderingPageNavigationState>(_settingsClone.GlobalSettings()));
contentFrame().Navigate(xaml_typename<Editor::Rendering>(), winrt::make<RenderingViewModel>(_settingsClone.GlobalSettings()));
const auto crumb = winrt::make<Breadcrumb>(box_value(clickedItemTag), RS_(L"Nav_Rendering/Content"), BreadcrumbSubPage::None);
_breadcrumbs.Append(crumb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<DependentUpon>ProfileViewModel.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="RenderingViewModel.h">
<DependentUpon>RenderingViewModel.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="InteractionViewModel.h">
<DependentUpon>InteractionViewModel.idl</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -205,6 +209,10 @@
<DependentUpon>ProfileViewModel.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="RenderingViewModel.cpp">
<DependentUpon>RenderingViewModel.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="InteractionViewModel.cpp">
<DependentUpon>InteractionViewModel.idl</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -287,6 +295,7 @@
<SubType>Code</SubType>
</Midl>
<Midl Include="ProfileViewModel.idl" />
<Midl Include="RenderingViewModel.idl" />
<Midl Include="InteractionViewModel.idl" />
<Midl Include="GlobalAppearanceViewModel.idl" />
<Midl Include="LaunchViewModel.idl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</ItemGroup>
<ItemGroup>
<Midl Include="ProfileViewModel.idl" />
<Midl Include="RenderingViewModel.idl" />
<Midl Include="InteractionViewModel.idl" />
<Midl Include="GlobalAppearanceViewModel.idl" />
<Midl Include="LaunchViewModel.idl" />
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalSettingsEditor/Rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "pch.h"
#include "Rendering.h"
#include "Rendering.g.cpp"
#include "RenderingPageNavigationState.g.cpp"

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

Expand All @@ -17,6 +16,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void Rendering::OnNavigatedTo(const NavigationEventArgs& e)
{
_State = e.Parameter().as<Editor::RenderingPageNavigationState>();
_ViewModel = e.Parameter().as<Editor::RenderingViewModel>();
}
}
13 changes: 2 additions & 11 deletions src/cascadia/TerminalSettingsEditor/Rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,18 @@
#pragma once

#include "Rendering.g.h"
#include "RenderingPageNavigationState.g.h"
#include "Utils.h"

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
struct RenderingPageNavigationState : RenderingPageNavigationStateT<RenderingPageNavigationState>
{
public:
RenderingPageNavigationState(const Model::GlobalAppSettings& settings) :
_Globals{ settings } {}

WINRT_PROPERTY(Model::GlobalAppSettings, Globals, nullptr)
};

struct Rendering : public HasScrollViewer<Rendering>, RenderingT<Rendering>
{
Rendering();

void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e);

WINRT_PROPERTY(Editor::RenderingPageNavigationState, State, nullptr);
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
WINRT_OBSERVABLE_PROPERTY(Editor::RenderingViewModel, ViewModel, _PropertyChangedHandlers, nullptr);
};
}

Expand Down
9 changes: 3 additions & 6 deletions src/cascadia/TerminalSettingsEditor/Rendering.idl
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import "RenderingViewModel.idl";

namespace Microsoft.Terminal.Settings.Editor
{
runtimeclass RenderingPageNavigationState
{
Microsoft.Terminal.Settings.Model.GlobalAppSettings Globals;
};

[default_interface] runtimeclass Rendering : Windows.UI.Xaml.Controls.Page
{
Rendering();
RenderingPageNavigationState State { get; };
RenderingViewModel ViewModel { get; };
}
}
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsEditor/Rendering.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

<!-- Force Full Repaint -->
<local:SettingContainer x:Uid="Globals_ForceFullRepaint">
<ToggleSwitch IsOn="{x:Bind State.Globals.ForceFullRepaintRendering, Mode=TwoWay}"
<ToggleSwitch IsOn="{x:Bind ViewModel.ForceFullRepaintRendering, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>

<!-- Software Rendering -->
<local:SettingContainer x:Uid="Globals_SoftwareRendering">
<ToggleSwitch IsOn="{x:Bind State.Globals.SoftwareRendering, Mode=TwoWay}"
<ToggleSwitch IsOn="{x:Bind ViewModel.SoftwareRendering, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
</StackPanel>
Expand Down
17 changes: 17 additions & 0 deletions src/cascadia/TerminalSettingsEditor/RenderingViewModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "RenderingViewModel.h"
#include "RenderingViewModel.g.cpp"

using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Terminal::Settings::Model;

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
RenderingViewModel::RenderingViewModel(Model::GlobalAppSettings globalSettings) :
_GlobalSettings{ globalSettings }
{
}
}
28 changes: 28 additions & 0 deletions src/cascadia/TerminalSettingsEditor/RenderingViewModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#pragma once

#include "RenderingViewModel.g.h"
#include "ViewModelHelpers.h"
#include "Utils.h"

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
struct RenderingViewModel : RenderingViewModelT<RenderingViewModel>, ViewModelHelper<RenderingViewModel>
{
public:
RenderingViewModel(Model::GlobalAppSettings globalSettings);

PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, ForceFullRepaintRendering);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, SoftwareRendering);

private:
Model::GlobalAppSettings _GlobalSettings;
};
};

namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
{
BASIC_FACTORY(RenderingViewModel);
}
17 changes: 17 additions & 0 deletions src/cascadia/TerminalSettingsEditor/RenderingViewModel.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import "EnumEntry.idl";

#include "ViewModelHelpers.idl.h"

namespace Microsoft.Terminal.Settings.Editor
{
runtimeclass RenderingViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
RenderingViewModel(Microsoft.Terminal.Settings.Model.GlobalAppSettings globalSettings);

PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, ForceFullRepaintRendering);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, SoftwareRendering);
}
}

0 comments on commit bbc570d

Please sign in to comment.