From 5fec964f3d5213b50e74f4eba804c84399727cba Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 11 Oct 2023 11:58:07 +0200 Subject: [PATCH] wip #6381 @0.5 --- app/Elearning/QuizCompiler.php | 1 + app/Elearning/QuizCompiler/Animations.php | 7 ++++--- app/Models/QuizTheme.php | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Elearning/QuizCompiler.php b/app/Elearning/QuizCompiler.php index 71a413ae6..fe7d0d44d 100644 --- a/app/Elearning/QuizCompiler.php +++ b/app/Elearning/QuizCompiler.php @@ -140,6 +140,7 @@ class QuizCompiler extends Base { // Main texts color $this->sassVariables['texts-color'] = $this->theme->getTextsColor(); + $this->sassVariables['button-texts-color'] = $this->theme->getButtonTextColor(); $this->sassVariables['opposite-texts-color'] = $this->theme->getTextsColor(true); // Font $this->sassVariables['font'] = $this->_font($this->theme->font); diff --git a/app/Elearning/QuizCompiler/Animations.php b/app/Elearning/QuizCompiler/Animations.php index a0edd1b13..67ac059d0 100644 --- a/app/Elearning/QuizCompiler/Animations.php +++ b/app/Elearning/QuizCompiler/Animations.php @@ -14,8 +14,8 @@ trait Animations const OK_COLOR = '#16BFBF'; const NOK_COLOR = '#D0167C'; const CONFETTI_COLOR = '#E4FF19'; - - const TEXT_COLOR = "#ffffff"; + const TEXT_COLOR = "#66666F"; + const BUTTON_TEXT_COLOR = "#33333F"; protected $animations = []; @@ -26,10 +26,11 @@ trait Animations protected function writeAnimations() { $colors = [ + self::BUTTON_TEXT_COLOR => $this->theme->getButtonTextColor(), + self::TEXT_COLOR => $this->theme->getTextsColor(), self::OK_COLOR => $this->theme->okColor, self::CONFETTI_COLOR => $this->theme->okColor, self::NOK_COLOR => $this->theme->nokColor, - self::TEXT_COLOR => $this->theme->getTextsColor(), ]; $animationReplace = []; $animationPregReplace = []; diff --git a/app/Models/QuizTheme.php b/app/Models/QuizTheme.php index 6d181232f..02ea5b65f 100644 --- a/app/Models/QuizTheme.php +++ b/app/Models/QuizTheme.php @@ -65,6 +65,7 @@ class QuizTheme extends ToolboxModel { $this->addField('sectionTexts', FormSection::class, __('Textes')); $this->addField('textColor', SelectFromArray::class, __('Couleur des textes'), ['default' => 'auto', 'options' => ['auto' => __('Automatique'), 'light' => __('Blanc'), 'dark' => __('Noir')]]); + $this->addField('buttonTextColor', SelectFromArray::class, __('Couleur de texte du bouton principal'), ['default' => 'auto', 'options' => ['auto' => __('Automatique'), 'light' => __('Blanc'), 'dark' => __('Noir')]]); $this->addField('font', FluidbookFont::class, __('Police de caractères'), ['default' => 'SourceSans', 'databaseDefault' => 'SourceSans']); } @@ -142,13 +143,23 @@ class QuizTheme extends ToolboxModel } public function getTextsColor($opposite = false) + { + return $this->_getAutoTextColor($this->neutralColor, $this->textColor, $opposite); + } + + public function getButtonTextColor($opposite = false) + { + return $this->_getAutoTextColor($this->mainColor, $this->buttonTextColor, $opposite); + } + + protected function _getAutoTextColor($base, $color, $opposite = false) { $darkColor = '#383838'; $lightColor = '#ffffff'; - if ($this->textColor == 'auto' || !$this->textColor) { + if ($color == 'auto' || !$color) { // If auto mode, check between black and white which have the biggest distance (i.e. most contrast) with neutralColor - $neutral = new \Cubist\Util\Graphics\Color($this->neutralColor); + $neutral = new \Cubist\Util\Graphics\Color($base); $black = new \Cubist\Util\Graphics\Color($darkColor); $white = new \Cubist\Util\Graphics\Color($lightColor); $distBlack = $neutral->distance($black); @@ -159,7 +170,7 @@ class QuizTheme extends ToolboxModel $res = $darkColor; } } else { - $res = match ($this->textColor) { + $res = match ($color) { 'dark' => $darkColor, '#000000' => $darkColor, '#ffffff' => $lightColor, -- 2.39.5