Skip to content

Commit

Permalink
disable box shadow when the colored rounded button is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Jan 23, 2024
1 parent 484ba8b commit d92770c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion screens/custom_widgets/colored_rounded_button.kv
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
canvas.before:
# Shadow
Color:
rgba: 0, 0, 0, 1
rgba: (0, 0, 0, 1) if not self.disable_button else (0,0,0,0)
BoxShadow:
pos: (0, 0)
size: self.size
Expand Down
2 changes: 2 additions & 0 deletions screens/game.kv
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
pos_hint: {"center_x":0.25, "center_y":0.8}
size_hint: (0.3, 0.075)
nb_stars: root.nb_stars
primary_color: root.primary_color
secondary_color: root.secondary_color

# Previous word
ColoredRoundedButton:
Expand Down
40 changes: 23 additions & 17 deletions screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def on_pre_enter(self, *args):
self.primary_color = THEMES_DICT[current_theme_colors]["primary"]
self.secondary_color = THEMES_DICT[current_theme_colors]["secondary"]
self.ids.keyboard_layout.build_keyboard()

self.nb_stars = USER_DATA.classic_mode[self.current_act_id][self.current_level_id]["nb_stars"]
return super().on_pre_enter(*args)

def on_enter(self, *args):
Expand All @@ -92,7 +94,7 @@ def on_enter(self, *args):
return super().on_enter(*args)

def on_pre_leave(self, *args):
self.ids.keyboard_layout.destroy_keyboard()
self.ids.keyboard_layout.destroy_keyboard()

return super().on_leave(*args)

Expand All @@ -113,39 +115,39 @@ def check_disable_keyboard(self):
def check_enable_submit_button(self):
"""
Enable the submit button if the word entered is valid.
Parameters
----------
None
Returns
-------
None
"""
if is_valid(
new_word=self.new_word.lower(),
current_word=self.current_word.lower()):
new_word=self.new_word.lower(),
current_word=self.current_word.lower()):
self.enable_submit_button()
else:
self.disable_submit_button()

def touch_letter(self, letter):
"""
React when a letter of the keyboard is released.
Parameters
----------
letter : str
Letter pressed. Can be any letter in capital or "DELETE".
Returns
-------
None
"""
# Delete the last letter of the current word
if letter == "DELETE":
self.new_word = self.new_word[:-1]

# Add the new letter to the current word
else:
self.new_word += letter
Expand All @@ -169,7 +171,8 @@ def build_word(self):

# Adapt the size of the letters if there are too many
if number_letters >= 11:
size_letter = (0.95 - (number_letters-1)*horizontal_padding)/number_letters
size_letter = (0.95 - (number_letters - 1) *
horizontal_padding) / number_letters
margin_left = 0.025

# Remove the previous widgets
Expand All @@ -184,7 +187,7 @@ def build_word(self):
outline_color = self.primary_color
else:
outline_color = self.secondary_color

# Determine the content of the letter
try:
letter = self.new_word[counter_letter]
Expand All @@ -193,19 +196,22 @@ def build_word(self):

# Determine the x position of the letter
if number_letters % 2 == 0:
x_position = margin_left + x_center + (counter_letter-number_letters/2+0.5)*horizontal_padding + (counter_letter-number_letters/2)*size_letter
x_position = margin_left + x_center + \
(counter_letter - number_letters / 2 + 0.5) * horizontal_padding + \
(counter_letter - number_letters / 2) * size_letter
else:
x_position = margin_left + x_center + (counter_letter-number_letters/2)*size_letter + (counter_letter-number_letters/2-0.5)*horizontal_padding
x_position = margin_left + x_center + (counter_letter - number_letters / 2) * size_letter + (
counter_letter - number_letters / 2 - 0.5) * horizontal_padding

# Create the letter widget
letter_widget = ColoredRoundedButton(
text=letter,
background_color=(1,1,1,1),
pos_hint={"x": x_position,"y": 0.35},
background_color=(1, 1, 1, 1),
pos_hint={"x": x_position, "y": 0.35},
font_size=LETTER_FONT_SIZE,
font_ratio=self.font_ratio,
size_hint=(size_letter, height_letter),
color_label=(0,0,0,1),
color_label=(0, 0, 0, 1),
outline_color=outline_color,
disable_button=True
)
Expand Down Expand Up @@ -254,11 +260,11 @@ def enable_arrow(self, mode: Literal["left", "right"]):
self.ids.left_arrow.disable_button = False

def enable_submit_button(self):
self.ids.submit_button.opacity = 1
# self.ids.submit_button.opacity = 1
self.ids.submit_button.disable_button = False

def disable_submit_button(self):
self.ids.submit_button.opacity = 0
# self.ids.submit_button.opacity = 0
self.ids.submit_button.disable_button = True

def go_backwards(self):
Expand Down

0 comments on commit d92770c

Please sign in to comment.