-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7086f9
commit 6a5366b
Showing
7 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#:kivy 2.2.1 | ||
|
||
<CustomButton>: | ||
|
||
# Background | ||
canvas.before: | ||
Color: | ||
rgba: self.background_color | ||
RoundedRectangle: | ||
pos:self.pos | ||
size:self.size | ||
radius:[40,] | ||
|
||
# Main text | ||
Label: | ||
text: root.text | ||
font_size: root.parent.font_ratio * root.font_size | ||
pos: root.pos | ||
size: root.size | ||
shorten: False | ||
text_size: (root.width*root.text_filling_ratio,None) | ||
font_name: root.text_font_name | ||
halign: "center" | ||
valign: "center" | ||
line_height: 1 | ||
color: (0,0,0,1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Module to create custom buttons with round transparent white background. | ||
""" | ||
|
||
############### | ||
### Imports ### | ||
############### | ||
|
||
### Kivy imports ### | ||
from kivy.uix.widget import Widget | ||
from kivy.uix.behaviors import ButtonBehavior | ||
from kivy.properties import ( | ||
StringProperty, | ||
NumericProperty | ||
) | ||
|
||
### Local imports ### | ||
from tools.path import ( | ||
PATH_TEXT_FONT | ||
) | ||
from tools.constants import ( | ||
CUSTOM_BUTTON_BACKGROUND_COLOR, | ||
MAIN_BUTTON_FONT_SIZE | ||
) | ||
|
||
############# | ||
### Class ### | ||
############# | ||
|
||
|
||
class CustomButton(ButtonBehavior, Widget): | ||
|
||
background_color = CUSTOM_BUTTON_BACKGROUND_COLOR | ||
text = StringProperty() | ||
text_filling_ratio = NumericProperty() | ||
font_size = NumericProperty() | ||
|
||
def __init__( | ||
self, | ||
text="", | ||
text_font_name=PATH_TEXT_FONT, | ||
text_filling_ratio=0.8, | ||
font_size=MAIN_BUTTON_FONT_SIZE, | ||
release_function=lambda: 1 + 1, | ||
**kwargs): | ||
super().__init__(**kwargs) | ||
self.release_function = release_function | ||
self.always_release = True | ||
self.text_font_name = text_font_name | ||
self.text = text | ||
self.text_filling_ratio = text_filling_ratio | ||
self.font_size = font_size | ||
|
||
def on_press(self): | ||
self.opacity = 0.8 | ||
|
||
def on_release(self): | ||
self.release_function() | ||
self.opacity = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters