Changeset 9214


Ignore:
Timestamp:
Sep 28, 2009, 3:49:02 PM (13 years ago)
Author:
livings124
Message:

right-align the peer counts in the tracker cells

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TrackerCell.m

    r9213 r9214  
    3535#define PADDING_BETWEEN_LINES 1.0
    3636#define PADDING_BETWEEN_LINES_ON_SAME_LINE 3.0
    37 #define COUNT_WIDTH 100.0
     37#define COUNT_WIDTH 40.0
    3838
    3939@interface TrackerCell (Private)
     
    4444- (NSRect) imageRectForBounds: (NSRect) bounds;
    4545- (NSRect) rectForNameWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
    46 - (NSRect) rectForCountWithString: (NSAttributedString *) string withAboveRect: (NSRect) nameRect inBounds: (NSRect) bounds;
     46- (NSRect) rectForCountWithString: (NSAttributedString *) string withAboveRect: (NSRect) aboveRect inBounds: (NSRect) bounds;
     47- (NSRect) rectForCountLabelWithString: (NSAttributedString *) string withRightRect: (NSRect) rightRect inBounds: (NSRect) bounds;
    4748- (NSRect) rectForStatusWithString: (NSAttributedString *) string withAboveRect: (NSRect) aboveRect withRightRect: (NSRect) rightRect
    4849            inBounds: (NSRect) bounds;
     
    135136   
    136137    //count strings
    137     NSString * seederBaseString = [NSLocalizedString(@"Seeders", "tracker peer stat") stringByAppendingFormat: @": %@",
    138                                     [node totalSeeders] != -1 ? [NSString stringWithFormat: @"%d", [node totalSeeders]]
    139                                                                 : NSLocalizedString(@"N/A", "tracker peer stat")];
     138    NSString * seederBaseString = [node totalSeeders] != -1 ? [NSString stringWithFormat: @"%d", [node totalSeeders]]
     139                                                            : NSLocalizedString(@"N/A", "tracker peer stat");
    140140    NSAttributedString * seederString = [self attributedStatusWithString: seederBaseString color: statusColor];
    141141    const NSRect seederRect = [self rectForCountWithString: seederString withAboveRect: nameRect inBounds: cellFrame];
    142142    [seederString drawInRect: seederRect];
    143143   
    144     NSString * leecherBaseString = [NSLocalizedString(@"Leechers", "tracker peer stat") stringByAppendingFormat: @": %@",
    145                                     [node totalLeechers] != -1 ? [NSString stringWithFormat: @"%d", [node totalLeechers]]
    146                                                                 : NSLocalizedString(@"N/A", "tracker peer stat")];
     144    NSString * leecherBaseString = [node totalLeechers] != -1 ? [NSString stringWithFormat: @"%d", [node totalLeechers]]
     145                                                                : NSLocalizedString(@"N/A", "tracker peer stat");
    147146    NSAttributedString * leecherString = [self attributedStatusWithString: leecherBaseString color: statusColor];
    148147    const NSRect leecherRect = [self rectForCountWithString: leecherString withAboveRect: seederRect inBounds: cellFrame];
    149148    [leecherString drawInRect: leecherRect];
    150149   
    151     NSString * downloadedBaseString = [NSLocalizedString(@"Downloaded", "tracker peer stat") stringByAppendingFormat: @": %@",
    152                                             [node totalDownloaded] != -1 ? [NSString stringWithFormat: @"%d", [node totalDownloaded]]
    153                                                                         : NSLocalizedString(@"N/A", "tracker peer stat")];
     150    NSString * downloadedBaseString = [node totalDownloaded] != -1 ? [NSString stringWithFormat: @"%d", [node totalDownloaded]]
     151                                                                    : NSLocalizedString(@"N/A", "tracker peer stat");
    154152    NSAttributedString * downloadedString = [self attributedStatusWithString: downloadedBaseString color: statusColor];
    155153    const NSRect downloadedRect = [self rectForCountWithString: downloadedString withAboveRect: leecherRect inBounds: cellFrame];
    156154    [downloadedString drawInRect: downloadedRect];
    157155   
     156    //count label strings
     157    NSString * seederLabelBaseString = [NSLocalizedString(@"Seeders", "tracker peer stat") stringByAppendingFormat: @": "];
     158    NSAttributedString * seederLabelString = [self attributedStatusWithString: seederLabelBaseString color: statusColor];
     159    const NSRect seederLabelRect = [self rectForCountLabelWithString: seederLabelString withRightRect: seederRect
     160                                        inBounds: cellFrame];
     161    [seederLabelString drawInRect: seederLabelRect];
     162   
     163    NSString * leecherLabelBaseString = [NSLocalizedString(@"Leechers", "tracker peer stat") stringByAppendingFormat: @": "];
     164    NSAttributedString * leecherLabelString = [self attributedStatusWithString: leecherLabelBaseString color: statusColor];
     165    const NSRect leecherLabelRect = [self rectForCountLabelWithString: leecherLabelString withRightRect: leecherRect
     166                                        inBounds: cellFrame];
     167    [leecherLabelString drawInRect: leecherLabelRect];
     168   
     169    NSString * downloadedLabelBaseString = [NSLocalizedString(@"Downloaded", "tracker peer stat") stringByAppendingFormat: @": "];
     170    NSAttributedString * downloadedLabelString = [self attributedStatusWithString: downloadedLabelBaseString color: statusColor];
     171    const NSRect downloadedLabelRect = [self rectForCountLabelWithString: downloadedLabelString withRightRect: downloadedRect
     172                                        inBounds: cellFrame];
     173    [downloadedLabelString drawInRect: downloadedLabelRect];
     174   
    158175    //status strings
    159176    NSAttributedString * lastAnnounceString = [self attributedStatusWithString: [node lastAnnounceStatusString] color: statusColor];
    160     const NSRect lastAnnounceRect = [self rectForStatusWithString: lastAnnounceString withAboveRect: nameRect withRightRect: seederRect
    161                                         inBounds: cellFrame];
     177    const NSRect lastAnnounceRect = [self rectForStatusWithString: lastAnnounceString withAboveRect: nameRect
     178                                        withRightRect: seederLabelRect inBounds: cellFrame];
    162179    [lastAnnounceString drawInRect: lastAnnounceRect];
    163180   
    164181    NSAttributedString * nextAnnounceString = [self attributedStatusWithString: [node nextAnnounceStatusString] color: statusColor];
    165182    const NSRect nextAnnounceRect = [self rectForStatusWithString: nextAnnounceString withAboveRect: lastAnnounceRect
    166                                         withRightRect: leecherRect inBounds: cellFrame];
     183                                        withRightRect: leecherLabelRect inBounds: cellFrame];
    167184    [nextAnnounceString drawInRect: nextAnnounceRect];
    168185   
    169186    NSAttributedString * lastScrapeString = [self attributedStatusWithString: [node lastScrapeStatusString] color: statusColor];
    170187    const NSRect lastScrapeRect = [self rectForStatusWithString: lastScrapeString withAboveRect: nextAnnounceRect
    171                                     withRightRect: downloadedRect inBounds: cellFrame];
     188                                    withRightRect: downloadedLabelRect inBounds: cellFrame];
    172189    [lastScrapeString drawInRect: lastScrapeRect];
    173190}
     
    248265}
    249266
    250 - (NSRect) rectForCountWithString: (NSAttributedString *) string withAboveRect: (NSRect) nameRect inBounds: (NSRect) bounds
     267- (NSRect) rectForCountWithString: (NSAttributedString *) string withAboveRect: (NSRect) aboveRect inBounds: (NSRect) bounds
    251268{
    252269    return NSMakeRect(NSMaxX(bounds) - PADDING_HORIZONAL - COUNT_WIDTH,
    253                         NSMaxY(nameRect) + PADDING_BETWEEN_LINES,
     270                        NSMaxY(aboveRect) + PADDING_BETWEEN_LINES,
    254271                        COUNT_WIDTH, [string size].height);
     272}
     273
     274- (NSRect) rectForCountLabelWithString: (NSAttributedString *) string withRightRect: (NSRect) rightRect inBounds: (NSRect) bounds
     275{
     276    NSRect result = rightRect;
     277    result.size.width = [string size].width;
     278    result.origin.x -= result.size.width;
     279   
     280    return result;
    255281}
    256282
Note: See TracChangeset for help on using the changeset viewer.