Toasts – Diff between revs 49 and 50

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 49 Rev 50
Line 33... Line 33...
33   33  
Line 34... Line 34...
34 public FormAnimator.AnimationMethod AnimationMethodDetached { get; set; } = FormAnimator.AnimationMethod.Fade; 34 public FormAnimator.AnimationMethod AnimationMethodDetached { get; set; } = FormAnimator.AnimationMethod.Fade;
Line 35... Line 35...
35   35  
Line 36... Line 36...
36 public FormAnimator.AnimationDirection AnimationDirectionDetached { get; set; } = FormAnimator.AnimationDirection.None; 36 public FormAnimator.AnimationDirection AnimationDirectionDetached { get; set; } = FormAnimator.AnimationDirection.None;
Line 37... Line 37...
37   37  
Line 38... Line 38...
38 public FormAnimator.AnimationMethod AnimationMethod { get; set; } = FormAnimator.AnimationMethod.Slide; 38 public FormAnimator.AnimationMethod AnimationMethod { get; set; } = FormAnimator.AnimationMethod.Fade;
Line 188... Line 188...
188 components.Dispose(); 188 components.Dispose();
189 } 189 }
Line 190... Line 190...
190   190  
191 if (_toastTimer != null) 191 if (_toastTimer != null)
-   192 {
192 { 193 _toastTimer.Stop();
193 _toastTimer.Dispose(); 194 _toastTimer.Dispose();
194 _toastTimer = null; 195 _toastTimer = null;
Line 195... Line 196...
195 } 196 }
Line 288... Line 289...
288   289  
289 Invoke(new MethodInvoker(() => 290 Invoke(new MethodInvoker(() =>
290 { 291 {
291 // compute notification height from body 292 // compute notification height from body
-   293 var maxWidth = tableLayoutPanel4.Width;
292 var maxWidth = tableLayoutPanel4.Width; 294  
293 using (var m_Bitmap = new Bitmap(64, 64)) 295 switch (ContentType)
-   296 {
294 { 297 case "text/markdown":
295 using (var graphics = Graphics.FromImage(m_Bitmap)) 298 var htmlDocument = new HtmlAgilityPack.HtmlDocument();
296 { 299 var panelText = htmlPanel1.Text;
297 switch (ContentType) 300 if (!string.IsNullOrEmpty(panelText))
298 { 301 {
299 case "text/markdown": 302 htmlDocument.LoadHtml(panelText);
-   303 if (htmlDocument.DocumentNode != null && htmlDocument.DocumentNode.Descendants().Any())
300 var htmlDocument = new HtmlAgilityPack.HtmlDocument(); 304 {
301 var panelText = htmlPanel1.Text; 305 var imgNodes = htmlDocument.DocumentNode.SelectNodes("//img");
302 if (!string.IsNullOrEmpty(panelText)) 306 if (imgNodes != null && imgNodes.Any())
303 { 307 {
304 htmlDocument.LoadHtml(panelText); -  
305 if (htmlDocument.DocumentNode != null && htmlDocument.DocumentNode.Descendants().Any()) 308 foreach (var node in imgNodes)
306 { -  
307 var imgNodes = htmlDocument.DocumentNode.SelectNodes("//img"); -  
308 if (imgNodes != null && imgNodes.Any()) -  
309 { -  
310 foreach (var node in imgNodes) -  
311 { 309 {
312 node.SetAttributeValue("style", $"max-width: {maxWidth}px"); -  
313 } -  
314 } 310 node.SetAttributeValue("style", $"max-width: {maxWidth}px");
315 } -  
316   -  
317 htmlPanel1.Text = htmlDocument.DocumentNode.WriteTo(); 311 }
318 } -  
319 break; -  
320 default: -  
321 break; 312 }
Line 322... Line -...
322 } -  
323   -  
324 PointF point = new PointF(0, 0); -  
325 SizeF maxSize = new SizeF(maxWidth, Screen.PrimaryScreen.WorkingArea.Height); -  
326 var renderSize = HtmlRender.Render(graphics, htmlPanel1.Text, point, maxSize); -  
327 // total height = height of text fitting in rectangle + the height of the title on top + one extra line for the last line wrap -  
328 var computedOptimalHeight = (int)Math.Round(renderSize.Height) + labelTitle.Height + (int)Math.Round(htmlPanel1.Font.GetHeight()); -  
329 // keep the default height of a notification constant -  
330 if (computedOptimalHeight > Height) 313 }
331 { 314  
-   315 htmlPanel1.Text = htmlDocument.DocumentNode.WriteTo();
-   316 }
-   317 break;
-   318 default:
-   319 break;
-   320 }
-   321  
-   322 //var maxSize = new Size(maxWidth, Screen.PrimaryScreen.WorkingArea.Height);
-   323 using (var image = HtmlRender.RenderToImage(htmlPanel1.Text, maxWidth, 0, Color.Empty))
-   324 {
-   325 var height = image.Height + labelTitle.Height;
-   326 if(height > Height)
332 Height = computedOptimalHeight; 327 {
333 } 328 Height = height;
334 } 329 }
Line 335... Line 330...
335 } 330 }