Recent

Author Topic: [SOLVED] Unable to change the font in TStatusBar  (Read 1431 times)

jipété

  • New Member
  • *
  • Posts: 43
[SOLVED] Unable to change the font in TStatusBar
« on: October 07, 2022, 07:15:46 pm »
Hi,

Just noticed the following : no way to change the size of the font (UseSystemFont is False, as is ParentFont), no way to display the good glyph when changing the default font.

See attached picture (top is design mode, bottom is running mode).

OS : Debian 11.5 Lazarus 2.2.2
Really disappointed...
« Last Edit: October 09, 2022, 01:20:13 pm by jipété »

krolikbest

  • Full Member
  • ***
  • Posts: 181
Re: Unable to change the font in TStatusBar
« Reply #1 on: October 08, 2022, 10:49:14 pm »
Hi,
win7, Laz 2.0.10. Well, having my configuration there is not any problem..

jipété

  • New Member
  • *
  • Posts: 43
Re: Unable to change the font in TStatusBar
« Reply #2 on: October 08, 2022, 11:59:57 pm »
Sure, but with Linux we have many other problems, that's life...

Look at the bottom-right corner if I change the color of the form:

And look at the same place if I play with Size Grip True (top) or False (bottom, image x 2).

Tired, really tired...

Fred vS

  • Hero Member
  • *****
  • Posts: 2836
    • StrumPract is the musicians best friend
Re: Unable to change the font in TStatusBar
« Reply #3 on: October 09, 2022, 12:40:16 am »
With MSEgui, no problems on Linux nor on Windows.

 ;)
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

paweld

  • Hero Member
  • *****
  • Posts: 521
Re: Unable to change the font in TStatusBar
« Reply #4 on: October 09, 2022, 08:02:06 am »
Unfortunately it doesn't work, but it's very easy to fix by setting Style to psOwnerDraw and handling the panel drawing:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   Width := 600;
  6.   StatusBar1.AutoSize := False;
  7.   StatusBar1.Height := 40;
  8.   StatusBar1.Font.Name := 'Quicksand';
  9.   StatusBar1.Font.Size := 16;
  10.   StatusBar1.Font.Style := [fsBold, fsItalic, fsUnderline];
  11.   for i := 0 to 2 do
  12.   begin
  13.     with StatusBar1.Panels.Add do
  14.     begin
  15.       Alignment := TAlignment(i);
  16.       Style := psOwnerDraw;
  17.       Width := 200;
  18.       Text := 'Panel ' + IntToStr(i);
  19.     end;
  20.   end;
  21.   StatusBar1.OnDrawPanel := @StatusBar1DrawPanel;
  22. end;
  23.  
  24. procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  25.   Panel: TStatusPanel; const Rect: TRect);
  26. var
  27.   w, h, x, y: Integer;
  28. begin
  29.   StatusBar.Canvas.Brush.Color := Form1.Color;
  30.   StatusBar.Canvas.Font := StatusBar.Font;
  31.   StatusBar.Canvas.FillRect(Rect);
  32.   w := StatusBar.Canvas.TextWidth(Panel.Text);
  33.   case Panel.Alignment of
  34.     taLeftJustify: x := Rect.Left + 2;
  35.     taRightJustify: x := Rect.Right - 2 - w;
  36.     taCenter: x := Rect.Left + (Rect.Width - w) div 2;
  37.   end;
  38.   h := StatusBar.Canvas.TextHeight(Panel.Text);
  39.   y := Rect.Top + (Rect.Height - h) div 2;
  40.   StatusBar.Canvas.TextOut(x, y, Panel.Text);
  41. end;  
« Last Edit: October 09, 2022, 08:04:39 am by paweld »
Best regards
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 12170
Re: Unable to change the font in TStatusBar
« Reply #5 on: October 09, 2022, 09:50:45 am »
Note that at least on Windows this is by design: it is to protect programmers to write confetti GUI's.
Which we all love and hate.... 8-) O:-)
Manuals, manuals, manuals first.
You have incompetence and sheer incompetence.

jipété

  • New Member
  • *
  • Posts: 43
Re: Unable to change the font in TStatusBar
« Reply #6 on: October 09, 2022, 12:06:08 pm »
Hello,
it's very easy to fix
uh uh... Windows or Linux or both ?

At least, nothing works as fine as for you here (Linux) :
coz many values are setup in IDE, I've only used the following and, yes, stb is faster to write than StatusBar1, so :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   aSimpleText: string;
  4. begin
  5.   aSimpleText := 'A Simple Text';
  6.   // new stb work :
  7.   stb.Font.Name := 'Liberation Serif';
  8.   stb.Font.Size := 16;
  9.   with stb.Panels.Add do begin
  10.     Alignment := taLeftJustify;
  11.     Text := aSimpleText;
  12.   end;
  13.   stb.OnDrawPanel := @stbDrawPanel;
  14. end;
  15.  
and nothing works.
Just noticed that text in panel is badly centered, when I ask for LeftJustify...
The drawing procedure is yours.
« Last Edit: October 09, 2022, 12:08:04 pm by jipété »

paweld

  • Hero Member
  • *****
  • Posts: 521
Re: Unable to change the font in TStatusBar
« Reply #7 on: October 09, 2022, 12:36:15 pm »
Both, tested on Windows 10 and Debian.
Set Style to psOwnerDraw:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject); var
  2.   aSimpleText: string;
  3. begin
  4.   aSimpleText := 'A Simple Text';
  5.   // new stb work :
  6.   stb.Font.Name := 'Liberation Serif';
  7.   stb.Font.Size := 16;
  8.   with stb.Panels.Add do begin
  9.     Alignment := taLeftJustify;
  10.     Style := psOwnerDraw; //<-- Add this
  11.     Text := aSimpleText;
  12.   end;
  13.   stb.OnDrawPanel := @stbDrawPanel;
  14. end;
  15.  
Best regards
paweld

jipété

  • New Member
  • *
  • Posts: 43
Re: Unable to change the font in TStatusBar
« Reply #8 on: October 09, 2022, 12:46:29 pm »
Both, tested on Windows 10 and Debian.
Set Style to psOwnerDraw:
Code: Pascal  [Select][+][-]
  1.     Style := psOwnerDraw; //<-- Add this
  2.  
Big thanks !



« Last Edit: October 09, 2022, 01:15:50 pm by jipété »

paweld

  • Hero Member
  • *****
  • Posts: 521
Re: Unable to change the font in TStatusBar
« Reply #9 on: October 09, 2022, 12:59:22 pm »
Attached is a sample project - drawing works both for panels added in the IDE and in the code.
Best regards
paweld

jipété

  • New Member
  • *
  • Posts: 43
Re: Unable to change the font in TStatusBar
« Reply #10 on: October 09, 2022, 01:19:37 pm »
Thanks !

That's fine.
I made a mistake : working with a virtual machine and Laz 2.2.4 which is ok, and with the host and Laz 2.0.12, which is broken...
Time to update, I think.

Thanks again, I'll add "solved" to the title.

But there is a problem with the color and the SizeGrip :
I set ParentColor False
I change the color of the form, say clSkyBlue and the StatusBar becomes skyblue, see image.

The black line on top of StatusBar stops when entering the SizeGrip.
« Last Edit: October 09, 2022, 01:26:55 pm by jipété »

paweld

  • Hero Member
  • *****
  • Posts: 521
Re: [SOLVED] Unable to change the font in TStatusBar
« Reply #11 on: October 09, 2022, 01:53:33 pm »
Try this - add LCLType and LCLIntf to uses section:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  2.   Panel: TStatusPanel; const Rect: TRect);
  3. var
  4.   w, h, x, y: Integer;
  5. begin
  6.   StatusBar.Canvas.Brush.Color := Form1.Color;
  7.   StatusBar.Canvas.Font := StatusBar.Font;
  8.   case (Panel.Index mod 3) of
  9.     1: StatusBar.Canvas.Font.Color := clGreen;
  10.     2: StatusBar.Canvas.Font.Color := clRed;
  11.   end;
  12.   StatusBar.Canvas.FillRect(Rect);
  13.   //Panel.Alignment := taRightJustify;
  14.   w := StatusBar.Canvas.TextWidth(Panel.Text);
  15.   if StatusBar.SizeGrip and (Panel.Index = StatusBar.Panels.Count - 1) then //<--Add this
  16.     w := w + GetSystemMetrics(SM_CXVSCROLL);                                //<--Add this
  17.   case Panel.Alignment of
  18.     taLeftJustify: x := Rect.Left + 2;
  19.     taRightJustify: x := Rect.Right - 2 - w;
  20.     taCenter: x := Rect.Left + (Rect.Width - w) div 2;
  21.   end;
  22.   h := StatusBar.Canvas.TextHeight(Panel.Text);
  23.   y := Rect.Top + (Rect.Height - h) div 2;
  24.   StatusBar.Canvas.TextOut(x, y, Panel.Text);
  25. end;              
  26.  
« Last Edit: October 09, 2022, 02:28:25 pm by paweld »
Best regards
paweld

jipété

  • New Member
  • *
  • Posts: 43
Re: [SOLVED] Unable to change the font in TStatusBar
« Reply #12 on: October 09, 2022, 02:53:32 pm »
Hi,

1:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  2.   Panel: TStatusPanel; const Rect: TRect);
  3. var
  4.   w, h, x, y: Integer;
  5. begin
  6.   x := 0; // happy compilo  // <-- Add this
  7.   if StatusBar.ParentColor then // <-- Add this
  8.     StatusBar.Canvas.Brush.Color := Form1.Color;

2: no way to get a wider black line.
What is strange is the description in the help, saying, about the SM_Cxy/vhSCROLL const, "used to get...", not "used to set..."

3: if I try
Code: Pascal  [Select][+][-]
  1. w := w + GetSystemMetrics(SM_CXBORDER)+20;
I don't see a wider black line.
Maybe it's impossible to have a wider, nice line ?

Something cool would be to have that :
add LCLType and LCLIntf to uses section
definitively added to the Unit1 skeleton, so each new project will have these two units.

paweld

  • Hero Member
  • *****
  • Posts: 521
Re: [SOLVED] Unable to change the font in TStatusBar
« Reply #13 on: October 09, 2022, 03:22:54 pm »
In my Windows grip does not have borders, while I checked in Debian and the final version below works fine:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  2.   Panel: TStatusPanel; const Rect: TRect);
  3. var
  4.   w, h, x, y: Integer;
  5.   r: TRect;
  6. begin
  7.   r.Create(Rect);
  8.   if StatusBar.SizeGrip and (Panel.Index = StatusBar.Panels.Count - 1) then
  9.     r.Width := r.Width - GetSystemMetrics(SM_CXVSCROLL) - GetSystemMetrics(SM_CXBORDER);
  10.   StatusBar.Canvas.Brush.Color := Form1.Color;
  11.   StatusBar.Canvas.Font := StatusBar.Font;
  12.   case (Panel.Index mod 3) of
  13.     1: StatusBar.Canvas.Font.Color := clGreen;
  14.     2: StatusBar.Canvas.Font.Color := clRed;
  15.   end;
  16.   StatusBar.Canvas.FillRect(r);
  17.   Panel.Alignment := taRightJustify;
  18.   w := StatusBar.Canvas.TextWidth(Panel.Text);
  19.   case Panel.Alignment of
  20.     taLeftJustify: x := r.Left + 2;
  21.     taRightJustify: x := r.Right - 2 - w;
  22.     taCenter: x := r.Left + (r.Width - w) div 2;
  23.   end;
  24.   h := StatusBar.Canvas.TextHeight(Panel.Text);
  25.   y := r.Top + (r.Height - h) div 2;
  26.   StatusBar.Canvas.TextOut(x, y, Panel.Text);
  27. end;    
  28.  
Best regards
paweld

jipété

  • New Member
  • *
  • Posts: 43
Re: [SOLVED] Unable to change the font in TStatusBar
« Reply #14 on: October 09, 2022, 04:33:47 pm »
Well, I say "Stop", or we'll loose our time and our lifes trying to have a working TStatusBar which will drive us nuts...

The main statusbar displays a not-nice sizegrip (image1), and another statusbar added in a TPanel cannot display the sizegrip at all, whereas the objects' inspector shows us it is true for displaying it and explanation belows says that it is visible, which is really wrong, see image.

Have you seen the post of Fred vS ? https://forum.lazarus.freepascal.org/index.php/topic,60834.msg456440.html#msg456440
That's exactly what I want (image2) : a true StatusBar with an old school look'n'feel and a nice sizegrip.
« Last Edit: October 09, 2022, 04:35:40 pm by jipété »

 

TinyPortal © 2005-2018