Skip to content

Introduce a way to bind an Enum setting for the Settings UI#8086

Merged
17 commits merged intofeature/settings-uifrom
dev/lelian/sui-globalappearance
Nov 3, 2020
Merged

Introduce a way to bind an Enum setting for the Settings UI#8086
17 commits merged intofeature/settings-uifrom
dev/lelian/sui-globalappearance

Conversation

@leonMSFT
Copy link
Contributor

@leonMSFT leonMSFT commented Oct 28, 2020

This PR's goal was to expose the String to Enum mappings we have in JsonUtils and to bind a group of Radio buttons to that setting and its possible enum values. To allow the Radio button groups to be data bound to, I created an EnumEntry class in TSE that'll take a string to represent your enum value name and an IInspectable to associate that name with an enum value. There's also macros that will initialize the necessary properties for a setting whose type is an enum. With these macros, you'll be able to bind to a collection of enum values and to the enum setting itself.

References #1564

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.

I'm fairly worried about how much boilerplate we're going to have to have - but at this point I think we're all used to seeing SOME_MACRO_THING that expands to a bunch of cppwinrt boilerplate that we know works.

I'm blocking over the initialization thing in EnumMappings.cpp, but I also know that the settings UI is all gas no brakes so you can go ahead and dismiss it if it isn't relevant

@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Oct 29, 2020
@DHowett DHowett mentioned this pull request Oct 29, 2020
6 tasks
Comment on lines 38 to 45
uint8_t GlobalAppearance::CurrentTheme()
{
return static_cast<uint8_t>(GlobalSettings().Theme());
}

void GlobalAppearance::CurrentTheme(const uint8_t index)
{
GlobalSettings().Theme(static_cast<ElementTheme>(index));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I can't just bind an enum to a XAML property that expects an int (like SelectedIndex) so had to do something like this

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 also just does not work if the enum isn't consecutive 👀 since I'm binding this property to SelectedIndex

Copy link
Member

Choose a reason for hiding this comment

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

Hmmmmmm. Okay, how about this? Is it possible for us to bind selectedITEM, and then pull the index out of the EnumEntry? We can also search the map to return the EnumEntry for the active theme.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah we could keep a map of enum -> enumentry, and from there we can do enumMap.Lookup(globalsettings.theme()) to grab the initial EnumEntry for the databound SelectedItem. Then the TwoWay binding will do all the work as long as we set the xaml->viewmodel binding up so that it updates GlobalSettings().Theme()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ehh actually scratch that first part, keeping a map just so we can initialize the SelectedItem seems overkill

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ehh screw it i made the map, it avoids having to do if(value), and binding SelectedItem avoids the whole index route

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Love it. This is all macroable!

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.

This is awesome! Great work!

Comment on lines +14 to +18
<Page.Resources>
<DataTemplate x:DataType="local:EnumEntry" x:Key="EnumRadioButtonTemplate">
<RadioButton Content="{x:Bind EnumName, Mode=OneWay}"/>
</DataTemplate>
</Page.Resources>
Copy link
Member

Choose a reason for hiding this comment

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

This is really cool

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.

Now THIS is working with macros

I like this a lot more now

@zadjii-msft zadjii-msft removed their assignment Nov 3, 2020
@leonMSFT leonMSFT added the AutoMerge Marked for automatic merge by the bot when requirements are met label Nov 3, 2020
@ghost
Copy link

ghost commented Nov 3, 2020

Hello @leonMSFT!

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 a8d52c1 into feature/settings-ui Nov 3, 2020
@ghost ghost deleted the dev/lelian/sui-globalappearance branch November 3, 2020 17:56
This pull request was closed.
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.

4 participants