Mercurial > dwindows
changeset 2423:b4cb136b5222
iOS: Special handling for combined text/image buttons like check and radio
buttons.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 04 Apr 2021 15:05:45 +0000 |
parents | 4a353a83b2e4 |
children | 6b302a8c856f |
files | ios/dw.m |
diffstat | 1 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ios/dw.m Sun Apr 04 01:23:56 2021 +0000 +++ b/ios/dw.m Sun Apr 04 15:05:45 2021 +0000 @@ -3218,21 +3218,28 @@ /* Handle all the different button types */ if([ object isMemberOfClass:[ DWButton class ] ]) { - UIImage *image = (UIImage *)[object image]; + UIImage *image = (UIImage *)[object imageForState:UIControlStateNormal]; if(image) { /* Image button */ CGSize size = [image size]; - extrawidth = (int)size.width; - extraheight = (int)size.height; + extrawidth = (int)size.width + 1; + /* Height isn't additive */ + thisheight = (int)size.height + 1; } /* Text button */ nsstr = [[object titleLabel] text]; if(nsstr && [nsstr length] > 0) { - extrawidth += 8; + /* With combined text/image we seem to + * need a lot of additional width space. + */ + if(image) + extrawidth += 30; + else + extrawidth += 8; extraheight += 4; } } @@ -3306,7 +3313,10 @@ thisheight = _DW_SCROLLED_MAX_HEIGHT; } else if([ object isKindOfClass:[UILabel class] ]) + { nsstr = [object text]; + extrawidth = extraheight = 2; + } /* Any other control type */ else if([ object isKindOfClass:[ UIControl class ] ]) nsstr = [object text]; @@ -3315,7 +3325,16 @@ * calculate the size with the current font. */ if(nsstr && [nsstr length]) - dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &thiswidth, &thisheight); + { + int textwidth, textheight; + + dw_font_text_extents_get(object, NULL, (char *)[nsstr UTF8String], &textwidth, &textheight); + + if(textheight > thisheight) + thisheight = textheight; + if(textwidth > thiswidth) + thiswidth = textwidth; + } /* Handle static text fields */ if([object isKindOfClass:[ UITextField class ]] && ![object isEditable]) @@ -5104,7 +5123,8 @@ } NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; /* If we didn't get a font from the pixmap... try the associated object */ - if(!font && ([object isMemberOfClass:[DWRender class]] || [object isKindOfClass:[UIControl class]])) + if(!font && ([object isMemberOfClass:[DWRender class]] || [object isKindOfClass:[UIControl class]] + || [object isKindOfClass:[UILabel class]])) { font = [object font]; }