Skip to content

Commit

Permalink
Updated to v1.0.6
Browse files Browse the repository at this point in the history
Fixed issue preventing CSColorPicker from launching in TweakSettings for some users
Added CSBaseDisplayCell as a base implementation for display cells
Added support for dynamic UIColors supporting hex strings, custom dynamic color picker coming soon
Updated project automation
  • Loading branch information
CreatureSurvive committed Jun 21, 2021
1 parent 4dbc4aa commit b0ed174
Show file tree
Hide file tree
Showing 21 changed files with 347 additions and 180 deletions.
4 changes: 2 additions & 2 deletions CSColorPicker Resources/CSColorPicker/CSColorPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved.
//

#import "UIColor+CSColorPicker.h"
#import "NSString+CSColorPicker.h"
#import "Categories/UIColor+CSColorPicker.h"
#import "Categories/NSString+CSColorPicker.h"
13 changes: 13 additions & 0 deletions CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
//
@interface NSString (CSColorPicker)

//
// same as csp_colorFromHexString: returning a dynamic color
// if the hex string is not dynamic, this will fallback to cscp_colorFromHexString:
// supported formats include 'l:RGB d:RGB', 'l:ARGB d:ARGB', 'l:RRGGBB d:RRGGBB', 'l:AARRGGBB d:AARRGGBB', 'l:RGB:0.500000 d:RGB:0.500000', 'l:RRGGBB:0.500000 d:RRGGBB:0.500000'
// all formats work with or without #
//
+ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString;

//
// returns a UIColor from the hex string eg [UIColor cscp_colorFromHexString:@"#FF0000"];
// if the hex string is invalid, returns red
Expand All @@ -23,6 +31,11 @@
// returns true if the string is a valid hex (will pass with or without #)
+ (BOOL)cscp_isValidHexString:(NSString *)hexString;

//
// returns a string dynamic hex string representation of the string instance
//
- (UIColor *)cscp_dynamicHexColor;

//
// returns a string hex string representation of the string instance
//
Expand Down
21 changes: 20 additions & 1 deletion CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Created by CreatureSurvive on 3/17/17.
// Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIColor (CSColorPicker)
Expand All @@ -15,6 +14,16 @@
//
+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString;

//
// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor]]; outputs @"l:#FF0000 d:#FF0000"
//
+ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color;

//
// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor] alpha:YES]; outputs @"#l:FFFF0000 d:FFFF0000"
//
+ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color alpha:(BOOL)include;

//
// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_hexStringFromColor:[UIColor redColor]]; outputs @"#FF0000"
//
Expand Down Expand Up @@ -76,6 +85,16 @@
//
- (CGFloat)cscp_brightness;

//
// the dynamic hexString value of the color instance
//
- (NSString *)cscp_dynamicHexString;

//
// the dynamic hexString value of the color instance with alpha included
//
- (NSString *)cscp_dynamicHexStringWithAlpha;

//
// the hexString value of the color instance
//
Expand Down
Binary file modified CSColorPicker Resources/libCSColorPicker.dylib
Binary file not shown.
Binary file removed CSColorPicker Resources/libCSPreferences.dylib
Binary file not shown.
31 changes: 22 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ARCHS = armv7 armv7s arm64 arm64e
TARGET = iphone:clang:13.0:5.0

GO_EASY_ON_ME = 0
DEBUG = 1
FINALPACKAGE = 1
DEBUG = 0
LEAN_AND_MEAN = 1
GO_EASY_ON_ME = 0

PREFIX = $(THEOS)/toolchains/xcode11.xctoolchain/usr/bin/
INSTALL_TARGET_PROCESSES = Preferences
INSTALL_TARGET_PROCESSES = Preferences TweakSettings

include $(THEOS)/makefiles/common.mk

Expand All @@ -20,9 +20,22 @@ $(LIBRARY_NAME)_CFLAGS += -fobjc-arc -I$(INCLUDES) -IPrefix.pch

include $(THEOS_MAKE_PATH)/library.mk


# SUBPROJECTS += lcpshim
# include $(THEOS_MAKE_PATH)/aggregate.mk

after-stage::
$(ECHO_NOTHING)cp "$(THEOS_STAGING_DIR)/usr/lib/libCSColorPicker.dylib" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/libCSPreferences.dylib"$(ECHO_END)
$(ECHO_NOTHING)mkdir -p "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/CSColorPicker.h" "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker/CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/UIColor+CSColorPicker.h" "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker/UIColor+CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/NSString+CSColorPicker.h" "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker/NSString+CSColorPicker.h"$(ECHO_END)

$(ECHO_NOTHING)mkdir -p "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_STAGING_DIR)/usr/lib/libCSColorPicker.dylib" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/libCSColorPicker.dylib"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/CSColorPicker.h" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker/CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/UIColor+CSColorPicker.h" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/NSString+CSColorPicker.h" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)zip "$(THEOS_PROJECT_DIR)/CSColorPicker Resources.zip" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources"$(ECHO_END)

$(ECHO_NOTHING)mkdir -p "$(THEOS)/include/CSColorPicker"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_STAGING_DIR)/usr/lib/libCSColorPicker.dylib" "$(THEOS)/lib/libCSColorPicker.dylib"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/CSColorPicker.h" "$(THEOS)/include/CSColorPicker/CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/UIColor+CSColorPicker.h" "$(THEOS)/include/CSColorPicker/UIColor+CSColorPicker.h"$(ECHO_END)
$(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/NSString+CSColorPicker.h" "$(THEOS)/include/CSColorPicker/NSString+CSColorPicker.h"$(ECHO_END)

2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.creaturesurvive.libcscolorpicker
Name: libCSColorPicker
Pre-Depends: firmware (>= 7.0)
Version: 1.0.5
Version: 1.0.6
Architecture: iphoneos-arm
Description: A minimal color picker library for developers
Maintainer: CreatureSurvive <support@creaturecoding.com>
Expand Down
13 changes: 13 additions & 0 deletions source/Categories/NSString+CSColorPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
//
@interface NSString (CSColorPicker)

//
// same as csp_colorFromHexString: returning a dynamic color
// if the hex string is not dynamic, this will fallback to cscp_colorFromHexString:
// supported formats include 'l:RGB d:RGB', 'l:ARGB d:ARGB', 'l:RRGGBB d:RRGGBB', 'l:AARRGGBB d:AARRGGBB', 'l:RGB:0.500000 d:RGB:0.500000', 'l:RRGGBB:0.500000 d:RRGGBB:0.500000'
// all formats work with or without #
//
+ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString;

//
// returns a UIColor from the hex string eg [UIColor cscp_colorFromHexString:@"#FF0000"];
// if the hex string is invalid, returns red
Expand All @@ -23,6 +31,11 @@
// returns true if the string is a valid hex (will pass with or without #)
+ (BOOL)cscp_isValidHexString:(NSString *)hexString;

//
// returns a string dynamic hex string representation of the string instance
//
- (UIColor *)cscp_dynamicHexColor;

//
// returns a string hex string representation of the string instance
//
Expand Down
45 changes: 44 additions & 1 deletion source/Categories/NSString+CSColorPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#import "NSString+CSColorPicker.h"
#import <UIKit/UIColor.h>
#import <UIKit/UITraitCollection.h>

struct CGFloat;
@interface NSString (Private)
Expand All @@ -15,7 +16,45 @@ + (CGFloat)_cscp_colorComponentFrom:(NSString *)string start:(NSUInteger)start l

@implementation NSString (CSColorPicker)

+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString {
+ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString {

if (!hexString || !hexString.length) return [UIColor redColor];

if (![hexString containsString:@" "] || ![hexString.lowercaseString containsString:@"l:"] || ![hexString.lowercaseString containsString:@"d:"]) {
return [self _cscp_colorFromHexString:hexString];
}

NSArray *components = [hexString componentsSeparatedByString:@" "];

if (!components || !components.count) {
return [self _cscp_colorFromHexString:hexString];
}

UIColor *light = [self _cscp_colorFromHexString:[components.firstObject substringFromIndex:2]];

if (@available(iOS 13.0, *)) {
UIColor *dark = [self _cscp_colorFromHexString:[components.lastObject substringFromIndex:2]];
return [UIColor colorWithDynamicProvider:^UIColor * (UITraitCollection *traitCollection) {
switch (traitCollection.userInterfaceStyle) {
case UIUserInterfaceStyleUnspecified:
case UIUserInterfaceStyleLight:
return light;
case UIUserInterfaceStyleDark:
return dark;
}
return light;
}];
}

return light;

}

+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString {
return [self _cscp_colorFromHexString:hexString];
}

+ (UIColor *)_cscp_colorFromHexString:(NSString *)hexString {
NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString];
CGFloat alpha, red, blue, green;

Expand Down Expand Up @@ -75,6 +114,10 @@ + (BOOL)cscp_isValidHexString:(NSString *)hexString {
return (NSNotFound == [[[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString] rangeOfCharacterFromSet:hexChars].location);
}

- (UIColor *)cscp_dynamicHexColor {
return [NSString cscp_dynamicColorFromHexString:self];
}

- (UIColor *)cscp_hexColor {
return [NSString cscp_colorFromHexString:self];
}
Expand Down
20 changes: 20 additions & 0 deletions source/Categories/UIColor+CSColorPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
//
+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString;

//
// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor]]; outputs @"l:#FF0000 d:#FF0000"
//
+ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color;

//
// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor] alpha:YES]; outputs @"#l:FFFF0000 d:FFFF0000"
//
+ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color alpha:(BOOL)include;

//
// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_hexStringFromColor:[UIColor redColor]]; outputs @"#FF0000"
//
Expand Down Expand Up @@ -75,6 +85,16 @@
//
- (CGFloat)cscp_brightness;

//
// the dynamic hexString value of the color instance
//
- (NSString *)cscp_dynamicHexString;

//
// the dynamic hexString value of the color instance with alpha included
//
- (NSString *)cscp_dynamicHexStringWithAlpha;

//
// the hexString value of the color instance
//
Expand Down
82 changes: 81 additions & 1 deletion source/Categories/UIColor+CSColorPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,45 @@ + (CGFloat)_cscp_colorComponentFrom:(NSString *)string start:(NSUInteger)start l

@implementation UIColor (CSColorPicker)

+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString {
+ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString {

if (!hexString || !hexString.length) return [UIColor redColor];

if (![hexString containsString:@" "] || ![hexString.lowercaseString containsString:@"l:"] || ![hexString.lowercaseString containsString:@"d:"]) {
return [self _cscp_colorFromHexString:hexString];
}

NSArray *components = [hexString componentsSeparatedByString:@" "];

if (!components || !components.count) {
return [self _cscp_colorFromHexString:hexString];
}

UIColor *light = [self _cscp_colorFromHexString:[components.firstObject substringFromIndex:2]];

if (@available(iOS 13.0, *)) {
UIColor *dark = [self _cscp_colorFromHexString:[components.lastObject substringFromIndex:2]];
return [UIColor colorWithDynamicProvider:^UIColor * (UITraitCollection *traitCollection) {
switch (traitCollection.userInterfaceStyle) {
case UIUserInterfaceStyleUnspecified:
case UIUserInterfaceStyleLight:
return light;
case UIUserInterfaceStyleDark:
return dark;
}
return light;
}];
}

return light;

}

+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString {
return [self _cscp_colorFromHexString:hexString];
}

+ (UIColor *)_cscp_colorFromHexString:(NSString *)hexString {

NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString];
CGFloat alpha, red, blue, green;
Expand Down Expand Up @@ -74,6 +112,40 @@ + (BOOL)cscp_isValidHexString:(NSString *)hexString {
return (NSNotFound == [[[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString] rangeOfCharacterFromSet:hexChars].location);
}

+ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color {
return [self cscp_dynamicHexStringFromColor:color alpha:NO];
}

+ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color alpha:(BOOL)include {

CGFloat rl,gl,bl,al,rd,gd,bd,ad;
BOOL (^componentsForColor)(UIColor*, CGFloat*, CGFloat*, CGFloat*, CGFloat*) = ^BOOL (UIColor*color ,CGFloat*red, CGFloat*green, CGFloat*blue, CGFloat*alpha) {
BOOL value = [color getRed:red green:green blue:blue alpha:alpha];
*red = roundf((float) (*red * 255.0f));
*green = roundf((float) (*green * 255.0f));
*blue = roundf((float) (*blue * 255.0f));
*alpha = roundf((float) (*blue * 255.0f));
return value;
};

if (@available(iOS 13.0, *)) {
componentsForColor(
[color resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]],
&rl, &gl, &bl, &al
);
componentsForColor(
[color resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]],
&rd, &gd, &bd, &ad
);
} else {
componentsForColor(color, &rl, &gl, &bl, &al);
componentsForColor(color, &rd, &gd, &bd, &ad);
}

return include ? [[NSString stringWithFormat:@"l:%02x%02x%02x%02x d:%02x%02x%02x%02x", (int)al, (int)rl, (int)gl, (int)bl, (int)ad, (int)rd, (int)gd, (int)bd] uppercaseString] :
[[NSString stringWithFormat:@"l:%02x%02x%02x d:%02x%02x%02x", (int)rl, (int)gl, (int)bl, (int)rd, (int)gd, (int)bd] uppercaseString];
}

+ (NSString *)cscp_hexStringFromColor:(UIColor *)color {

CGFloat red, green, blue;
Expand Down Expand Up @@ -151,6 +223,14 @@ - (CGFloat)cscp_brightness {
return b;
}

- (NSString *)cscp_dynamicHexString {
return [UIColor cscp_dynamicHexStringFromColor:self];
}

- (NSString *)cscp_dynamicHexStringWithAlpha {
return [UIColor cscp_dynamicHexStringFromColor:self alpha:YES];
}

- (NSString *)cscp_hexString {
return [UIColor cscp_hexStringFromColor:self];
}
Expand Down
21 changes: 21 additions & 0 deletions source/Cells/CSBaseDisplayCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by CreatureSurvive on 3/17/17.
// Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved.
//

#import <Headers/PSSpecifier.h>
#import <Headers/PSTableCell.h>
#import <Headers/PSViewController.h>
#import <Controllers/CSColorPickerViewController.h>


@interface CSBaseDisplayCell : PSTableCell

@property (nonatomic, retain) UIView *cellColorDisplay;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier;
- (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier;

- (void)openColorPickerView;

@end
Loading

0 comments on commit b0ed174

Please sign in to comment.