2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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.Runtime.InteropServices;
22 namespace MyCSharpExample
26 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
27 delegate void CallbackDelegate(IntPtr data);
29 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
30 delegate void ActorCallbackDelegate(IntPtr data);
32 private Dali.Application _application;
33 private ScrollView _scrollView;
34 private ScrollBar _scrollBar;
36 public Example(Dali.Application application)
38 _application = application;
39 _application.Initialized += Initialize;
43 public void Initialize(object source, AUIApplicationInitEventArgs e)
48 private void CreateScrollView()
50 Stage stage = Stage.GetCurrent();
51 stage.BackgroundColor = NDalic.WHITE;
53 // Create a scroll view
54 _scrollView = new ScrollView();
55 Vector2 stageSize = stage.Size;
56 _scrollView.Size = new Vector3(stageSize.x, stageSize.y, 0.0f);
57 _scrollView.ParentOrigin = NDalic.ParentOriginCenter;
58 _scrollView.AnchorPoint = NDalic.AnchorPointCenter;
59 stage.Add(_scrollView);
61 // Add actors to a scroll view with 3 pages
64 for(int pageRow = 0; pageRow < pageRows; pageRow++)
66 for(int pageColumn = 0; pageColumn < pageColumns; pageColumn++)
68 View pageActor = new View();
69 pageActor.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS);
70 pageActor.ParentOrigin = NDalic.ParentOriginCenter;
71 pageActor.AnchorPoint = NDalic.AnchorPointCenter;
72 pageActor.Position = new Vector3(pageColumn * stageSize.x, pageRow * stageSize.y, 0.0f);
74 // Add images in a 3x4 grid layout for each page
78 Vector3 imageSize = new Vector3((stageSize.x / imageColumns) - margin, (stageSize.y / imageRows) - margin, 0.0f);
80 for(int row = 0; row < imageRows; row++)
82 for(int column = 0; column < imageColumns;column++)
84 int imageId = (row * imageColumns + column) % 2 + 1;
85 ImageView imageView = new ImageView("images/image-" + imageId + ".jpg");
86 imageView.ParentOrigin = NDalic.ParentOriginCenter;
87 imageView.AnchorPoint = NDalic.AnchorPointCenter;
88 imageView.Size = imageSize;
89 imageView.Position = new Vector3( margin * 0.5f + (imageSize.x + margin) * column - stageSize.x * 0.5f + imageSize.x * 0.5f,
90 margin * 0.5f + (imageSize.y + margin) * row - stageSize.y * 0.5f + imageSize.y * 0.5f, 0.0f );
91 pageActor.Add(imageView);
95 _scrollView.Add(pageActor);
99 _scrollView.SetAxisAutoLock(true);
101 // Set scroll view to have 3 pages in X axis and allow page snapping,
102 // and also disable scrolling in Y axis.
103 RulerPtr scrollRulerX = new RulerPtr(new FixedRuler(stageSize.width));
104 RulerPtr scrollRulerY = new RulerPtr(new DefaultRuler());
105 scrollRulerX.SetDomain(new RulerDomain(0.0f, stageSize.width * pageColumns, true));
106 scrollRulerY.Disable();
107 _scrollView.SetRulerX(scrollRulerX);
108 _scrollView.SetRulerY(scrollRulerY);
110 // Create a horizontal scroll bar in the bottom of scroll view (which is optional)
111 _scrollBar = new ScrollBar();
112 _scrollBar.ParentOrigin = NDalic.ParentOriginBottomLeft;
113 _scrollBar.AnchorPoint = NDalic.AnchorPointTopLeft;
114 _scrollBar.SetResizePolicy(ResizePolicyType.FIT_TO_CHILDREN, DimensionType.WIDTH);
115 _scrollBar.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
116 _scrollBar.Orientation = new Quaternion( new Radian( new Degree( 270.0f ) ), Vector3.ZAXIS );
117 _scrollBar.SetScrollDirection(ScrollBar.Direction.Horizontal);
118 _scrollView.Add(_scrollBar);
120 // Connect to the OnRelayout signal
121 _scrollView.OnRelayoutEvent += OnScrollViewRelayout;
124 private void OnScrollViewRelayout(object source, View.OnRelayoutEventArgs e)
126 // Set the correct scroll bar size after size negotiation of scroll view is done
127 _scrollBar.Size = new Vector3(0.0f, _scrollView.GetRelayoutSize(DimensionType.WIDTH), 0.0f);
130 public void MainLoop()
132 _application.MainLoop ();
136 /// The main entry point for the application.
139 static void Main(string[] args)
141 Example example = new Example(Application.NewApplication());