Skip to content
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

Allow editing font axes in the Settings UI #16104

Merged
merged 31 commits into from
Feb 29, 2024

Conversation

PankajBhojwani
Copy link
Contributor

@PankajBhojwani PankajBhojwani commented Oct 5, 2023

Summary of the Pull Request

Allow editing of font features and axes in the SUI to get the UI closer towards JSON parity

The allowed font axes are obtained directly from the currently selected font, and their display names are presented to the user in the user's current locale (if it exists). Otherwise, we just display the axis tag to the user.

References and Relevant Issues

#10000

Validation Steps Performed

  • Font Axes can be added/changed/removed from the Settings UI

image
image

PR Checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated
    • If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated (if necessary)

@github-actions

This comment has been minimized.

@PankajBhojwani
Copy link
Contributor Author

Some explanation before you review:

There is no way for xaml to bind to an IObservableMap in C++ (see more here). So, we make an IObservableVector of a custom struct, which is effectively just a wrapper around KeyValuePairs.

This means that we need to manually update the underlying map when the observable vector is changed via the UI, and whenever a new key value pair is added/removed we also need to manually propagate those changes to the map.

@DHowett

This comment was marked as resolved.

@PankajBhojwani

This comment was marked as resolved.

@github-actions

This comment has been minimized.

src/cascadia/TerminalSettingsEditor/Appearances.xaml Outdated Show resolved Hide resolved
Comment on lines 33 to 42
// We cannot simply copy the font axes and features with `fontInfo->_FontAxes = source->_FontAxes;`
// since that'll just create a reference; we have to manually copy the values.
if (source->_FontAxes)
{
fontInfo->_FontAxes = winrt::single_threaded_map<winrt::hstring, float>();
for (const auto keyValuePair : source->_FontAxes.value())
{
fontInfo->_FontAxes.value().Insert(keyValuePair.Key(), keyValuePair.Value());
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes the MTSM_FONT_SETTINGS macro call above pointless for FontAxes, but I'd still rather not remove FontAxes from that macro since it is relevant in other places

@PankajBhojwani

This comment was marked as resolved.

@github-actions

This comment has been minimized.

@zadjii-msft
Copy link
Member

Okay so I don't know how extra this would be, or what it would even look like, but: is there any way we could add like, descriptions to the axes as you add them? Little old me doesn't know enough about fonts to know what slnt means. Though, I suppose "Used to vary between upright and slanted text" is just about as helpful as "Slant"

@PankajBhojwani PankajBhojwani changed the title Allow editing font features and axes in the Settings UI Allow editing font axes in the Settings UI Jan 25, 2024
@PankajBhojwani PankajBhojwani marked this pull request as ready for review January 25, 2024 23:15

This comment has been minimized.

Comment on lines 172 to 180
for (const auto tagAndName : _tagToNameMap)
{
if (i == _AxisIndex)
{
AxisKey(tagAndName.Key());
break;
}
++i;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the manual index to key mapping we have to do because xaml struggles with combo box bindings

Comment on lines +604 to +614
if (!Appearance().AreFontAxesAvailable())
{
// if the previous font had available font axes and the expander was expanded,
// at this point the expander would be set to disabled so manually collapse it
FontAxesContainer().SetExpanded(false);
FontAxesContainer().HelpText(RS_(L"Profile_FontAxesUnavailable/Text"));
}
else
{
FontAxesContainer().HelpText(RS_(L"Profile_FontAxesAvailable/Text"));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was something extra I added - we could just set the entire expander to invisible if the font does not support font axes, but I figured it would be more consistent for the user if we still show the expander and just set it to disabled instead. If we feel like this is more trouble than its worth I'm happy to switch to the invisible implementation instead.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

This is a pile of comments but I don't think I have any blocking concerns

src/cascadia/TerminalSettingsEditor/Appearances.idl Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/Appearances.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/Appearances.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/Appearances.cpp Outdated Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

@zadjii-msft zadjii-msft added this to the Terminal v1.21 milestone Feb 27, 2024
@PankajBhojwani PankajBhojwani added the AutoMerge Marked for automatic merge by the bot when requirements are met label Feb 29, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit 99042d2 into main Feb 29, 2024
20 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the dev/pabhoj/sui_font_parity branch February 29, 2024 18:39
microsoft-github-policy-service bot pushed a commit that referenced this pull request Feb 29, 2024
## Summary of the Pull Request
**Targets #16104** 

Same as #16104, but for font features

## References and Relevant Issues
#10000 

## Validation Steps Performed
Font features are detected correctly and can be set in the settings UI

![image](https://github.com/microsoft/terminal/assets/26824113/054c30fa-c584-4b71-872d-d956526c373b)

![image](https://github.com/microsoft/terminal/assets/26824113/484a20eb-abe9-478c-99cf-f63939ab4c5b)

## PR Checklist
- [ ] Closes #xxx
- [ ] Tests added/passed
- [ ] Documentation updated
- If checked, please file a pull request on [our docs
repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
- [ ] Schema updated (if necessary)
zadjii-msft pushed a commit that referenced this pull request Mar 1, 2024
Make sure the delete button's `Tag` updates when the selected
axis/feature changes, so that the correct key value gets propagated when
the delete button is clicked.

Refs #16678 #16104 

## Validation Steps Performed
1. Add a new feature/axis
2. Change the key
3. Click the delete button
4. Delete button works
github-merge-queue bot pushed a commit that referenced this pull request May 1, 2024
Due to #16821 everything about #16104 broke. This PR rights the wrongs
by rewriting all the `Font`-based code to not use `Font` at all.
Instead we split the font spec once into font families, do a lot of
complex logic to split font axes/features into used and unused ones
and construct all the UI elements. So. much. boilerplate. code.

Closes #16943

## Validation Steps Performed
There are more edge cases than I can list here... Some ideas:
* Edit the settings.json with invalid axis/feature keys ✅
* ...out of range values ✅
* Settings UI reloads when the settings.json changes ✅
* Adding axes/features works ✅
* Removing axes/features works ✅
* Resetting axes/features works ✅
* Axes/features apply in the renderer when saving ✅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants