Recent

Author Topic: Button always has center alignment  (Read 6896 times)

elioenaishalom

  • New Member
  • *
  • Posts: 28
Button always has center alignment
« on: July 30, 2013, 03:22:30 pm »
Can anyone help me how to add alignment property to TSpeedButton caption (left, center and right justify) - Button always has center alignment

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Button always has center alignment
« Reply #1 on: July 30, 2013, 03:49:11 pm »
You can change Margin property to something > -1. It will align Caption to the left (or to the right if it BiDi mode is RightToLeft).
If you want full alignment, probably the best way is to change the flags. Caption is painted via ThemeServices.DrawText, so you will change flags DT_CENTER and DT_VCENTER to DT_TOP, DT_LEFT, DT_BOTTOM or DT_RIGHT. It will align the text to the edges of the control rectangle.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

elioenaishalom

  • New Member
  • *
  • Posts: 28
Re: Button always has center alignment
« Reply #2 on: July 30, 2013, 05:18:11 pm »
Mr. Blaazen,
I appreciate the attention and readiness to respond.
It does not seem so easy for me to use ThemeServices.DrawText - I've read the documentation on lazarus http://wiki.freepascal.org/Theme_library and the post http://forum.lazarus.freepascal.org/index.php?topic=21526.0.
For now I'll use the Margin, but if you can have patience for more detail how to write the TSpeedButton.Caption changing the default alignment I am very grateful because my power is not enough to translate the example for the component.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Button always has center alignment
« Reply #3 on: July 30, 2013, 06:43:07 pm »
The important part is in method TCustomSpeedButton.MeasureDraw in file speedbutton.inc on line 675-681:
Code: [Select]

      TextFlags := DT_LEFT or DT_TOP;
      if UseRightToLeftReading then
        TextFlags := TextFlags or DT_RTLREADING;

      if Draw then
        ThemeServices.DrawText(Canvas, DrawDetails, Caption, PaintRect,
          TextFlags, 0);       
All you need is to modify and add a case .. of construction:
Code: [Select]
case Alignment of
  alTop: TextFlags := TextFlags or DT_TOP;
  alRight: TextFlags := TextFlags or DT_RIGHT;
  //etc. for other positions
end;
And test, test, test for all possible combinantions, i.e. with glyph, without glyph, LeftToRight, RightToLeft, glyph only (no caption) etc.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

elioenaishalom

  • New Member
  • *
  • Posts: 28
Re: Button always has center alignment
« Reply #4 on: August 02, 2013, 08:56:48 pm »
Not enough words to thank your attention - I'll try asap ...

 

TinyPortal © 2005-2018