From eb643a2df8580a3384d9d64211c38b0c17768ac9 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 9 Jul 2012 20:31:29 +0100 Subject: [PATCH] Simplify code. --- AppKit/CPButton.j | 23 +++-------------------- AppKit/CPTextField.j | 17 ++--------------- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/AppKit/CPButton.j b/AppKit/CPButton.j index 7add82d70..8594bc410 100644 --- a/AppKit/CPButton.j +++ b/AppKit/CPButton.j @@ -576,35 +576,18 @@ CPButtonImageOffset = 3.0; { var contentInset = [self currentValueForThemeAttribute:@"content-inset"]; - if (_CGInsetIsEmpty(contentInset)) - return bounds; - - bounds = _CGRectMakeCopy(bounds); - bounds.origin.x += contentInset.left; - bounds.origin.y += contentInset.top; - bounds.size.width -= contentInset.left + contentInset.right; - bounds.size.height -= contentInset.top + contentInset.bottom; - - return bounds; + return _CGRectInsetByInset(bounds, contentInset); } - (CGRect)bezelRectForBounds:(CGRect)bounds { + // Is this necessary? The theme itself can just change its inset to a zero inset when !CPThemeStateBordered. if (![self isBordered]) return bounds; var bezelInset = [self currentValueForThemeAttribute:@"bezel-inset"]; - if (_CGInsetIsEmpty(bezelInset)) - return bounds; - - bounds = _CGRectMakeCopy(bounds); - bounds.origin.x += bezelInset.left; - bounds.origin.y += bezelInset.top; - bounds.size.width -= bezelInset.left + bezelInset.right; - bounds.size.height -= bezelInset.top + bezelInset.bottom; - - return bounds; + return _CGRectInsetByInset(bounds, bezelInset); } - (CGSize)_minimumFrameSize diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 60874a91a..f02bb28fd 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -1313,27 +1313,14 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); { var contentInset = [self currentValueForThemeAttribute:@"content-inset"]; - bounds.origin.x += contentInset.left; - bounds.origin.y += contentInset.top; - bounds.size.width -= contentInset.left + contentInset.right; - bounds.size.height -= contentInset.top + contentInset.bottom; - - return bounds; + return _CGRectInsetByInset(bounds, contentInset); } - (CGRect)bezelRectForBounds:(CGRect)bounds { var bezelInset = [self currentValueForThemeAttribute:@"bezel-inset"]; - if (_CGInsetIsEmpty(bezelInset)) - return bounds; - - bounds.origin.x += bezelInset.left; - bounds.origin.y += bezelInset.top; - bounds.size.width -= bezelInset.left + bezelInset.right; - bounds.size.height -= bezelInset.top + bezelInset.bottom; - - return bounds; + return _CGRectInsetByInset(bounds, bezelInset); } - (CGRect)rectForEphemeralSubviewNamed:(CPString)aName