[NUI] add ControlState class to support combined and custom state (#1762)
authorYeongJong Lee <cleanlyj@naver.com>
Fri, 3 Jul 2020 02:05:20 +0000 (11:05 +0900)
committerGitHub <noreply@github.com>
Fri, 3 Jul 2020 02:05:20 +0000 (11:05 +0900)
commitf35ca6fa89c4cc86c53f087daa6012d53c8f7765
treee7bf512434fd4f36a64838bdf8840d71de6321fe
parent7c984d9f3468ff8724c377b5e10fa271f942b7d4
[NUI] add ControlState class to support combined and custom state (#1762)

### Custom State

You can define your own control states. first, declare ControlState variable
and initialize using  `ControlState.Create`.
```
public class MyButton : Button {
   ...
   ControlState MyState = ControlState.Create("MyState");
   ...
}
```
And assign to `View.ControlState`.
```
void OnStateChanged(...) {
    ControlState = MyState;
}
```

If you want to assign the value of custom state to `Selector`, use
`Add(ControlState state, object value)`.
```
Selector<string> textSelector = new Selector<string>();
textSelector.Add(ControlState.Pressed, "Pressed!");
textSelector.Add(MyState, "MyText");
```
or
```
Selector<string> textSelector = new Selector<string>()
{
    { ControlState.Pressed, "Pressed!" },
    { MyState, "MyText" }
};
```

 ### Combined State
To implement your own combined control states, you can use the `+` or `+=`
operators.
For example, `MyCombinedStateX` are all the same.
```
ControlState MyCombinedStateA =
   ControlState.Create(ControlState.Pressed, ControlState.Focused);

ControlState MyCombinedStateB = ControlState.Pressed + ControlState.Focused;
```

Note that `Normal` and `All` state cannot be combined with other states.
`Normal` state is ignored. however, `All` state will ignore other states.
```
ControlState.Create(ControlState.Pressed, ControlState.Focused, ControlState.Normal) ==
   ControlState.Create(ControlState.Pressed, ControlState.Focused)

ControlState.Create(ControlState.All, ControlState.Pressed, ControlState.Focused) ==
   ControlState.Create(ControlState.All)
```

 ### ControlState in Xaml

It will support new initialization syntax.
Legacy:
```
<c:TextLabelStyle.Text>
    <c:Selector x:TypeArguments="x:String" Normal="button" Pressed="pressed!!"/>
</c:TextLabelStyle.Text>
```

New:
```
<c:TextLabelStyle.Text>
    <c:StateValuePair x:TypeArguments="x:String" State="Normal" Value="button"/>
    <c:StateValuePair x:TypeArguments="x:String" State="Pressed" Value="pressed!!" />
    <c:StateValuePair x:TypeArguments="x:String" State="MyState" Value="my state!" />
    <c:StateValuePair x:TypeArguments="x:String" State="MyState,Normal,Focused" Value="my combined state!" />
</c:TextLabelStyle.Text>
```

However, it won't work because there is no converter of  `ControlState`.
The next step would be to implement `ControlState` converter.
14 files changed:
src/Tizen.NUI.Components/Controls/Button.Internal.cs
src/Tizen.NUI.Components/Controls/Control.cs
src/Tizen.NUI.Components/Controls/DropDown.DropDownItemView.cs
src/Tizen.NUI.Components/Controls/Extension/LottieButtonExtension.cs
src/Tizen.NUI.Components/Controls/Slider.cs
src/Tizen.NUI.Components/Controls/Tab.cs
src/Tizen.NUI.Components/PreloadStyle/OverlayAnimationButtonStyle.cs
src/Tizen.NUI.Wearable/src/public/CircularProgress.cs
src/Tizen.NUI/src/public/BaseComponents/ControlState.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/BaseComponents/Style/Constants.cs
src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs
src/Tizen.NUI/src/public/BaseComponents/Style/StateValueCollection.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs