Skip to content

Represent font face as a combo box in SUI - #9275

Merged
13 commits merged into
mainfrom
dev/cazamor/sui/font-face-combobox
Mar 8, 2021
Merged

13 commits merged into
mainfrom
dev/cazamor/sui/font-face-combobox

Conversation

@carlos-zamora

@carlos-zamora Carlos Zamora (carlos-zamora) commented Feb 24, 2021 •

Copy link
Copy Markdown

Summary of the Pull Request

This replaces the Profiles > Font Face text box with a combo box.

References

#6800 - Settings UI Epic

Detailed Description of the Pull Request / Additional comments

  • Enumerating the fonts
    • This doc was the main reference used to enumerate the fonts. It was mildly adapted to use WinRT instead of WRL.
  • Updating the UI
    • Similar to other combo box settings, Profiles keeps a reference to the current value. We use that as a way to update the settings model. If an invalid value is used, we fallback to Cascadia Mono.
    • A checkbox was added to let the user select from all of the installed fonts, or just the monospace ones.

Demo

Font Face Combo Box Demo

@carlos-zamora

This comment has been minimized.

@zadjii-msft

Copy link
Copy Markdown
Member

With this proposed approach, if the user has a monospaced font selected, maybe I could just set the combobox as "custom" or something? Or create an item for the non-monospaced font? (this should be a rare case)

IMO, if the user has Papyrus in their settings, then we should add that one in the combobox, along with the other monospace fonts. They can see clearly that Papyrus is selected, and they can keep that selection, or pick a sane, monospace one.

@zadjii-msft Mike Griese (zadjii-msft) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking over the memory leak. I think Michael Niksa (@miniksa) should review the "collect all the fonts" bit, since he's the dwrite expert.

<TextBox Text="{x:Bind State.Profile.FontFace, Mode=TwoWay}"
Style="{StaticResource TextBoxSettingStyle}"/>
<ComboBox ItemsSource="{x:Bind FontList, Mode=OneWay}"
SelectedItem="{x:Bind CurrentFontFace, Mode=TwoWay}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if CurrentFontFace is something that's not an installed font? Like if I set my fontFace to asdf, what happens then?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there's a two fold approach (it's more developed in the upcoming commit):

  1. We have 2 lists: all installed fonts and monospace fonts. If we find that the current font face is not in the list of monospace fonts, assume that it's in the list of all fonts. So we update the UI to force the user to look at all of the installed fonts.
  2. If the user still selected a font that doesn't exist, CurrentFontFace() returns Cascadia Mono. This has to be valid since it is shipped with Windows Terminal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather there be an error or warning instead of a whole "it automatically edits the setting if I look at the settings page" :/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I think we might be ok, but let me run through it out loud to double check.

  • JSON - invalid font face in settings.json --> show "Cascadia Mono" in SUI:
    warning dialog
  • SUI - limited to autogenerated list

So the only way to get an invalid font is if you modified the JSON. That said, if you then go to SUI, the change won't go into effect until you click on the combo box.

Maybe the behavior should be that we add another "font" called "Invalid Font"? But I feel like this case is fairly rare, and this is more of a request for input validation in SUI. So I'm inclined to say we should punt on this one or throw it in the backlog? Whatcha think?

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Feb 26, 2021
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Feb 26, 2021
@carlos-zamora

Copy link
Copy Markdown
Author

@msftbot make sure Michael Niksa (@miniksa) signs off

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Feb 26, 2021
@ghost

Copy link
Copy Markdown

Hello Carlos Zamora (@carlos-zamora)!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

Comment on lines +858 to +863
<data name="Profile_FontFaceShowAllFonts.Content" xml:space="preserve">
<value>Show all fonts</value>
</data>
<data name="Profile_FontFaceShowAllFonts.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>If checked, show all installed fonts in the list above. Otherwise, only show the list of monospace fonts.</value>
</data>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kayla Cinnamon (@cinnamon-msft) (or others) feel free to suggest changes for this part.

@DHowett Dustin L. Howett (DHowett) removed the AutoMerge Marked for automatic merge by the bot when requirements are met label Feb 26, 2021
</DataTemplate>

<DataTemplate x:DataType="x:String" x:Key="FontFaceComboBoxItemTemplate">
<TextBlock Text="{x:Bind}" FontFamily="{x:Bind}"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you double check that this is fine receiving the localized name on other languages? I know you're keeping the localized name in the list for sorting and presentation.... but I have no idea what code TextBlock is calling to turn that localized string into its display font. I just want to make sure you double checked this on at least one non-English scenario.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to test this, but I have a feeling that this is definitely going to fail. Working on a solution rn.

@miniksa Michael Niksa (miniksa) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good with the DWrite stuff. A few odds and ends comments, but I'll let the other blocks be the definitive ones.

@github-actions

This comment has been minimized.

@mdtauk

Copy link
Copy Markdown

If it were an Editable ComboBox, that makes it the best of both worlds.

You could also present a text warning, if the FontName read from the JSON, does not match a font available to use.

@carlos-zamora

Copy link
Copy Markdown
Author

If it were an Editable ComboBox, that makes it the best of both worlds.

You could also present a text warning, if the FontName read from the JSON, does not match a font available to use.

My concern with it being editable is that you could choose a font that doesn't exist. Yeah, we could present a warning, but if the list fully encompasses the accepted fonts, I think this is fine?

That said, making it editable would be "the cherry on top", so I'm gonna open a follow-up task for somebody to do that (most of the work would be creating the warning and validation after this PR).

@zadjii-msft Mike Griese (zadjii-msft) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhg I feel conflicted - these feel like nits, but there's enough that I'm gonna block.

Generally looks good to me though

// generate the font list, if we don't have one
if (!_State.Profile().CompleteFontList() || !_State.Profile().MonospaceFontList())
{
ProfileViewModel::UpdateFontList();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this here, or should we instead have the font lists initialized in the ProfileViewModel ctor?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually wait this is done in the ctor. So is this ever hit?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have this here in case loading the fonts fails for some reason. The one in the constructor is hit when the Settings UI is opened, but then we check if we have it when we navigate to the profiles page.

_ShowAllFonts = value;
_NotifyChanges(L"ShowAllFonts");
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an aside: almost starting to feel like PVM warrants its own file

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. I think this'll be a part of #9207.

monospaceFontList.emplace_back(fontEntry);
}
}
CATCH_LOG();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't gonna log 100 warnings as we iterate over all the fonts, is it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched from .as to .try_as. So I think the only one we are really logging here is GetFirstMatchingFont. I think that's fair because we'd want to know which fonts we can't get the IDWriteFont version of?

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 4, 2021
@zadjii-msft Mike Griese (zadjii-msft) removed their assignment Mar 4, 2021
@zadjii-msft Mike Griese (zadjii-msft) added Area-SettingsUI Anything specific to the SUI Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Mar 4, 2021
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 4, 2021
@zadjii-msft Mike Griese (zadjii-msft) added the AutoMerge Marked for automatic merge by the bot when requirements are met label Mar 8, 2021
@ghost

Copy link
Copy Markdown

Hello Mike Griese (@zadjii-msft)!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
ghost merged commit 87fa526 into main Mar 8, 2021
@ghost
ghost deleted the dev/cazamor/sui/font-face-combobox branch March 8, 2021 16:45
@ghost

Copy link
Copy Markdown

🎉Windows Terminal Preview v1.8.1032.0 has been released which incorporates this pull request.:tada:

Handy links:

</data>

There are any number of "resheader" rows that contain simple

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespaces...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Turns out that Visual Studio will automatically add those trailing spaces to a .resw file pretty much always. That's why every other commit in this repo removes them, then adds them back, depending on what editor the author is using. It really doesn't matter in the end though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(thanks for the review though? :P)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-SettingsUI Anything specific to the SUI AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants