Skip to content

Commit

Permalink
Try to add the dashed line for rounded rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Jan 21, 2024
1 parent 0732e9f commit ab5fb3e
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 12 deletions.
29 changes: 21 additions & 8 deletions screens/custom_widgets/colored_rounded_button.kv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#:kivy 2.2.1
#:set OUTLINE_RECTANGLE 6
#:set OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON 1.5

<ColoredRoundedButton>:

Expand All @@ -14,19 +14,32 @@
offset: 5, -5
spread_radius: -10, -10
blur_radius: 30
# Border
Color:
rgba: root.outline_color
RoundedRectangle:
pos: (-OUTLINE_RECTANGLE//2, -OUTLINE_RECTANGLE//2)
size: (self.size[0]+OUTLINE_RECTANGLE,self.size[1]+OUTLINE_RECTANGLE)
radius: [12]
# Rounded rectangle
Color:
rgba: root.background_color
RoundedRectangle:
pos:(0, 0)
size:self.size
# Border
Color:
rgba: root.outline_color
Line:
dash_offset: 4
dash_length: 7
width: OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON
rounded_rectangle: (-OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, -OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, self.size[0]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON,self.size[1]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON, 12, 12, 12, 12)
# # Border 2
# Line:
# dash_offset: 4
# dash_length: 7
# width: OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON
# rounded_rectangle: (-OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON, -OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON, self.size[0]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*2,self.size[1]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*2, 12, 12, 12, 12)
# # Border 3
# Line:
# dash_offset: 4
# dash_length: 7
# width: OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON
# rounded_rectangle: (-3*OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, -3*OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, self.size[0]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*3,self.size[1]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*3, 12, 12, 12, 12)

# Main text
Label:
Expand Down
112 changes: 111 additions & 1 deletion screens/custom_widgets/keyboard_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,23 @@ def update_padding(self, base_widget, value):
self.size_letter = (1 - self.horizontal_padding*9)/10 # because maximum of 9 letters in line

def build_keyboard(self):
"""
Add the different letters and the delete button in the keyboard layout.
Parameters
----------
None
Returns
-------
Nonee
"""
self.list_letter_keys = []

vertical_padding = 0.05
height_letter = (1-vertical_padding*3) / 3

# Define the type of the keyboard
if self.type_keyboard == "QWERTY":
first_line_letters = ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"]
second_line_letters = ["A", "S", "D", "F", "G", "H", "J", "K", "L"]
Expand Down Expand Up @@ -168,7 +180,7 @@ def build_keyboard(self):
self.list_letter_keys.append(colored_rounded_button)
counter += 1

# BACK key
# DELETE key
self.delete_key = ColoredRoundedButtonImage(
image_path=PATH_IMAGES + "delete.png",
background_color=self.background_color,
Expand All @@ -183,29 +195,127 @@ def build_keyboard(self):
)
self.add_widget(self.delete_key)

def destroy_keyboard(self):
"""
Remove all the keys of the keyboard.
Parameters
----------
None
Returns
-------
None
"""
for letter in self.list_letter_keys:
self.remove_widget(letter)
self.remove_widget(self.delete_key)

def disable_delete_button(self):
"""
Disable the delete button.
Parameters
----------
None
Returns
-------
None
"""
self.delete_key.background_color = DISABLE_BUTTON_COLOR
self.delete_key.disable_button = True

def activate_delete_button(self):
"""
Enable the delete button.
Parameters
----------
None
Returns
-------
None
"""
self.delete_key.disable_button = False
self.delete_key.background_color = self.background_color

def disable_letters(self):
"""
Disable the buttons of the letters.
Parameters
----------
None
Returns
-------
None
"""
letter_key: ColoredRoundedButton
for letter_key in self.list_letter_keys:
letter_key.background_color = DISABLE_BUTTON_COLOR
letter_key.disable_button = True

def activate_letters(self):
"""
Enable the buttons of the letters.
Parameters
----------
None
Returns
-------
None
"""
letter_key: ColoredRoundedButton
for letter_key in self.list_letter_keys:
letter_key.disable_button = False
letter_key.background_color = self.background_color

def disable_whole_keyboard(self):
"""
Disable the whole keyboard.
Parameters
----------
None
Returns
-------
None
"""
self.disable_delete_button()
self.disable_letters()

def activate_whole_keyboard(self):
"""
Activate the whole keyboard.
Parameters
----------
None
Returns
-------
None
"""
self.activate_letters()
self.activate_delete_button()

def touch_letter(self, letter, *args):
"""
Activate the function when a letter is pressed in the keyboard.
Parameters
----------
letter : string
Letter, it can be a capital letter or "DELETE"
Returns
-------
None
"""
self.touch_function(letter)
3 changes: 3 additions & 0 deletions screens/custom_widgets/rounded_button_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def __init__(
self,
image_path:str="",
colors=(0, 0, 0, 1),
release_function=lambda: 1 + 1,
**kwargs):
super().__init__(**kwargs)

self.release_function = release_function
self.image_path = image_path
self.colors = colors
self.always_release = True
Expand All @@ -63,4 +65,5 @@ def on_press(self):

def on_release(self):
if not self.disable_button:
self.release_function()
self.opacity = 1
4 changes: 2 additions & 2 deletions screens/game.kv
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
size_hint: (None, 0.05)
width: self.height
colors: root.primary_color
on_release: root.go_to_previous_level()
release_function: root.go_to_previous_level
opacity: 0
disable_button: True

Expand All @@ -87,6 +87,6 @@
size_hint: (None, 0.05)
width: self.height
colors: root.primary_color
on_release: root.go_to_next_level()
release_function: root.go_to_next_level
opacity: 0
disable_button: True
6 changes: 5 additions & 1 deletion screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def on_enter(self, *args):
self.check_enable_submit_button()
return super().on_enter(*args)

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

return super().on_leave(*args)

def check_disable_keyboard(self):

# Disable the back button if we have nothing to delete
Expand Down Expand Up @@ -255,7 +260,6 @@ def enable_submit_button(self):
def disable_submit_button(self):
self.ids.submit_button.opacity = 0
self.ids.submit_button.disable_button = True
print(self.ids.submit_button.opacity)

def go_backwards(self):
self.manager.get_screen("levels").current_act_id = self.current_act_id
Expand Down

0 comments on commit ab5fb3e

Please sign in to comment.