Toasts – Diff between revs 34 and 35
?pathlinks?
Rev 34 | Rev 35 | |||
---|---|---|---|---|
Line 33... | Line 33... | |||
33 | |
33 | |
|
Line 34... | Line 34... | |||
34 | public FormAnimator.AnimationDirection AnimationDirection { get; set; } = FormAnimator.AnimationDirection.Up; |
34 | public FormAnimator.AnimationDirection AnimationDirection { get; set; } = FormAnimator.AnimationDirection.Up; |
|
Line -... | Line 35... | |||
- | 35 | |
||
- | 36 | public int AnimationDuration { get; set; } = 500; |
||
35 | |
37 | |
|
36 | public int AnimationDuration { get; set; } = 500; |
38 | public string ContentType { get; internal set; } = "text/plain"; |
|
37 | |
39 | |
|
38 | public byte[] Chime |
40 | public byte[] Chime |
|
39 | { |
41 | { |
|
Line 93... | Line 95... | |||
93 | |
95 | |
|
94 | return baseParams; |
96 | return baseParams; |
|
95 | } |
97 | } |
|
Line -... | Line 98... | |||
- | 98 | } |
||
- | 99 | |
||
96 | } |
100 | |
|
Line 97... | Line 101... | |||
97 | |
101 | |
|
Line 98... | Line 102... | |||
98 | #endregion |
102 | #endregion |
|
Line 200... | Line 204... | |||
200 | |
204 | |
|
201 | try |
205 | try |
|
202 | { |
206 | { |
|
203 | lock (OpenNotificationsLock) |
207 | lock (OpenNotificationsLock) |
|
- | 208 | { |
||
204 | { |
209 | // if not image is provided, just collapse the panel for the extra space |
|
205 | Invoke(new MethodInvoker(() => |
210 | if (imageBox.Image == null) |
|
206 | { |
- | ||
207 | // if not image is provided, just collapse the panel for the extra space |
- | ||
208 | if (imageBox.Image == null) |
- | ||
209 | { |
211 | { |
|
210 | splitContainer1.Panel1Collapsed = true; |
212 | splitContainer1.Panel1Collapsed = true; |
|
Line -... | Line 213... | |||
- | 213 | } |
||
- | 214 | |
||
211 | } |
215 | Invoke(new MethodInvoker(() => |
|
212 | |
216 | { |
|
213 | // compute notification height from body |
- | ||
214 | var maxWidth = tableLayoutPanel4.Width; |
217 | // compute notification height from body |
|
215 | htmlPanel1.MaximumSize = new Size(maxWidth, Screen.PrimaryScreen.WorkingArea.Height); |
218 | var maxWidth = tableLayoutPanel4.Width; |
|
216 | using (var m_Bitmap = new Bitmap(64, 64)) |
- | ||
217 | { |
- | ||
218 | PointF point = new PointF(0, 0); |
219 | using (var m_Bitmap = new Bitmap(64, 64)) |
|
219 | SizeF maxSize = new SizeF(maxWidth, Screen.PrimaryScreen.WorkingArea.Height); |
220 | { |
|
- | 221 | using (var graphics = Graphics.FromImage(m_Bitmap)) |
||
- | 222 | { |
||
- | 223 | switch(ContentType) |
||
- | 224 | { |
||
- | 225 | case "text/markdown": |
||
- | 226 | var htmlDocument = new HtmlAgilityPack.HtmlDocument(); |
||
- | 227 | htmlDocument.LoadHtml(htmlPanel1.Text); |
||
- | 228 | foreach (var node in htmlDocument.DocumentNode.SelectNodes("//img")) |
||
- | 229 | { |
||
- | 230 | node.SetAttributeValue("style", $"max-width: {maxWidth}px"); |
||
- | 231 | } |
||
- | 232 | |
||
- | 233 | htmlPanel1.Text = htmlDocument.DocumentNode.WriteTo(); |
||
- | 234 | break; |
||
- | 235 | default: |
||
- | 236 | break; |
||
- | 237 | } |
||
- | 238 | |
||
220 | using (var graphics = Graphics.FromImage(m_Bitmap)) |
239 | PointF point = new PointF(0, 0); |
|
221 | { |
240 | SizeF maxSize = new SizeF(maxWidth, Screen.PrimaryScreen.WorkingArea.Height); |
|
222 | var size = HtmlRender.Render(graphics, htmlPanel1.Text, point, maxSize); |
241 | var renderSize = HtmlRender.Render(graphics, htmlPanel1.Text, point, maxSize); |
|
- | 242 | // total height = height of text fitting in rectangle + the height of the title on top + one extra line for the last line wrap |
||
- | 243 | var computedOptimalHeight = (int)Math.Round(renderSize.Height) + labelTitle.Height + (int)Math.Round(htmlPanel1.Font.GetHeight()); |
||
- | 244 | // keep the default height of a notification constant |
||
- | 245 | if(computedOptimalHeight > Height) |
||
- | 246 | { |
||
223 | // total height = height of text fitting in rectangle + the height of the title on top + one extra line for the last line wrap |
247 | Height = computedOptimalHeight; |
|
224 | Height = (int)Math.Round(size.Height) + labelTitle.Height + (int)Math.Round(htmlPanel1.Font.GetHeight()); |
248 | } |
|
225 | } |
249 | } |
|
Line 226... | Line 250... | |||
226 | } |
250 | } |
|
Line 365... | Line 389... | |||
365 | Debug.WriteLine("Error in form click event."); |
389 | Debug.WriteLine("Error in form click event."); |
|
366 | } |
390 | } |
|
367 | } |
391 | } |
|
Line 368... | Line 392... | |||
368 | |
392 | |
|
- | 393 | #endregion |
||
- | 394 | |
||
- | 395 | private void htmlPanel1_TextChanged(object sender, EventArgs e) |
||
- | 396 | { |
||
- | 397 | |
||
369 | #endregion |
398 | } |
|
370 | } |
399 | } |
|
371 | } |
400 | } |