-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add separate padding settings for left, top, right and bottom #17909
base: main
Are you sure you want to change the base?
Changes from all commits
0eb788c
fa2eae3
af5a194
93c234c
483f92b
dc55cee
4341be1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | |
{ | ||
_NotifyChanges(L"HideIcon"); | ||
} | ||
else if (viewModelProperty == L"Padding") | ||
{ | ||
_NotifyChanges(L"LeftPadding", L"TopPadding", L"RightPadding", L"BottomPadding"); | ||
} | ||
}); | ||
|
||
// Do the same for the starting directory | ||
|
@@ -98,6 +102,138 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | |
_defaultAppearanceViewModel.IsDefault(true); | ||
} | ||
|
||
void ProfileViewModel::LeftPadding(double value) noexcept | ||
{ | ||
const hstring& padding = _GetNewPadding(PaddingDirection::Left, value); | ||
|
||
Padding(padding); | ||
} | ||
|
||
double ProfileViewModel::LeftPadding() const noexcept | ||
{ | ||
return _GetPaddingValue(PaddingDirection::Left); | ||
} | ||
|
||
void ProfileViewModel::TopPadding(double value) noexcept | ||
{ | ||
const hstring& padding = _GetNewPadding(PaddingDirection::Top, value); | ||
|
||
Padding(padding); | ||
} | ||
|
||
double ProfileViewModel::TopPadding() const noexcept | ||
{ | ||
return _GetPaddingValue(PaddingDirection::Top); | ||
} | ||
|
||
void ProfileViewModel::RightPadding(double value) noexcept | ||
{ | ||
const hstring& padding = _GetNewPadding(PaddingDirection::Right, value); | ||
|
||
Padding(padding); | ||
} | ||
|
||
double ProfileViewModel::RightPadding() const noexcept | ||
{ | ||
return _GetPaddingValue(PaddingDirection::Right); | ||
} | ||
|
||
void ProfileViewModel::BottomPadding(double value) noexcept | ||
{ | ||
const hstring& padding = _GetNewPadding(PaddingDirection::Bottom, value); | ||
|
||
Padding(padding); | ||
} | ||
|
||
double ProfileViewModel::BottomPadding() const noexcept | ||
{ | ||
return _GetPaddingValue(PaddingDirection::Bottom); | ||
} | ||
|
||
winrt::hstring ProfileViewModel::_GetNewPadding(PaddingDirection paddingDirection, double newPaddingValue) const | ||
{ | ||
std::array<double, 4> values{}; | ||
std::wstring_view remaining{ Padding() }; | ||
uint32_t paddingIndex = static_cast<uint32_t>(paddingDirection); | ||
|
||
try | ||
{ | ||
for (uint32_t index = 0; !remaining.empty() && index < values.size(); ++index) | ||
{ | ||
const std::wstring token{ til::prefix_split(remaining, L',') }; | ||
auto curVal = std::stod(token); | ||
|
||
if (paddingIndex == index) | ||
{ | ||
curVal = newPaddingValue; | ||
} | ||
|
||
values[index] = curVal; | ||
} | ||
} | ||
catch (...) | ||
{ | ||
values.fill(0); | ||
LOG_CAUGHT_EXCEPTION(); | ||
} | ||
|
||
const auto result = fmt::format(FMT_COMPILE(L"{:.6f}"), fmt::join(values, L",")); | ||
|
||
return winrt::hstring{ result }; | ||
} | ||
|
||
double ProfileViewModel::_GetPaddingValue(PaddingDirection paddingDirection) const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My only concern is that this pair of functions will mis-handle 1-part and 2-part paddings: padding everything else, I'm totally ready to sign off! |
||
{ | ||
std::wstring_view remaining{ Padding() }; | ||
uint32_t paddingIndex = static_cast<uint32_t>(paddingDirection); | ||
std::array<double, 4> paddingValues{}; | ||
double paddingValue = 0.; | ||
uint32_t index = 0; | ||
|
||
try | ||
{ | ||
for (index = 0; !remaining.empty() && index < paddingValues.size(); ++index) | ||
{ | ||
const std::wstring token{ til::prefix_split(remaining, L',') }; | ||
auto curVal = std::stod(token); | ||
|
||
paddingValues[index] = curVal; | ||
} | ||
} | ||
catch (...) | ||
{ | ||
paddingValue = 0.; | ||
LOG_CAUGHT_EXCEPTION(); | ||
} | ||
|
||
// Padding: 8 | ||
if (index == 1) | ||
{ | ||
paddingValue = paddingValues[0]; | ||
} | ||
// Padding: 8, 4 | ||
else if (index == 2) | ||
{ | ||
if (paddingDirection == PaddingDirection::Left || | ||
paddingDirection == PaddingDirection::Right) | ||
{ | ||
paddingValue = paddingValues[0]; | ||
} | ||
else if (paddingDirection == PaddingDirection::Top || | ||
paddingDirection == PaddingDirection::Bottom) | ||
{ | ||
paddingValue = paddingValues[1]; | ||
} | ||
} | ||
// Padding: 8, 4, 8, 4 | ||
else | ||
{ | ||
paddingValue = paddingValues[paddingIndex]; | ||
} | ||
|
||
return paddingValue; | ||
} | ||
|
||
Model::TerminalSettings ProfileViewModel::TermSettings() const | ||
{ | ||
return Model::TerminalSettings::CreateForPreview(_appSettings, _profile); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,10 +51,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | |
Opacity(static_cast<float>(value) / 100.0f); | ||
}; | ||
|
||
void SetPadding(double value) | ||
{ | ||
Padding(to_hstring(value)); | ||
} | ||
void LeftPadding(double value) noexcept; | ||
double LeftPadding() const noexcept; | ||
void TopPadding(double value) noexcept; | ||
double TopPadding() const noexcept; | ||
void RightPadding(double value) noexcept; | ||
double RightPadding() const noexcept; | ||
void BottomPadding(double value) noexcept; | ||
double BottomPadding() const noexcept; | ||
|
||
winrt::hstring EvaluatedIcon() const | ||
{ | ||
|
@@ -140,6 +144,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | |
|
||
Model::CascadiaSettings _appSettings; | ||
Editor::AppearanceViewModel _unfocusedAppearanceViewModel; | ||
|
||
enum class PaddingDirection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used this |
||
{ | ||
Left = 0, | ||
Top = 1, | ||
Right = 2, | ||
Bottom = 3 | ||
}; | ||
|
||
winrt::hstring _GetNewPadding(PaddingDirection paddingDirection, double newPaddingValue) const; | ||
double _GetPaddingValue(PaddingDirection paddingDirection) const; | ||
}; | ||
|
||
struct DeleteProfileEventArgs : | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the directional padding setters
Padding(padding)
will call_notifyChanges(L "Padding")
and_notifyChanges(L "HasPadding")
. If I call_notifyChanges
for all directional paddings here, it works, including theClearPadding
case.