2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Collections.Generic;
21 namespace ElmSharp.Test
23 public class ToolbarTest1 : TestCaseBase
25 Dictionary<ToolbarItem, int> _itemTable = new Dictionary<ToolbarItem, int>();
26 Dictionary<int, ToolbarItem> _reverseItemTable = new Dictionary<int, ToolbarItem>();
27 int currentItemIndex = 0;
28 public override string TestName => "ToolbarTest1";
29 public override string TestDescription => "To test basic operation of Toolbar";
30 public override void Run(Window window)
32 Conformant conformant = new Conformant(window);
34 Box outterBox = new Box(window)
44 Toolbar toolbar = new Toolbar(window)
48 ShrinkMode = ToolbarShrinkMode.Scroll
52 outterBox.PackEnd(toolbar);
55 Scroller scroller = new Scroller(window)
61 ScrollBlock = ScrollBlock.Vertical,
62 HorizontalPageScrollLimit = 1,
64 scroller.SetPageSize(1.0, 1.0);
67 Box box = new Box(window)
76 scroller.SetContent(box);
78 var rnd = new Random();
79 for (int i = 0; i < 5; i++)
81 int r = rnd.Next(255);
82 int g = rnd.Next(255);
83 int b = rnd.Next(255);
84 Color color = Color.FromRgb(r, g, b);
85 Rectangle colorBox = new Rectangle(window)
92 MinimumWidth = window.ScreenSize.Width,
95 box.PackEnd(colorBox);
96 ToolbarItem item = toolbar.Append(string.Format("{0} Item", i), "home");
98 _reverseItemTable[i] = item;
99 item.Selected += (s, e) =>
101 scroller.ScrollTo(_itemTable[(ToolbarItem)s], 0, true);
104 scroller.Scrolled += (s, e) =>
106 if (scroller.HorizontalPageIndex != currentItemIndex)
108 currentItemIndex = scroller.HorizontalPageIndex;
109 _reverseItemTable[currentItemIndex].IsSelected = true;
112 conformant.SetContent(outterBox);
113 outterBox.PackEnd(scroller);