4 using System.Collections.Generic;
6 namespace ElmSharp.Test
8 public class ImageTest1 : TestCaseBase
10 public override string TestName => "ImageTest1";
11 public override string TestDescription => "To test basic operation of Image";
16 public override void Run(Window window)
18 Conformant conformant = new Conformant(window);
20 Box box = new Box(window);
21 conformant.SetContent(box);
24 Box buttonBox1 = new Box(window)
32 Box buttonBox2 = new Box(window)
40 Button btnFile1 = new Button(window)
50 Button btnFile2 = new Button(window)
60 Button btnUri1 = new Button(window)
70 Button btnStream1 = new Button(window)
80 buttonBox1.PackEnd(btnFile1);
81 buttonBox1.PackEnd(btnFile2);
82 buttonBox1.PackEnd(btnUri1);
83 buttonBox1.PackEnd(btnStream1);
86 Button btnFileAsync1 = new Button(window)
96 Button btnFileAsync2 = new Button(window)
104 btnFileAsync2.Show();
106 Button btnUriAsync1 = new Button(window)
116 Button btnStreamAsync1 = new Button(window)
124 btnStreamAsync1.Show();
126 buttonBox2.PackEnd(btnFileAsync1);
127 buttonBox2.PackEnd(btnFileAsync2);
128 buttonBox2.PackEnd(btnUriAsync1);
129 buttonBox2.PackEnd(btnStreamAsync1);
132 lbInfo = new Label(window)
141 image = new Image(window)
143 IsFixedAspect = true,
150 image.Load(Path.Combine(TestRunner.ResourceDir, "picture.png"));
151 image.Clicked += (s, e) =>
153 Console.WriteLine("Image has been clicked. (IsFixedAspect = {0}", image.IsFixedAspect);
154 image.IsFixedAspect = image.IsFixedAspect == true ? false : true;
157 btnFile1.Clicked += (s, e) => LoadFile("TED/large/a.jpg");
158 btnFile2.Clicked += (s, e) => LoadFile("TED/large/b.jpg");
159 btnUri1.Clicked += (s, e) => LoadUri("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
160 btnStream1.Clicked += (s, e) => LoadStream(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/c.jpg"), FileMode.Open));
162 btnFileAsync1.Clicked += (s, e) => LoadFileAsync("TED/large/d.jpg");
163 btnFileAsync2.Clicked += (s, e) => LoadFileAsync("TED/large/e.jpg");
164 btnUriAsync1.Clicked += (s, e) => LoadUriAsync("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
165 btnStreamAsync1.Clicked += (s, e) => LoadStreamAsync(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/f.jpg"), FileMode.Open));
166 box.PackEnd(buttonBox1);
167 box.PackEnd(buttonBox2);
172 void LoadFile(string file)
174 bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
176 UpdateLabelText(lbInfo, image.File);
178 UpdateLabelText(lbInfo, "Loading Failed.");
181 void LoadUri(string uri)
183 bool ret = image.Load(uri);
185 UpdateLabelText(lbInfo, image.File);
187 UpdateLabelText(lbInfo, "Loading Failed.");
190 void LoadStream(Stream stream)
192 bool ret = image.Load(stream);
194 UpdateLabelText(lbInfo, image.File);
196 UpdateLabelText(lbInfo, "Loading Failed.");
199 async void LoadFileAsync(string file)
201 var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
203 UpdateLabelText(lbInfo, image.File);
205 UpdateLabelText(lbInfo, "Loading Failed.");
208 async void LoadUriAsync(string uri)
210 var ret = await image.LoadAsync(uri);
212 UpdateLabelText(lbInfo, image.File);
214 UpdateLabelText(lbInfo, "Loading Failed.");
217 async void LoadStreamAsync(Stream stream)
219 var ret = await image.LoadAsync(stream);
221 UpdateLabelText(lbInfo, image.File);
223 UpdateLabelText(lbInfo, "Loading Failed.");
226 void UpdateLabelText(Label lable, string text)
228 lable.Text = "<span color=#ffffff font_size=20>" + text + "</span>";