TsSpeedButton getting the max. available width of caption

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35919
    remsi
    Participant

    Hello!

    Since version 8.48 I have a problem with the alignment of the TsSpeedButton's caption:

    I have my own function taking care of wrapping the words of the caption following some complex rules.

    Before version 8.48 it was sufficient to determine the maximum available width for the caption using MySpeedButton.Width – 8 (which is actually not a good solution).

    This solution no longer works because now the caption is automatically wordwrapped resulting in some messy layout.

    Quick and dirty:

    Is it possible to disable the automatic wrapping? Setting MySpeedButton.WordWrap := false will also ignore the CR-LF I placed.

    or

    The better way:

    How can I get the maximum available width of a TsSpeedButton's caption?

    MaxCaptionWidth might do the trick (for non-empty captions) but it does not seem to be accessible from outside unit sSpeedButton…

    By the way it seems that I have the same wordwrap-problem with TsButton.

    Greetings,

    Clemens

    #51083
    Support
    Keymaster

    Hello!

    'remsi' wrote:
    I have my own function taking care of wrapping the words of the caption following some complex rules.

    Before version 8.48 it was sufficient to determine the maximum available width for the caption using MySpeedButton.Width – 8 (which is actually not a good solution).

    This solution no longer works because now the caption is automatically wordwrapped resulting in some messy layout.

    You can calculate maximal allowed width of text using this code:

    Code:
    uses ComCtrls;

    function GetMaxTextWidth(Btn: TsSpeedButton): integer;
    var
    iGlyphWidth, iMargin: integer;
    begin
    with Btn do begin
    if (Glyph <> nil) then
    iGlyphWidth := Glyph.Width div NumGlyphs
    else
    if Assigned(Images) then
    iGlyphWidth := Images.Width div NumGlyphs
    else
    iGlyphWidth := 0;

    if Margin < 0 then
    iMargin := 0
    else
    iMargin := Margin + 3;

    Result := Width – 16 * integer(ButtonStyle = tbsDropDown) – iGlyphWidth – Spacing * integer((iGlyphWidth > 0) and (Caption <> '')) – iMargin * 2;
    end;
    end;

    Same code should work for TsBitBtn too.

    Quote:
    Quick and dirty:

    Is it possible to disable the automatic wrapping? Setting MySpeedButton.WordWrap := false will also ignore the CR-LF I placed.

    CR-LF is working always, even if WordWrap property is False.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.