|
| 1 | +/* |
| 2 | +* Copyright (c) 2020 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 | + |
| 18 | +using System; |
| 19 | +using Tizen.NUI; |
| 20 | +using Tizen.NUI.BaseComponents; |
| 21 | +using Tizen.NUI.Components; |
| 22 | + |
| 23 | +namespace Tizen.NUI.Samples |
| 24 | +{ |
| 25 | + class GridExample : IExample |
| 26 | + { |
| 27 | + private Window currentWindow; |
| 28 | + private static int MAX_ITEM_COUNT = 31; |
| 29 | + private int layoutOption = 3; |
| 30 | + |
| 31 | + private View layoutView; |
| 32 | + private TextLabel label; |
| 33 | + private View bottomView; |
| 34 | + private View bottomView_2; |
| 35 | + |
| 36 | + public void Activate() |
| 37 | + { |
| 38 | + Initialize(); |
| 39 | + } |
| 40 | + |
| 41 | + public void Initialize() |
| 42 | + { |
| 43 | + currentWindow = NUIApplication.GetDefaultWindow(); |
| 44 | + currentWindow.BackgroundColor = Color.White; |
| 45 | + |
| 46 | + InitializeDefaultUI(); |
| 47 | + InitializeLayoutUI(); |
| 48 | + } |
| 49 | + |
| 50 | + public void InitializeLayoutUI() |
| 51 | + { |
| 52 | + for (int i = 0; i < MAX_ITEM_COUNT; i++) |
| 53 | + { |
| 54 | + View child = new View() |
| 55 | + { |
| 56 | + Size = new Size(100, 100), |
| 57 | + BackgroundColor = i % 2 == 0 ? Color.Magenta : Color.Cyan, |
| 58 | + }; |
| 59 | + |
| 60 | + TextLabel text = new TextLabel("" + (i + 1)) |
| 61 | + { |
| 62 | + PointSize = 14, |
| 63 | + Size = new Size(50, 50), |
| 64 | + }; |
| 65 | + |
| 66 | + child.Add(text); |
| 67 | + layoutView.Add(child); |
| 68 | + } |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | + public void InitializeDefaultUI() |
| 73 | + { |
| 74 | + label = new TextLabel() |
| 75 | + { |
| 76 | + Text = "Layout Sample", |
| 77 | + PointSize = 20, |
| 78 | + }; |
| 79 | + currentWindow.Add(label); |
| 80 | + |
| 81 | + layoutView = new View() |
| 82 | + { |
| 83 | + Size2D = new Size2D(480, 600), |
| 84 | + Position2D = new Position2D(0, 30), |
| 85 | + BackgroundColor = Color.Black, |
| 86 | + Layout = new GridLayout() |
| 87 | + { |
| 88 | + LinearOrientation = GridLayout.Orientation.Vertical, |
| 89 | + Columns = 5, |
| 90 | + }, |
| 91 | + |
| 92 | + }; |
| 93 | + currentWindow.Add(layoutView); |
| 94 | + |
| 95 | + View bottomView = new View() |
| 96 | + { |
| 97 | + Size = new Size(480, 100), |
| 98 | + Position2D = new Position2D(0, 600), |
| 99 | + BackgroundColor = Color.Black, |
| 100 | + Layout = new LinearLayout() |
| 101 | + { |
| 102 | + LinearOrientation = LinearLayout.Orientation.Horizontal, |
| 103 | + LinearAlignment = LinearLayout.Alignment.Center, |
| 104 | + } |
| 105 | + |
| 106 | + }; |
| 107 | + currentWindow.Add(bottomView); |
| 108 | + |
| 109 | + Button btn_1 = new Button() |
| 110 | + { |
| 111 | + Text = "Grid_V", |
| 112 | + Size = new Size(100, 50), |
| 113 | + Margin = 10, |
| 114 | + }; |
| 115 | + Button btn_2 = new Button() |
| 116 | + { |
| 117 | + Text = "Grid_H", |
| 118 | + Size = new Size(100, 50), |
| 119 | + Margin = 10, |
| 120 | + }; |
| 121 | + btn_1.ClickEvent += Btn1_ClickEvent; |
| 122 | + btn_2.ClickEvent += Btn2_ClickEvent; |
| 123 | + |
| 124 | + bottomView.Add(btn_1); |
| 125 | + bottomView.Add(btn_2); |
| 126 | + |
| 127 | + bottomView_2 = new View() |
| 128 | + { |
| 129 | + Size = new Size(480, 100), |
| 130 | + Position2D = new Position2D(0, 700), |
| 131 | + BackgroundColor = Color.Black, |
| 132 | + Layout = new LinearLayout() |
| 133 | + { |
| 134 | + LinearOrientation = LinearLayout.Orientation.Horizontal, |
| 135 | + LinearAlignment = LinearLayout.Alignment.Center, |
| 136 | + } |
| 137 | + }; |
| 138 | + currentWindow.Add(bottomView_2); |
| 139 | + |
| 140 | + Button btn_5 = new Button() |
| 141 | + { |
| 142 | + Text = "++", |
| 143 | + Size = new Size(50, 50), |
| 144 | + Margin = 10, |
| 145 | + }; |
| 146 | + Button btn_6 = new Button() |
| 147 | + { |
| 148 | + Text = "--", |
| 149 | + Size = new Size(50, 50), |
| 150 | + Margin = 10, |
| 151 | + }; |
| 152 | + btn_5.ClickEvent += Btn5_ClickEvent; |
| 153 | + btn_6.ClickEvent += Btn6_ClickEvent; |
| 154 | + |
| 155 | + bottomView_2.Add(btn_5); |
| 156 | + bottomView_2.Add(btn_6); |
| 157 | + } |
| 158 | + |
| 159 | + private void Btn1_ClickEvent(object sender, Button.ClickEventArgs e) |
| 160 | + { |
| 161 | + GridLayout layout = new GridLayout(); |
| 162 | + layout.Columns = 5; |
| 163 | + layout.LinearOrientation = GridLayout.Orientation.Vertical; |
| 164 | + layoutView.Layout = layout; |
| 165 | + layoutOption = 1; |
| 166 | + layout.LayoutWithTransition = true; |
| 167 | + } |
| 168 | + |
| 169 | + private void Btn2_ClickEvent(object sender, Button.ClickEventArgs e) |
| 170 | + { |
| 171 | + GridLayout layout = new GridLayout(); |
| 172 | + layout.LayoutWithTransition = true; |
| 173 | + layout.Rows = 5; |
| 174 | + layout.LinearOrientation = GridLayout.Orientation.Horizontal; |
| 175 | + layoutView.Layout = layout; |
| 176 | + |
| 177 | + layoutOption = 2; |
| 178 | + } |
| 179 | + |
| 180 | + private void Btn5_ClickEvent(object sender, Button.ClickEventArgs e) |
| 181 | + { |
| 182 | + ObjectProcess(true); |
| 183 | + } |
| 184 | + |
| 185 | + private void Btn6_ClickEvent(object sender, Button.ClickEventArgs e) |
| 186 | + { |
| 187 | + ObjectProcess(false); |
| 188 | + } |
| 189 | + |
| 190 | + public void ObjectProcess(bool opt) |
| 191 | + { |
| 192 | + int nValue = opt ? 1 : -1; |
| 193 | + switch (layoutOption) |
| 194 | + { |
| 195 | + case 1: |
| 196 | + (layoutView.Layout as GridLayout).Columns += nValue; |
| 197 | + break; |
| 198 | + case 2: |
| 199 | + (layoutView.Layout as GridLayout).Rows += nValue; |
| 200 | + break; |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + public void Deactivate() |
| 205 | + { |
| 206 | + label.Unparent(); |
| 207 | + layoutView.Unparent(); |
| 208 | + bottomView.Unparent(); |
| 209 | + bottomView_2.Unparent(); |
| 210 | + |
| 211 | + label.Dispose(); |
| 212 | + layoutView.Dispose(); |
| 213 | + bottomView.Dispose(); |
| 214 | + bottomView_2.Dispose(); |
| 215 | + |
| 216 | + label = null; |
| 217 | + layoutView = null; |
| 218 | + bottomView = null; |
| 219 | + bottomView_2 = null; |
| 220 | + } |
| 221 | + } |
| 222 | +} |
0 commit comments