Skip to content

Optional position in resize #11

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

Closed
wants to merge 3 commits into from

Conversation

FoamyGuy
Copy link
Contributor

This adds an optional argument for position to the resize function in Widget.

subclasses can make use of this argument to do things that require knowing the position such as updating the touch_boundry to reflect the new size and location of a widget after it's been moved.

Using these changes and GridLayout I was able to make a grid of IconWidgets that are all individually touch capable.

image

@kmatch98
Copy link
Contributor

kmatch98 commented Mar 12, 2021

@FoamyGuy I don’t understand the need for sending the position when resizing a Widget. When a widget gets resized it should automatically update its touch boundary to reflect the new size. A widget call always get its own new position from self.x and set.y.

However I do understand the need for grid layout having a feature like anchor_point to allow centering or justifying widgets inside the grid. Can this be solved using an anchor_point input to grid_layout?

I think I may be missing what your getting at here.

In SwitchRound here’s how I adjust for the local position when calling the superclass Control.contains():

def contains(self, touch_point):  # overrides, then calls Control.contains(x,y)
        """Checks if the Widget was touched.  Returns True if the touch_point
        is within the Control's touch_boundary.
        :param touch_point: x,y location of the screen, in absolute display coordinates.
        :return: Boolean
        """
        touch_x = (
            touch_point[0] - self.x
        )  # adjust touch position for the local position
        touch_y = touch_point[1] - self.y

        return super().contains((touch_x, touch_y, 0))

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Mar 12, 2021

@kmatch98 the code that uses it is here currently: https://github.com/FoamyGuy/Touch_Deck_Working_Files/blob/main/touch_deck_code.py

In particular it's used inside of IconWidget in order to update the touch_boundry to the new size and positioned that was set by the grid_layout.

Nice idea to override contains to adjust the coordinates. That is pretty much what I need I think. I'll give that a try and close this if it works how I'm thinking.

@FoamyGuy
Copy link
Contributor Author

@kmatch98 if you find yourself curious this was the code at the time I made the change: FoamyGuy/Touch_Deck_Working_Files@f2171c2#diff-538a96780fd1dad5b3b939f4b6280ae5e39d202c22811192e647c73cbca3a677

But I have successfully changed it over to use the same technique you mentioned here from the switch.

Thank you for the pointer!

@FoamyGuy FoamyGuy closed this Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants