Changeset 13526


Ignore:
Timestamp:
Sep 24, 2012, 2:43:44 AM (10 years ago)
Author:
livings124
Message:

Make the stats window's localization-resizing code a bit more generic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/StatsWindowController.m

    r13492 r13526  
    8080    [fNumOpenedLabelField setStringValue: [NSLocalizedString(@"Program Started", "Stats window -> label") stringByAppendingString: @":"]];
    8181   
    82     //size all elements
     82    //size of all labels
    8383    const CGFloat oldWidth = [fUploadedLabelField frame].size.width;
    8484   
    85     [fUploadedLabelField sizeToFit];
    86     [fDownloadedLabelField sizeToFit];
    87     [fRatioLabelField sizeToFit];
    88     [fTimeLabelField sizeToFit];
    89     [fNumOpenedLabelField sizeToFit];
    90    
    91     CGFloat maxWidth = MAX([fUploadedLabelField frame].size.width, [fDownloadedLabelField frame].size.width);
    92     maxWidth = MAX(maxWidth, [fRatioLabelField frame].size.width);
    93     maxWidth = MAX(maxWidth, [fTimeLabelField frame].size.width);
    94     maxWidth = MAX(maxWidth, [fNumOpenedLabelField frame].size.width);
    95    
    96     NSRect frame = [fUploadedLabelField frame];
    97     frame.size.width = maxWidth;
    98     [fUploadedLabelField setFrame: frame];
    99    
    100     frame = [fDownloadedLabelField frame];
    101     frame.size.width = maxWidth;
    102     [fDownloadedLabelField setFrame: frame];
    103    
    104     frame = [fRatioLabelField frame];
    105     frame.size.width = maxWidth;
    106     [fRatioLabelField setFrame: frame];
    107    
    108     frame = [fTimeLabelField frame];
    109     frame.size.width = maxWidth;
    110     [fTimeLabelField setFrame: frame];
    111    
    112     frame = [fNumOpenedLabelField frame];
    113     frame.size.width = maxWidth;
    114     [fNumOpenedLabelField setFrame: frame];
     85    NSArray * labels = @[fUploadedLabelField, fDownloadedLabelField, fRatioLabelField, fTimeLabelField, fNumOpenedLabelField];
     86   
     87    CGFloat maxWidth = CGFLOAT_MIN;
     88    for (NSTextField * label in labels)
     89    {
     90        [label sizeToFit];
     91       
     92        const CGFloat width = [label frame].size.width;
     93        maxWidth = MAX(maxWidth, width);
     94    }
     95   
     96    for (NSTextField * label in labels)
     97    {
     98        NSRect frame = [label frame];
     99        frame.size.width = maxWidth;
     100        [label setFrame: frame];
     101    }
    115102   
    116103    //resize window for new label width - fields are set in nib to adjust correctly
Note: See TracChangeset for help on using the changeset viewer.