Recent

Author Topic: LazarusToastMessage  (Read 3721 times)

szlbz

  • New Member
  • *
  • Posts: 39
LazarusToastMessage
« on: May 18, 2024, 03:44:28 am »
下载地址:
https://github.com/szlbz/LazarusToastMessage

基于pcplayer版本,修改后适用于lazarus,并可以跨平台使用
1、根据显示内容调整totast的宽度和高度,防止显示内容不完整。
2024-05-15:
显示方向增加左右上下居中
2024-05-14:
1、将System.NetEncoding改用Base64
2、增加从form底向上移动

秋风 2024-05-12
« Last Edit: May 18, 2024, 04:37:51 am by szlbz »

Handoko

  • Hero Member
  • *****
  • Posts: 5375
  • My goal: build my own game engine using Lazarus
Re: LazarusToastMessage
« Reply #1 on: May 18, 2024, 06:38:40 am »
Nice!
Thank you for sharing it.

I saw you hardcoded the font name Segoe UI, but not all computers have this font installed.
Code: Pascal  [Select][+][-]
  1.   Title.Font.Name   := 'Segoe UI';

szlbz

  • New Member
  • *
  • Posts: 39
Re: LazarusToastMessage
« Reply #2 on: May 18, 2024, 09:33:16 am »
谢谢,字体已改为 :default
Code: Pascal  [Select][+][-]
  1.   Title.Font.Name   := 'default';

Handoko

  • Hero Member
  • *****
  • Posts: 5375
  • My goal: build my own game engine using Lazarus
Re: LazarusToastMessage
« Reply #3 on: May 18, 2024, 12:03:14 pm »
I would recommend to use multiple if-statements to find an available font, for example:

Code: Pascal  [Select][+][-]
  1. const
  2.   Font1 = 'Segoe UI';
  3.   Font2 = 'Verdana'; // Available in WinXP .. Win11
  4.   Font3 = 'Liberation Sans'; // Available in most Linuxes
  5.  
  6. // ...
  7. begin
  8.   S := 'default';
  9.   if Screen.Fonts.IndexOf(Font1) >= 0 then
  10.     S := Font1
  11.   else
  12.     if Screen.Fonts.IndexOf(Font2) >= 0 then
  13.       S := Font2
  14.     else
  15.       if Screen.Fonts.IndexOf(Font3) >= 0 then
  16.         S := Font3;
  17.   Title.Font.Name := S;
  18. end;

dseligo

  • Hero Member
  • *****
  • Posts: 1406
Re: LazarusToastMessage
« Reply #4 on: May 18, 2024, 05:26:13 pm »
Nice 8)

I noticed one 'glitch'.
Sometimes when you 'ToastIt', on the upper-middle position window shows for a split second before started showing in the right position.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   TToastMessage.ToastIt(Self, tpInfo, 'Proba', 'Ovo je poruka 2', 2);
  4. end;

Other than that, you have (probably) lapsus in the name 'RealseMe' - did you mean ReleaseMe?
Can you give example when this procedure is supposed to be called?

szlbz

  • New Member
  • *
  • Posts: 39
Re: LazarusToastMessage
« Reply #5 on: May 19, 2024, 12:46:34 am »
Quote
Sometimes when you 'ToastIt', on the upper-middle position window shows for a split second before started showing in the right position.
--我要检查一下

'RealseMe' -Spelling error,Change to:  ReleaseMe
Code: Pascal  [Select][+][-]
  1. initialization
  2.  
  3. finalization
  4.   TToastMessage.ReleaseMe;
  5.  
  6. end.  

szlbz

  • New Member
  • *
  • Posts: 39
Re: LazarusToastMessage
« Reply #6 on: May 19, 2024, 09:59:56 am »
Nice 8)

I noticed one 'glitch'.
Sometimes when you 'ToastIt', on the upper-middle position window shows for a split second before started showing in the right position.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   TToastMessage.ToastIt(Self, tpInfo, 'Proba', 'Ovo je poruka 2', 2);
  4. end;
Other than that, you have (probably) lapsus in the name 'RealseMe' - did you mean ReleaseMe?
Can you give example when this procedure is supposed to be called?
LazarusToastMessage已更新,请重新下载

dseligo

  • Hero Member
  • *****
  • Posts: 1406
Re: LazarusToastMessage
« Reply #7 on: May 19, 2024, 12:40:07 pm »
Nice 8)

I noticed one 'glitch'.
Sometimes when you 'ToastIt', on the upper-middle position window shows for a split second before started showing in the right position.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   TToastMessage.ToastIt(Self, tpInfo, 'Proba', 'Ovo je poruka 2', 2);
  4. end;
Other than that, you have (probably) lapsus in the name 'RealseMe' - did you mean ReleaseMe?
Can you give example when this procedure is supposed to be called?
LazarusToastMessage已更新,请重新下载

It seems that is working great now, thanks.

I have one more suggestion. Toast direction is now integer (parameter TD in ToastIt procedure). IMHO, it would be better if you'd create enumerated type for this, something like this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TToastDirection = (tdTopLeft, tdTopCenter, tdTopRight, tdBottomLeft, tdBottomCenter, tdBottomRight);

szlbz

  • New Member
  • *
  • Posts: 39
Re: LazarusToastMessage
« Reply #8 on: May 19, 2024, 01:30:21 pm »
Code: Pascal  [Select][+][-]
  1. procedure TToastMessage.Animate(Sender: TObject);
  2. var
  3.   PanelBoxMaxTop,PanelBoxMinTop:integer;
  4. begin
  5.   //Tag 0 Show
  6.   if PanelBox.Tag = 0 then
  7.   begin
  8.     PanelBox.Visible := True;
  9.     if (ToastDirection=tdTopCenter) or (ToastDirection=tdBottomCenter) then  //居中
  10.       PanelBox.Left := Trunc(((Self.PanelBox.Parent as TForm).Width / 2) - (PanelBox.Width / 2));
  11.  
  12.     if (ToastDirection=tdTopLeft) or (ToastDirection=tdBottomLeft) then  //左对齐
  13.       PanelBox.Left := 7;
  14.  
  15.     if (ToastDirection=tdTopRight) or (ToastDirection=tdBottomRight) then  //右对齐
  16.       PanelBox.Left := ((Self.PanelBox.Parent as TForm).Width) - PanelBox.Width-7;
  17.  
  18.     if (ToastDirection=tdBottomCenter) or (ToastDirection=tdBottomLeft) or (ToastDirection=tdBottomRight) then  //从屏幕底向上
  19.     begin
  20.       dec(ToastHeith);
  21.       PanelBoxMaxTop:=(Self.PanelBox.Parent as TForm).Height-abs(MinTop)-MaxTop;
  22.       PanelBox.Top := ToastHeith ;
  23.     end;
  24.     if (ToastDirection=tdTopCenter) or (ToastDirection=tdTopLeft) or (ToastDirection=tdTopRight) then //从屏幕顶向下
  25.     begin
  26.       PanelBoxTop:= PanelBoxTop+1;
  27.       PanelBoxMaxTop:= MaxTop;
  28.       PanelBox.Top :=PanelBoxTop;
  29.     end;
  30.  
谢谢你的建议,已更新

dseligo

  • Hero Member
  • *****
  • Posts: 1406
Re: LazarusToastMessage
« Reply #9 on: May 19, 2024, 03:03:41 pm »
谢谢你的建议,已更新

Thank you.

 

TinyPortal © 2005-2018