-
Notifications
You must be signed in to change notification settings - Fork 18
Allow label to be scaled #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,8 @@ def __init__( | |
label=None, | ||
label_font=None, | ||
label_color=0x0, | ||
selected_label=None | ||
selected_label=None, | ||
label_scale=None | ||
): | ||
super().__init__(x=x, y=y) | ||
self.x = x | ||
|
@@ -72,6 +73,7 @@ def __init__( | |
self._label_color = label_color | ||
self._label_font = label_font | ||
self._selected_label = _check_color(selected_label) | ||
self._label_scale = label_scale or 1 | ||
|
||
@property | ||
def label(self): | ||
|
@@ -89,14 +91,18 @@ def label(self, newtext): | |
|
||
if not self._label_font: | ||
raise RuntimeError("Please provide label font") | ||
self._label = Label(self._label_font, text=newtext) | ||
dims = self._label.bounding_box | ||
self._label = Label(self._label_font, text=newtext, scale=self._label_scale) | ||
dims = list(self._label.bounding_box) | ||
dims[2] *= self._label.scale | ||
dims[3] *= self._label.scale | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not in love with having to do this with the bounding box dimensions. As I mentioned in the description, I'm not sure if it was intentional or not that the bounding box for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do think the approach you've gone for here is fine. It may be worth considering changing in Label in the long term, but there could be reasons in there why it's like this, I don't know for certain. |
||
if dims[2] >= self.width or dims[3] >= self.height: | ||
while len(self._label.text) > 1 and ( | ||
dims[2] >= self.width or dims[3] >= self.height | ||
): | ||
self._label.text = "{}.".format(self._label.text[:-2]) | ||
dims = self._label.bounding_box | ||
dims = list(self._label.bounding_box) | ||
dims[2] *= self._label.scale | ||
dims[3] *= self._label.scale | ||
if len(self._label.text) <= 1: | ||
raise RuntimeError("Button not large enough for label") | ||
self._label.x = (self.width - dims[2]) // 2 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is passed in to
Label
which wouldn't like aNone
value for scale, so this defaults the value to 1. I prefer for optional parameters to default to None, that way callers can pass in a None and get default behavior. But if it's desirable to set the default on the parameter to 1 asLabel
does it, I can change it.