From 7187b8fcc22f915f42da6873079c79969b031b03 Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Thu, 12 Feb 2015 15:34:54 +0000 Subject: Cleaner implementation of metrics for radiobuttons and checkbuttons under Cocoa; still a bit of extra padding required, but only when absolutely necessary --- macosx/tkMacOSXButton.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 763f544..9c2196f 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -296,24 +296,6 @@ TkpComputeButtonGeometry( haveImage = 1; } - /*Tk Aqua can't handle metrics for radiobuttons and checkbuttons with images unless they are set first. These are derived from experimentation.*/ - if (haveImage && !haveText) { - switch (butPtr->type) { - case TYPE_RADIO_BUTTON: - width = butPtr->width; - width +=50; - break; - case TYPE_CHECK_BUTTON: - width = butPtr->width; - width +=50; - break; - case TYPE_BUTTON: - width = butPtr->width; - width += 0; - break; - } - } - if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) { Tk_FreeTextLayout(butPtr->textLayout); butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont, @@ -396,16 +378,37 @@ TkpComputeButtonGeometry( width += 2 * butPtr->padX; height += 2 * butPtr->padY; - - /* Need special handling for radiobuttons and checkbuttons: the text is drawn right on top of the button unless we expand the width. This is not perfect; some radiobuttons may render on top anyway. Need to find a better solution to calculate average text width.*/ + /* Need special handling for radiobuttons and checkbuttons: + the text and images is drawn right on top of the button unless + we expand the width. This is not perfect; some radiobuttons may render + on top anyway. + */ switch (butPtr->type) { case TYPE_RADIO_BUTTON: - width += 50; + /*Pad radiobutton by 50 to ensure image does not draw right over + radiobutton on left.*/ + if (butPtr->image != None) { + width += 50; + } else if (butPtr->bitmap != None) { + width +=50; + } else { + /*If just text, just add width of string.*/ + width += txtWidth; + } break; case TYPE_CHECK_BUTTON: - width += 50; + /*No padding required here.*/ + if (butPtr->image != None) { + width += 0; + } else if (butPtr->bitmap != None) { + width +=0; + } else { + /*If just text, just add width of string.*/ + width += txtWidth; + } break; } + /* * Now figure out the size of the border decorations for the button. -- cgit v0.12 From ea244cc080877648787abafed6ca504c8d6a6e10 Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Thu, 12 Feb 2015 16:01:25 +0000 Subject: Limit hard-coded padding in Cocoa buttons to radiobuttons indicatorOn --- macosx/tkMacOSXButton.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 9c2196f..09027fe 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -378,19 +378,27 @@ TkpComputeButtonGeometry( width += 2 * butPtr->padX; height += 2 * butPtr->padY; - /* Need special handling for radiobuttons and checkbuttons: + /* Need special handling for radiobuttons and checkbuttons: the text and images is drawn right on top of the button unless we expand the width. This is not perfect; some radiobuttons may render on top anyway. */ switch (butPtr->type) { case TYPE_RADIO_BUTTON: - /*Pad radiobutton by 50 to ensure image does not draw right over - radiobutton on left.*/ + /*Pad radiobutton by 50 if indicatorOn to ensure image does not draw + right over radiobutton on left.*/ if (butPtr->image != None) { - width += 50; + if (butPtr->indicatorOn) { + width += 50; + } else { + width += 0; + } } else if (butPtr->bitmap != None) { - width +=50; + if (butPtr->indicatorOn) { + width += 50; + } else { + width += 0; + } } else { /*If just text, just add width of string.*/ width += txtWidth; @@ -408,7 +416,6 @@ TkpComputeButtonGeometry( } break; } - /* * Now figure out the size of the border decorations for the button. -- cgit v0.12 From 7b2a9f3e0e3a52a26c1fcb28818f8b0a988ce5b3 Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Thu, 12 Feb 2015 16:14:57 +0000 Subject: Apply same padding fix to Cocoa checkbuttons --- macosx/tkMacOSXButton.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 09027fe..4dddcf9 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -405,11 +405,20 @@ TkpComputeButtonGeometry( } break; case TYPE_CHECK_BUTTON: - /*No padding required here.*/ + /*Pad checkbutton by 50 if indicatorOn to ensure image does not draw + right over radiobutton on left.*/ if (butPtr->image != None) { - width += 0; + if (butPtr->indicatorOn) { + width += 50; + } else { + width += 0; + } } else if (butPtr->bitmap != None) { - width +=0; + if (butPtr->indicatorOn) { + width += 50; + } else { + width += 0; + } } else { /*If just text, just add width of string.*/ width += txtWidth; -- cgit v0.12