twitter/twui — Issue #101: Automatic OS detection and screen scale factors.
Author: galaxas0
Created: 2012-03-03 04:55:37+00:00
State: open

Wouldn't it be far better to do something like:

TUIKit.h:

// Test for Lion support.
extern BOOL isAtleastLion(void);

// Set and get global screen scale factor.
extern float screenScale(void);
extern void setScreenScale(float);

TUIKit.m:

static BOOL initialized = NO;
static float screen_scale = 0.0;
static BOOL is_lion = NO;

BOOL isAtleastLion() {
if(!initialized) {
SInt32 major = 0;
SInt32 minor = 0;
Gestalt(gestaltSystemVersionMajor, &major);
Gestalt(gestaltSystemVersionMinor, &minor);
if((major == 10 && minor >= 7) || major >= 11) {
is_lion = YES;
} else is_lion = NO;

initialized = YES;
} return is_lion;
}

float screenScale() {
if(screen_scale <= CGFLOAT_MIN)
screen_scale = [[NSScreen mainScreen] userSpaceScaleFactor];

return screen_scale;
}

void setScreenScale(float scale) {
if((scale > CGFLOAT_MIN)) {
screen_scale = scale;
}
}

To abstract the screen scaling and OS detection away from the end developer?
What I did was move all TUIGraphics* functions into a new .h/.m TUIGraphics.m, and add those functions into TUIKit.h/.m. Then I proceeded to remove #import "TUIKit.h"'s and replaced them with #import "TUIGraphics.h" to make more sense.