-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
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.
I know you’re unavailable so I’m going to clear the no-activity label! |
@DHowett if @nukoseer is unavailable, should one of the rest of us tidy up your concern in #17909 (comment) to get this merged? |
Actually, I have updated this but there was no review :) |
Ah my bad, that's what I get for reading review threads at 6am. I'll stick this back in @DHowett's court then |
OH NO!! I missed the notification about this update! |
The code in #17909 was not completely right for padding values with fewer than four components, and it was doing some fragile string math (that is: if you wanted to change the third element in the padding it would parse out the whole thing, edit the third value, and then format it again). This pull request moves the control's padding parser into cppwinrt_utils (for lack of a better place) and makes the settings UI use it to parse the padding out into a `Thickness` as early as possible. Then, the controls operate directly on the Thickness' members rather than parsing the padding string again. To handle two-way serialization properly, we also required a function that converts a thickness back into a reduced string representation (i.e. when all four values are N, it will return "N"). As a bonus, this pull request also: - removes another use of `std::getline` - fixes an issue where resetting the padding would change it (infinitesimally) and cause it to be set again - adds a readout of the current padding value in the expander itself
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