Implement #1949 Background Image Align (as one setting)#1959
Conversation
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.
zadjii-msft
left a comment
There was a problem hiding this comment.
This seems good and reasonable to me. However, would you mind updating SettingsSchema.md as well?
|
Of course. Wasn't sure if documentation was delegated to other parties or not. I'll also add entries for the original 3 |
* 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".
|
4 new entries have been added to the In addition, one background image-related setting capitalization typo (which results in an invalid value) has been fixed in the Also my apologies, I should have added a |
| | `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"` | |
There was a problem hiding this comment.
Can you list out what the default behavior will be if you don't set the alignment/opacity/stretch given they're optional?
There was a problem hiding this comment.
I believe that's what column 4 is for, but I'm not sure
There was a problem hiding this comment.
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.
carlos-zamora
left a comment
There was a problem hiding this comment.
I prefer the one setting. Good work!
|
🎉 Handy links: |
Summary of the Pull Request
Implement #1949:
profiles.jsonhas 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.When
left,top,right, orbottomis specified, the other axis is implied to be centered, as that is the default behavior. I went in favor of labeling the default value ascenterinstead ofnoneas "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.jsonsetting 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
added/passedDetailed Description of the Pull Request / Additional comments
The
Profileclass defines methods for parsing and serializing the combinedHorizontalAlignmentandVerticalAlignmentenums to and from JSON. Anstd::tuple<HorizontalAlignment, VerticalAlignment>field_backgroundImageAlignmenthas been added for storing the profile setting in one place, as it logically makes sense that both alignments to be in use together.TerminalSettingsandIControlSettingshave been givenBackgroundImageHorizontalAlignmentandBackgroundImageVerticalAlignmentproperties. The combination ofstd::tuple<HorizontalAlignment, VerticalAlignment>is gone once we leave theProfileclass. Combining the two enums is only relevant to how they are stored inprofiles.json.TerminalSettingsdefines the default values of both alignment properties asCenter.The
TermControlclass changes the image setup inTermControl::_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 (StretchandOpacity).Additional Fixes
The line below for the constant definition has a lowercase
iat the beginning of the word "image". Theihas been capitalized to follow proper UpperCamelCase. The two references to thisBackgroundImageStretchModeKeyconstant have been updated to reflect the new name.terminal/src/cascadia/TerminalApp/Profile.cpp
Line 43 in fad7638
(This change was performed in its own commit, so it can be reverted if needed.)
Validation Steps Performed
Preview Example Alignments
Below are examples of the alignments
bottom(Left) andbottomRight(Right) in use.Figure A (Left) shows the use of
bottomalignment withuniformToFillstretch mode. The waves will always be at the bottom and stay centered horizontally. Figure B (Right) shows the use ofbottomRightalignment withnonestretch mode. The image will always remain in the bottom right corner and remain the same size.