2 * Copyright (c) 2017 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.
22 namespace MyCSharpExample
26 private Application _application;
27 private TextLabel _title;
29 public Example(Application application)
31 _application = application;
32 _application.Initialized += Initialize;
35 public void Initialize(object source, NUIApplicationInitEventArgs e)
37 Window window = Window.Instance;
38 window.BackgroundColor = Color.White;
40 TableView contentLayout = new TableView(4, 1);
41 contentLayout.Name = ("ContentLayout");
42 contentLayout.WidthResizePolicy = "FILL_TO_PARENT";
43 contentLayout.HeightResizePolicy = "FILL_TO_PARENT";
44 contentLayout.SetCellPadding(new Size2D(0, 5));
45 contentLayout.BackgroundColor = new Color(0.949f, 0.949f, 0.949f, 1.0f);
47 window.GetDefaultLayer().Add(contentLayout);
49 _title = new TextLabel("Visuals Example");
50 _title.Name = "Title";
51 _title.StyleName = "Title";
52 _title.WidthResizePolicy = "FILL_TO_PARENT";
53 _title.HeightResizePolicy = "USE_NATURAL_SIZE";
54 _title.HorizontalAlignment = "CENTER";
55 _title.BackgroundColor = Color.Yellow;
56 contentLayout.Add(_title);
57 contentLayout.SetFitHeight(0);
59 // Color Visual example
60 View colorView = new View();
61 colorView.WidthResizePolicy = "SIZE_RELATIVE_TO_PARENT";
62 colorView.HeightResizePolicy = "SIZE_RELATIVE_TO_PARENT";
63 Property.Map colorVisual = new Property.Map();
64 colorVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Color ))
65 .Add( ColorVisualProperty.MixColor, new Property.Value( Color.Green ));
66 colorView.Background = colorVisual;
67 contentLayout.Add(colorView);
69 // Image Visual example
70 View imageView = new View();
71 imageView.WidthResizePolicy = "USE_NATURAL_SIZE";
72 imageView.HeightResizePolicy = "USE_NATURAL_SIZE";
73 Property.Map imageVisual = new Property.Map();
74 imageVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Image ))
75 .Add( ImageVisualProperty.URL, new Property.Value( "./images/gallery-0.jpg" ));
76 imageView.Background = imageVisual;
77 contentLayout.SetCellAlignment(new TableView.CellPosition(2, 0), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
78 contentLayout.Add(imageView);
80 // Primitive Visual example
81 View primitiveView = new View();
82 primitiveView.WidthResizePolicy = "SIZE_RELATIVE_TO_PARENT";
83 primitiveView.HeightResizePolicy = "SIZE_RELATIVE_TO_PARENT";
84 Property.Map primitiveVisual = new Property.Map();
85 primitiveVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Primitive ))
86 .Add( PrimitiveVisualProperty.Shape, new Property.Value((int)PrimitiveVisualShapeType.BEVELLED_CUBE))
87 .Add( PrimitiveVisualProperty.BevelPercentage, new Property.Value(0.3f))
88 .Add( PrimitiveVisualProperty.BevelSmoothness, new Property.Value(0.0f))
89 .Add( PrimitiveVisualProperty.ScaleDimensions, new Property.Value(new Vector3(1.0f,1.0f,0.3f)))
90 .Add( PrimitiveVisualProperty.MixColor, new Property.Value(new Vector4(0.7f, 0.5f, 0.05f, 1.0f)));
91 primitiveView.Background = primitiveVisual;
92 Radian rad = new Radian(new Degree(45.0f));
93 primitiveView.Orientation = new Rotation(rad, Vector3.YAXIS);
94 contentLayout.Add(primitiveView);
96 // Text Visual example
97 View textView = new View();
98 textView.WidthResizePolicy = "SIZE_RELATIVE_TO_PARENT";
99 textView.HeightResizePolicy = "SIZE_RELATIVE_TO_PARENT";
100 Property.Map textVisual = new Property.Map();
101 textVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Text ))
102 .Add( TextVisualProperty.Text, new Property.Value("I am text visual"))
103 .Add( TextVisualProperty.TextColor, new Property.Value(Color.Blue))
104 .Add( TextVisualProperty.PointSize, new Property.Value(20));
105 textView.Background = textVisual;
106 contentLayout.Add(textView);
109 public void MainLoop()
111 _application.MainLoop();
115 /// The main entry point for the application.
118 static void Main(string[] args)
120 Example example = new Example(Application.NewApplication());