Dynamic colors in tables and fix #67

This commit is contained in:
Brian Miyaji
2014-10-23 13:27:20 +11:00
parent 12064bd8c3
commit 6344be35a3
4 changed files with 41 additions and 25 deletions

View File

@@ -141,14 +141,18 @@ if ( ! function_exists( 'sp_hex_darker' ) ) {
* @param int $factor (default: 30)
* @return string
*/
function sp_hex_darker( $color, $factor = 30 ) {
function sp_hex_darker( $color, $factor = 30, $absolute = false ) {
$base = sp_rgb_from_hex( $color );
$color = '#';
foreach ($base as $k => $v) :
$amount = $v / 100;
$amount = round($amount * $factor);
$new_decimal = $v - $amount;
if ( $absolute ) {
$amount = $factor;
} else {
$amount = $v / 100;
$amount = round($amount * $factor);
}
$new_decimal = max( $v - $amount, 0 );
$new_hex_component = dechex($new_decimal);
if(strlen($new_hex_component) < 2) :
@@ -171,15 +175,19 @@ if ( ! function_exists( 'sp_hex_lighter' ) ) {
* @param int $factor (default: 30)
* @return string
*/
function sp_hex_lighter( $color, $factor = 30 ) {
function sp_hex_lighter( $color, $factor = 30, $absolute = false ) {
$base = sp_rgb_from_hex( $color );
$color = '#';
foreach ($base as $k => $v) :
$amount = 255 - $v;
$amount = $amount / 100;
$amount = round($amount * $factor);
$new_decimal = $v + $amount;
if ( $absolute ) {
$amount = $factor;
} else {
$amount = 255 - $v;
$amount = $amount / 100;
$amount = round($amount * $factor);
}
$new_decimal = min( $v + $amount, 255 );
$new_hex_component = dechex($new_decimal);
if(strlen($new_hex_component) < 2) :