[NUI] Add IsEnabled Property in View class for controling user interactions.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.StyleGuide / Examples / ButtonExample.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using Tizen.NUI;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Components;
22
23 namespace Tizen.NUI.StyleGuide
24 {
25     // IExample inehrited class will be automatically added in the main examples list.
26     internal class ButtonExample : ContentPage, IExample
27     {
28         private Window window;
29         public void Activate()
30         {
31         }
32         public void Deactivate()
33         {
34             window = null;
35         }
36
37         /// Modify this method for adding other examples.
38         public ButtonExample() : base()
39         {
40             Log.Info(this.GetType().Name, $"{this.GetType().Name} is contructed\n");
41
42             WidthSpecification = LayoutParamPolicies.MatchParent;
43             HeightSpecification = LayoutParamPolicies.MatchParent;
44             // Navigator bar title is added here.
45             AppBar = new AppBar()
46             {
47                 Title = "Button Default Style",
48             };
49
50             // Example root content view.
51             // you can decorate, add children on this view.
52             var rootContent = new View()
53             {
54                 WidthSpecification = LayoutParamPolicies.MatchParent,
55                 HeightSpecification = LayoutParamPolicies.MatchParent,
56
57                 Layout = new LinearLayout()
58                 {
59                     LinearOrientation = LinearLayout.Orientation.Vertical,
60                     HorizontalAlignment = HorizontalAlignment.Center,
61                     VerticalAlignment = VerticalAlignment.Center,
62                     CellPadding = new Size2D(10, 20),
63                 },
64             };
65
66             // Button style examples.
67
68             var enabledButton = new Button()
69             {
70                 Text = "Enabled"
71             };
72             enabledButton.Clicked += (object obj, ClickedEventArgs ev) =>
73             {
74                 Log.Info(this.GetType().Name, "Enabled Button Clicked\n");
75             };
76             rootContent.Add(enabledButton);
77
78             var disabledButton = new Button()
79             {
80                 Text = "Disabled",
81                 IsEnabled = false,
82             };
83             disabledButton.EnableFocus();
84             disabledButton.Clicked += (object obj, ClickedEventArgs ev) =>
85             {
86                 // This event should not be recieved. button is disabled.
87                 Log.Info(this.GetType().Name, "Disabled Button Clicked\n");
88
89             };
90             rootContent.Add(disabledButton);
91
92             var selectableButton = new Button()
93             {
94                 Text = "Unselected",
95                 IsSelectable = true,
96             };
97             selectableButton.Clicked += (object obj, ClickedEventArgs ev) =>
98             {
99                 Log.Info(this.GetType().Name, "Selected Button Clicked\n");
100                 if (obj is Button button)
101                 {
102                    disabledButton.IsEnabled = button.IsSelected;
103                    if (button.IsSelected)
104                     {
105                         button.Text = "Selected";
106                     }
107                     else
108                     {
109                         button.Text = "Unselected";
110                     }
111                 }
112             };
113             rootContent.Add(selectableButton);
114             Content = rootContent;
115         }
116     }
117 }