-
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?
Conversation
@@ -51,9 +51,32 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | |||
Opacity(static_cast<float>(value) / 100.0f); | |||
}; | |||
|
|||
void SetPadding(double value) | |||
void SetLeftPadding(double value) |
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.
Maybe SetXXXPadding(double value)
functions can be overloaded but idk how to make it work with XAML.
@@ -140,6 +163,47 @@ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Used this enum
just to clarify the intention.
@@ -105,4 +105,35 @@ namespace winrt::Microsoft::Terminal::UI::implementation | |||
|
|||
return maxVal; | |||
} | |||
|
|||
double Converters::PaddingValueFromIndex(const winrt::hstring& paddingString, uint32_t paddingIndex) |
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.
Maybe this should also take an enum
parameter instead of index but this is only called from XAML.
LOG_CAUGHT_EXCEPTION(); | ||
} | ||
|
||
result << values[0] << L", " << values[1] << L", " << values[2] << L", " << values[3]; |
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.
We use fmt
instead of sstream
almost everywhere. This would also allow us to easily round the padding to e.g. 6 digits during formatting, just in case (to avoid 0.3000000000000001
situations).
Something like this:
const auto result = fmt::format(
FMT_COMPILE(L"{:.6f},{:.6f},{:.6f},{:.6f}"),
values[0],
values[1],
values[2],
values[3]
);
return winrt::hstring{ result };
Theoretically you should also have access to fmt::join
so this may work:
const auto result = fmt::format(FMT_COMPILE(L"{:.6f}"), fmt::join(values, L","));
I think the way you made it looks amazing! I'm overall fine with this PR already. However, I was wondering: Couldn't we parse the margin string once, when the ViewModel loads, store it as a member and then expose them as 4 doubles? Your PR introduces the 4 |
If you think it is worth I can change it to the way you described. I know that |
I think it would be better, because it would better contain the changes within this class and avoid adding more dependencies between different parts of the code base. It would also simplify However, I also don't want to force you to spend more time on this, so I've approved it for now. 🙂 |
This definitely needs a review 🙂. I tried to update it according to your suggestions but I ran into some problems so I couldn't make it that simpler. I got rid of the |
This week we've got an internal hackathon so attention will be stretched a little thin. I'll try to take a look soon though (unless someone else gets here first^^). 🙂 |
Ok, no problem for me 🙂. Just for info, I will also be off for a month from this Saturday, so if I can't finish it until Saturday, I won't be able to work on it for a long time. |
This UI is exactly what I had imagined! Thank you |
So, the normal way to do this is to raise a We have this pattern elsewhere in the Profile View Model. You can look at |
Since you have true implementations for the directional padding setters, you may want to use the first pattern (that is: call |
This is silly, but you may also need to send a notification when Padding changes so the View knows that all 4 padding values might have changed. This will make sure that when you click Rest/Clear it properly cascades to the 4 text boxes. |
Padding(to_hstring(value)); | ||
const hstring& padding = _GetNewPadding(PaddingDirection::Left, value); | ||
|
||
Padding(padding); |
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.
Oh, I understand now. This will properly propagate the change notification through to Padding. You may still need to do the other notifications yourself.
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.
That will allow you to turn this into a setter and a getter with normal two-way binding.
@@ -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"); |
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 the ClearPadding
case.
It could probably still be simpler, the |
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.
So sorry for the delay!
@@ -74,7 +77,7 @@ namespace Microsoft.Terminal.Settings.Editor | |||
Boolean ShowMarksAvailable { get; }; | |||
Boolean AutoMarkPromptsAvailable { get; }; | |||
Boolean RepositionCursorWithMouseAvailable { get; }; | |||
|
|||
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.
return winrt::hstring{ result }; | ||
} | ||
|
||
double ProfileViewModel::_GetPaddingValue(PaddingDirection paddingDirection) const |
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.
My only concern is that this pair of functions will mis-handle 1-part and 2-part paddings:
padding 8
should be parsed as 8,8,8,8
; padding 8,4
should be parsed as 8,4,8,4
everything else, I'm totally ready to sign off!
I know you’re unavailable so I’m going to clear the no-activity label! |
Left, Top, Right and Bottom paddings can be set separetely in
Appearance
. I tried to make it as close as possible to one of the suggestions in #9127. I hope it doesn't look that bad.Relevant Issue: #9127