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

Implement #1949 Background Image Align (as one setting) #1959

Conversation

trigger-segfault
Copy link
Contributor

@trigger-segfault trigger-segfault commented Jul 13, 2019

Summary of the Pull Request

Implement #1949: profiles.json has been given a setting for background images labeled as shown below, with the following valid values. This allows background images to be anchored to different corners/sides of the console to fit that background image's intended use-case and focus.

"backgroundImageAlignment": "center" | "left" | "top" | "right" | "bottom"
                   | "topLeft" | "topRight" | "bottomLeft" | "bottomRight"

When left, top, right, or bottom is specified, the other axis is implied to be centered, as that is the default behavior. I went in favor of labeling the default value as center instead of none as "none" does not clearly list the alignment behavior.

Alternative Setting

The branch dev/trigger/background-image-align-two-settings implements the exact same functionality, but by splitting the profiles.json setting into separate horizontal and vertical settings. I am happy to submit it as a PR if the two-setting approach is preferred.

References

There seems to be no other issues or pull requests relevant to background image alignment.

PR Checklist

Detailed Description of the Pull Request / Additional comments

The Profile class defines methods for parsing and serializing the combined HorizontalAlignment and VerticalAlignment enums to and from JSON. An std::tuple<HorizontalAlignment, VerticalAlignment> field _backgroundImageAlignment has been added for storing the profile setting in one place, as it logically makes sense that both alignments to be in use together.

TerminalSettings and IControlSettings have been given BackgroundImageHorizontalAlignment and BackgroundImageVerticalAlignment properties. The combination of std::tuple<HorizontalAlignment, VerticalAlignment> is gone once we leave the Profile class. Combining the two enums is only relevant to how they are stored in profiles.json. TerminalSettings defines the default values of both alignment properties as Center.

The TermControl class changes the image setup in TermControl::_InitializeBackgroundBrush() to assign the _bgImageLayer's (background image control's) alignments to that of the specified alignment settings. The alignments assignments have also been moved from within the image source assignment block, to the bottom of the additional images settings definitions (Stretch and Opacity).

Additional Fixes

The line below for the constant definition has a lowercase i at the beginning of the word "image". The i has been capitalized to follow proper UpperCamelCase. The two references to this BackgroundImageStretchModeKey constant have been updated to reflect the new name.

static constexpr std::string_view BackgroundimageStretchModeKey{ "backgroundImageStretchMode" };

(This change was performed in its own commit, so it can be reverted if needed.)

Validation Steps Performed

  • Test and observe all 9 possible alignment values, invalid input, and not specifying the setting at all.
    • For each image stretch mode.
    • For when a background image is defined or not.
    • Confirm alignment names match up.
  • For each alignment value, confirm they are re-serialized correctly when opening Windows Terminal.
  • Confirm default setting results in a centered background image.
  • Test and observe if alignment settings are properly applied when first opening the Windows Terminal or opening a new profile tab.

Preview Example Alignments

Below are examples of the alignments bottom (Left) and bottomRight (Right) in use.

Preview Figure A (Left) and Figure B (Right)

Figure A (Left) shows the use of bottom alignment with uniformToFill stretch mode. The waves will always be at the bottom and stay centered horizontally. Figure B (Right) shows the use of bottomRight alignment with none stretch mode. The image will always remain in the bottom right corner and remain the same size.

TerminalSettings now has two new properties:
* BackgroundImageHorizontalAlignment
* BackgroundImageVerticalAlignment

These properties are used in TermControl::_InitializeBackgroundBrush to specify the alignment for TermControl::_bgImageLayer.

This is a base commit that will split into two possible branches:
* Use one setting in profiles.json: "backgroundImageAlignment"
* Use two settings in profiles.json: "backgroundImageHorizontal/VerticalAlignment"
Implement background image alignment as one profile setting.
* This has the benefit of acting as a single setting when the user would likely want to change both horizontal and vertical alignment.
* HorizontalAlignment and VerticalAlignment are still stored as a tuple in Profile because they are an optional field. And thus, it would not make sense for one of the alignments to be left unused while the other is not.
* Cons are that the tuple signature is quite long, but it is only used in a small number of locations. The Serialize method is also a little mishapen with the nested switch statements. Empty lines have been added between base-level cases to improve readability.
In Profiles.cpp, the key for the image stretch mode json property had a lowercase 'i' in "Backgroundimage", not following proper UpperCamelCase.
The "i" has been capitalized and the two usages of the constant have been updated as well.
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 seems good and reasonable to me. However, would you mind updating SettingsSchema.md as well?

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 16, 2019
@trigger-segfault
Copy link
Contributor Author

Of course. Wasn't sure if documentation was delegated to other parties or not. I'll also add entries for the original 3 backgroundImage settings.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 16, 2019
@trigger-segfault trigger-segfault marked this pull request as ready for review July 16, 2019 16:26
* Adds entries SettingsSchema.md for the original 3 backgroundImage settings in addition to the new backgroundImageAlignment setting.
* The background image example in UsingJsonSettings.md listing a backgroundImageStretchMode of "Fill" has been corrected to "fill".
@trigger-segfault
Copy link
Contributor Author

trigger-segfault commented Jul 16, 2019

4 new entries have been added to the SettingsSchema.md documentation.

In addition, one background image-related setting capitalization typo (which results in an invalid value) has been fixed in the UsingJsonSettings.md file.

Also my apologies, I should have added a [ci skip] to the last two commits.

@@ -35,6 +35,10 @@ Properties listed below are specific to each unique profile.
| `startingDirectory` | _Required_ | String | `%USERPROFILE%` | The directory the shell starts in when it is loaded. |
| `useAcrylic` | _Required_ | Boolean | `false` | When set to `true`, the window will have an acrylic background. When set to `false`, the window will have a plain, untextured background. |
| `background` | Optional | String | | Sets the background color of the profile. Overrides `background` set in color scheme if `colorscheme` is set. Uses hex color format: `"#rrggbb"`. |
| `backgroundImage` | Optional | String | | Sets the file location of the Image to draw over the window background. |
| `backgroundImageAlignment` | Optional | String | `center` | Sets how the background image aligns to the boundaries of the window. Possible values: `"center"`, `"left"`, `"top"`, `"right"`, `"bottom"`, `"topLeft"`, `"topRight"`, `"bottomLeft"`, `"bottomRight"` |
Copy link
Member

Choose a reason for hiding this comment

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

Can you list out what the default behavior will be if you don't set the alignment/opacity/stretch given they're optional?

Copy link
Member

Choose a reason for hiding this comment

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

I believe that's what column 4 is for, but I'm not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, column 4 ( Default ) lists the default settings of center, 1.0, and uniformToFill respectively. Default values are listed for other optional settings in the Globals category as well.

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.

Looks good, thanks!

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

I prefer the one setting. Good work!

Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Thank you!

@DHowett-MSFT DHowett-MSFT merged commit 89190c6 into microsoft:master Jul 25, 2019
@ghost
Copy link

ghost commented Aug 3, 2019

🎉Windows Terminal Preview v0.3.2142.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Background image alignment
5 participants