-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
Correct scaling of MIN_WIDTH and MIN_HEIGHT on Android and WinForms #2186
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from abc import ABC, abstractmethod | ||
from decimal import ROUND_UP | ||
|
||
from android.view import View | ||
from android.widget import EditText | ||
|
@@ -42,4 +43,6 @@ def create(self): | |
def rehint(self): | ||
self.interface.intrinsic.width = at_least(300) | ||
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. Should this constant value be scaled (and/or expressed in terms that are suitable for scaling?) 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. No, for the same reason as above. And since date and time pickers look quite different on each platform, I think it makes sense for the backend to have its own value in this case, rather than defining a _MIN_WIDTH that they all share. |
||
self.native.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) | ||
self.interface.intrinsic.height = self.native.getMeasuredHeight() | ||
self.interface.intrinsic.height = self.scale_out( | ||
self.native.getMeasuredHeight(), ROUND_UP | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from decimal import ROUND_UP | ||
|
||
from android import R | ||
from android.view import View | ||
from android.widget import ProgressBar as A_ProgressBar | ||
|
@@ -92,5 +94,9 @@ def rehint(self): | |
View.MeasureSpec.UNSPECIFIED, | ||
View.MeasureSpec.UNSPECIFIED, | ||
) | ||
self.interface.intrinsic.width = at_least(self.native.getMeasuredWidth()) | ||
self.interface.intrinsic.height = self.native.getMeasuredHeight() | ||
self.interface.intrinsic.width = self.scale_out( | ||
at_least(self.native.getMeasuredWidth()), ROUND_UP | ||
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. Should this have a MIN_WIDTH component to ensure it doesn't just collapse to the smallest possible rendered size? 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. Yes, that would probably be better, and more consistent with some of the other backends. I didn't do that in this PR because I wanted to limit it to just one problem at a time. |
||
) | ||
self.interface.intrinsic.height = self.scale_out( | ||
self.native.getMeasuredHeight(), ROUND_UP | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from decimal import ROUND_UP | ||
|
||
from android.text import InputType, TextWatcher | ||
from android.view import Gravity, View | ||
from android.widget import EditText | ||
from java import dynamic_proxy | ||
from travertino.size import at_least | ||
|
||
from toga_android.keys import toga_key | ||
|
||
|
@@ -123,6 +124,7 @@ def _on_lose_focus(self): | |
self.interface.on_lose_focus() | ||
|
||
def rehint(self): | ||
self.interface.intrinsic.width = at_least(self.interface._MIN_WIDTH) | ||
self.native.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) | ||
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. Why no width specifier? 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. The base class |
||
self.interface.intrinsic.height = self.native.getMeasuredHeight() | ||
self.interface.intrinsic.height = self.scale_out( | ||
self.native.getMeasuredHeight(), ROUND_UP | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Correct scaling of MIN_WIDTH and MIN_HEIGHT on Android and WinForms |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
|
||
|
||
class Box(Widget): | ||
_MIN_WIDTH = 0 | ||
_MIN_HEIGHT = 0 | ||
|
||
def __init__( | ||
self, | ||
id: str | None = None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
|
||
|
||
class ScrollContainer(Widget): | ||
_MIN_WIDTH = 0 | ||
_MIN_HEIGHT = 0 | ||
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. Not 100% convinced this is desirable. Box and Canvas both need to be able to collapse to 0 in case someone wants to use them for very small or 0 sized display elements - but ScrollContainer has to have scroll bars. Assuming a minimum size (historically 100x100, but I'm open to other suggestions) would seem like a sensible default, as otherwise you're potentially going to have a scroll container that can collapse to 0 size in a layout, and therefore be unusable. Any user-specified size will always override this value - so if the use explicitly asks for a 10x10 scroll container, then they will get it - but a minimum value puts a floor on how small Pack will let it get by default. 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. Agreed. |
||
|
||
def __init__( | ||
self, | ||
id=None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import System.Windows.Forms as WinForms | ||
from travertino.size import at_least | ||
|
||
from .base import Widget | ||
|
||
|
||
class Box(Widget): | ||
def create(self): | ||
self.native = WinForms.Panel() | ||
|
||
def rehint(self): | ||
self.interface.intrinsic.width = at_least(0) | ||
self.interface.intrinsic.height = at_least(0) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from decimal import ROUND_UP | ||
|
||
import System.Windows.Forms as WinForms | ||
from travertino.size import at_least | ||
|
||
|
@@ -31,7 +33,9 @@ def set_text(self, text): | |
self.native.Text = text | ||
|
||
def rehint(self): | ||
# self.native.Size = Size(0, 0) | ||
# print("REHINT Button", self, self.native.PreferredSize) | ||
self.interface.intrinsic.width = at_least(self.native.PreferredSize.Width) | ||
self.interface.intrinsic.height = self.native.PreferredSize.Height | ||
self.interface.intrinsic.width = self.scale_out( | ||
at_least(self.native.PreferredSize.Width), ROUND_UP | ||
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. Should this have a MIN_SIZE component? 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. In this case I think it's better to use PreferredSize, because it reacts to the label text. |
||
) | ||
self.interface.intrinsic.height = self.scale_out( | ||
self.native.PreferredSize.Height, ROUND_UP | ||
) |
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.
Should these default values be scaled out?
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.
No, because they're already in CSS pixels. The intention of this PR is that when sizes are assigned to intrinsic.width or intrinsic.height, they are already in CSS pixels as the interface layer expects, so they don't need to be scaled again.