Improving contrast for dyslexics and adding colours to buttons.

This commit is contained in:
sergiotarxz 2024-07-13 05:20:13 +02:00
parent 15d3c03127
commit 78d9e78900
2 changed files with 21 additions and 13 deletions

View File

@ -9,6 +9,8 @@ use Moo;
use Path::Tiny;
use JSON;
use Data::Dumper;
use Encode qw(encode);
use Digest::SHA qw(sha1_hex);
use JapaChar::Random;
@ -185,4 +187,15 @@ sub _retrieve_started_chars_not_finished( $self, $type ) {
);
}
sub get_color_attr($self, $text) {
my $style_manager = Adw::StyleManager::get_default();
my $hex_color = sha1_hex( encode 'utf-8', $text);
my @foreground =
map { $_ & 0xffff }
map { int($_ * ( $style_manager->get_dark ? 2 : 0.5 )) }
map { ( $_ << 8 ) | $_ }
map { $_ = hex $_; } $hex_color =~ /(..)(..)(..)/;
my $fore_attr = Pango::AttrForeground->new(@foreground);
return $fore_attr;
}
1;

View File

@ -16,8 +16,6 @@ use JapaChar::Characters;
use Pango;
use JapaChar::Random;
use JapaChar::Score;
use Digest::SHA qw(sha1_hex);
use Encode qw(encode);
use Glib::IO;
@ -164,16 +162,13 @@ sub _new_challenge_generic_code( $self, $show, $guess, $can_be_typed = 0 ) {
my $box = Gtk::Box->new( 'horizontal', 10 );
$box->set_valign('center');
$box->set_halign('center');
my $resize_buttons = sub {
};
$resize_buttons->();
for my $button (@buttons) {
$box->append($button);
}
$self->_buttons_box($box);
$self->_on_resize_buttons->();
$self->_app->on_resize($resize_buttons);
$self->_app->on_resize($self->_on_resize_buttons);
$grid->attach( $box, 0, 2, 12, 1 );
$grid->attach( $continue_button, 6, 3, 5, 1 );
}
@ -191,6 +186,10 @@ sub _build__on_resize_buttons($self) {
if ( $size_pango_number < $size_number ) {
$size = Pango::AttrSize->new($size_pango_number);
}
if ($self->_app->accessibility->is_dyslexia) {
my $fore_attr = $self->_app->characters->get_color_attr($button->get_child->get_text);
$attr_list->insert($fore_attr);
}
$attr_list->insert($size);
$button->get_child->set_attributes($attr_list);
}
@ -210,15 +209,11 @@ sub _get_label_featured_character( $self, $text ) {
my $size = Pango::AttrSize->new( 72 * PANGO_SCALE );
my $color = Pango::Color->new;
my $hex_color = sha1_hex(encode 'utf-8', $text);
my @foreground = map { $_ = hex $_; ($_ << 8) | $_ } $hex_color =~ /(..)(..)(..)/;
my @background = map { 0xffff - $_ } @foreground;
my $fore_attr = Pango::AttrForeground->new(@foreground);
my $back_attr = Pango::AttrBackground->new(@background);
$attr_list->insert($size);
if ($self->_app->accessibility->is_dyslexia) {
my $fore_attr = $self->_app->characters->get_color_attr($text);
if ( $self->_app->accessibility->is_dyslexia ) {
$attr_list->insert($fore_attr);
$attr_list->insert($back_attr);
}
$label->set_attributes($attr_list);
$label->set_halign('center');