mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-22 14:35:52 +00:00
Clean up the interface a bit to consolidate ThemeState methods onto one object. Keep CPThemeState as just a helper function.
This commit is contained in:
1 parent
b0d90bb612
commit
745ad7cc34
4 files changed
+36
-36
No files matched your search
+1
-1
@@ -733,7 +733,7 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
|
||||
var themeState = _themeState;
|
||||
|
||||
if (NAMES_FOR_PARTS[_hitPart] + "-color" !== anAttributeName)
|
||||
themeState = CPThemeState.subtractThemeStates(themeState, CPThemeStateHighlighted);
|
||||
themeState = ThemeState.subtractThemeStates(themeState, CPThemeStateHighlighted);
|
||||
|
||||
return [self valueForThemeAttribute:anAttributeName inState:themeState];
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ CPSegmentSwitchTrackingMomentary = 2;
|
||||
[_segments[aSegment] setEnabled:shouldBeEnabled];
|
||||
|
||||
if (shouldBeEnabled)
|
||||
_themeStates[aSegment] = CPThemeState.subtractThemeStates(_themeStates[aSegment], CPThemeStateDisabled);
|
||||
_themeStates[aSegment] = ThemeState.subtractThemeStates(_themeStates[aSegment], CPThemeStateDisabled);
|
||||
else
|
||||
_themeStates[aSegment] = CPThemeState(_themeStates[aSegment], CPThemeStateDisabled);
|
||||
|
||||
@@ -479,7 +479,7 @@ CPSegmentSwitchTrackingMomentary = 2;
|
||||
if (shouldHighlight)
|
||||
_themeStates[aSegment] = CPThemeState(_themeStates[aSegment], CPThemeStateHighlighted);
|
||||
else
|
||||
_themeStates[aSegment] = CPThemeState.subtractThemeStates(_themeStates[aSegment], CPThemeStateHighlighted);
|
||||
_themeStates[aSegment] = ThemeState.subtractThemeStates(_themeStates[aSegment], CPThemeStateHighlighted);
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
+32
-32
@@ -316,7 +316,7 @@ var CPThemeNameKey = @"CPThemeNameKey",
|
||||
|
||||
/*!
|
||||
* ThemeStates are immutable objects representing a particular ThemeState. Applications should never be creating
|
||||
* ThemeStates directly but should instead use the CPThemeState helper methods.
|
||||
* ThemeStates directly but should instead use the CPThemeState function.
|
||||
*/
|
||||
function ThemeState(stateNames)
|
||||
{
|
||||
@@ -384,6 +384,36 @@ ThemeState.prototype.isSubsetOf = function(aState)
|
||||
return true;
|
||||
}
|
||||
|
||||
ThemeState.subtractThemeStates = function(aState1, aState2)
|
||||
{
|
||||
if (aState2 === undefined || aState2 === nil || aState2 === [CPNull null])
|
||||
return aState1;
|
||||
|
||||
var newStates = {};
|
||||
for (var stateName in aState1._stateNames)
|
||||
{
|
||||
if (!aState1._stateNames.hasOwnProperty(stateName))
|
||||
continue;
|
||||
|
||||
if (!aState2._stateNames[stateName])
|
||||
newStates[stateName] = true;
|
||||
}
|
||||
|
||||
return ThemeState._cacheThemeState(new ThemeState(newStates));
|
||||
}
|
||||
|
||||
ThemeState._cacheThemeState = function(aState)
|
||||
{
|
||||
// We do this caching so themeState equality works. Basically, doing CPThemeState('foo+bar') === CPThemeState('bar', 'foo') will return true.
|
||||
var themeState = CPThemeStates[String(aState)];
|
||||
if (themeState === undefined)
|
||||
{
|
||||
themeState = aState;
|
||||
CPThemeStates[String(themeState)] = themeState;
|
||||
}
|
||||
return themeState;
|
||||
}
|
||||
|
||||
var CPThemeStates = {};
|
||||
|
||||
/*!
|
||||
@@ -430,37 +460,7 @@ function CPThemeState()
|
||||
}
|
||||
}
|
||||
|
||||
themeState = CPThemeState._cacheThemeState(new ThemeState(stateNames));
|
||||
return themeState;
|
||||
}
|
||||
|
||||
CPThemeState.subtractThemeStates = function(aState1, aState2)
|
||||
{
|
||||
if (aState2 === undefined || aState2 === nil || aState2 === [CPNull null])
|
||||
return aState1;
|
||||
|
||||
var newStates = {};
|
||||
for (var stateName in aState1._stateNames)
|
||||
{
|
||||
if (!aState1._stateNames.hasOwnProperty(stateName))
|
||||
continue;
|
||||
|
||||
if (!aState2._stateNames[stateName])
|
||||
newStates[stateName] = true;
|
||||
}
|
||||
|
||||
return CPThemeState._cacheThemeState(new ThemeState(newStates));
|
||||
}
|
||||
|
||||
CPThemeState._cacheThemeState = function(aState)
|
||||
{
|
||||
// We do this caching so themeState equality works. Basically, doing CPThemeState('foo+bar') === CPThemeState('bar', 'foo') will return true.
|
||||
var themeState = CPThemeStates[String(aState)];
|
||||
if (themeState === undefined)
|
||||
{
|
||||
themeState = aState;
|
||||
CPThemeStates[String(themeState)] = themeState;
|
||||
}
|
||||
themeState = ThemeState._cacheThemeState(new ThemeState(stateNames));
|
||||
return themeState;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2910,7 +2910,7 @@ setBoundsOrigin:
|
||||
if (!_themeState.hasThemeState(aState))
|
||||
return NO;
|
||||
|
||||
_themeState = CPThemeState.subtractThemeStates(_themeState, aState);
|
||||
_themeState = ThemeState.subtractThemeStates(_themeState, aState);
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
Reference in new issue
Block a user