How to determine required button width based on caption?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #33103
    OldGrumpy
    Participant

    Hi there,

    when skins are active, a button is sometimes noticeably larger than “normal”. And depending on the text on the button, I need to resize some buttons. So I need a way to determine how much space the caption requires to size the button accordingly, and I need to know the total size of the button to make the buttons fit nicely. I can retrieve the required space for the caption via DrawTextW API, but how can I get the total dimension of the button?

    #39869
    Support
    Keymaster

    AlphaSkins do not changes a sizes of such controls like buttons or edits. Could you show a little demo? )

    #39889
    OldGrumpy
    Participant

    QUOTE (Support @ Jul 10 2009, 10:30 AM)
    AlphaSkins do not changes a sizes of such controls like buttons or edits. Could you show a little demo? )

    Some skins have thicker borders on buttons and other controls, so that buttons with only small gaps between them look like stuffed together. I'll try to make a demo to illustrate it. Furthermore, some skins (e.g. “Cold”) make the buttons look slightly trapezoidal. Basically, I am looking for a feature that tells me “this button will accept a text of x pixels width without wrap-around”. Or are these values exactly the same as for unskinned buttons? My tests with the “Cold” skin seemed to show that there are slight differences.

    #39916
    Support
    Keymaster

    Size of button and position of content are same as in standard mode.
    Maybe some visual illusion exists when skinned borders is drawn.

    #40161
    OldGrumpy
    Participant

    Yes, all borders are drawn inside the button rect. That leads me to a slightly changed question: Can I somehow determine the “client rect” of a skinned button? I mean the area that remains free for text. In some skins I have the effect that the button text reaches into the border area and that looks ugly. If I could determine the border width, I could adjust the button size accordingly to make the text fit nicely.

    #40162
    Neon
    Participant

    You may tamper with sGraphUtils functions. For example, function CutText has saved me a lot of time when I tried to ellipse caption of TsTabSheet.

    #40227
    Support
    Keymaster

    The SkinManager component have four functions :

    CODE
        function MaskWidthTop(MaskIndex : integer) : integer;
        function MaskWidthLeft(MaskIndex : integer) : integer;
        function MaskWidthBottom(MaskIndex : integer) : integer;
        function MaskWidthRight(MaskIndex : integer) : integer;


    These functions returns a width of top, left, bottom and right borders of controls. MaskIndex may be found in AlphaControl(YourButton).SkinData.BorderIndex
    So, you can use code like this :

    CODE
    with sSkinManager1
      do BtnClientRect := Rect(
        MaskWidthLeft(sBtn1.Skindata.BorderIndex),
        MaskWidthTop(sBtn1.Skindata.BorderIndex),
        sBtn1.Width – MaskWidthRight(sBtn1.Skindata.BorderIndex),
        sBtn1.Height – MaskWidthBottom(sBtn1.Skindata.BorderIndex)
      );


    I hope this info can help you.
    If problem will not be solved please write me again.

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