DougHennig / Ribbon

A Microsoft Office 365-like ribbon control for VFP forms
24 stars 11 forks source link

Wrong control width when Button caption is empty #13

Closed VfpImaging closed 1 year ago

VfpImaging commented 1 year ago

Buttons are getting a fixed value of 100 pixels when the button caption is empty. Fix:

In SfRibbonToolbarButton.CalculateWidth, added code to deal with the empty Caption:

LOCAL lnWidth

DO CASE CASE NOT EMPTY(THIS.CAPTION) IF THIS.WORDWRAP THIS.oGDI.SETSIZE(THIS.LBLBUTTON.WIDTH, THIS.LBLBUTTON.HEIGHT) ENDIF THIS.WORDWRAP THIS.oGDI.MEASURESTRING(THIS.LBLBUTTON.CAPTION) m.lnWidth = MAX(CEILING(THIS.oGDI.nWidth) + 2 THIS.LBLBUTTON.LEFT, ; THIS.IMGBUTTON.WIDTH + 2 THIS.Padding) && use a width of the label or the image, whichever is wider && This.lblButton.Width is inaccurate if the form isn't visible yet IF THIS.WIDTH <> m.lnWidth AND NOT THIS.WORDWRAP THIS.WIDTH = m.lnWidth THIS.LBLBUTTON.WIDTH = THIS.WIDTH - 2 * THIS.LBLBUTTON.LEFT ENDIF THIS.WIDTH <> m.lnWidth ... THIS.IMGBUTTON.LEFT = INT((THIS.WIDTH - THIS.IMGBUTTON.WIDTH) / 2) && center the image

    * If there's one line of text, center the down button below the label.

    IF THIS.oGDI.nLines = 1
        THIS.IMGDOWN.LEFT = INT((THIS.WIDTH - THIS.IMGDOWN.WIDTH) / 2)
        THIS.IMGDOWN.TOP  = THIS.LBLBUTTON.TOP  + 24
    ELSE
        THIS.IMGDOWN.LEFT = THIS.LBLBUTTON.LEFT + THIS.LBLBUTTON.WIDTH  - 5
        THIS.IMGDOWN.TOP  = THIS.LBLBUTTON.TOP  + THIS.LBLBUTTON.HEIGHT - 10
    ENDIF THIS.oGDI.nLines = 1
    THIS.nLines = THIS.oGDI.nLines
    THIS.PARENT.CalculateWidth()

ENDCASE

DougHennig commented 1 year ago

Fixed in the latest build. Thanks for providing the fix!