Skip to content
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

ModalView: Updating ModalView to improve theming #6469

Merged
merged 4 commits into from
Nov 7, 2019
Merged

ModalView: Updating ModalView to improve theming #6469

merged 4 commits into from
Nov 7, 2019

Conversation

snuq
Copy link
Contributor

@snuq snuq commented Aug 14, 2019

Some simple proposed changes to the ModalView class to make its background_color behave more closely to the same variable in other classes in kivy. Also, added overlay_color variable to allow independent setting of the 'fade out' color when a popup is activated.

Note that the doc string for background_color is copied from the Button class, hopefully they parse correctly, I do not know anything about the documentation format or how to test it.

@welcome
Copy link

welcome bot commented Aug 14, 2019

Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines.

@snuq
Copy link
Contributor Author

snuq commented Aug 14, 2019

i believe this will fix
#2198
as well, tho it is difficult to tell without the user's code available.

@@ -490,14 +490,14 @@

# ModalView widget
<ModalView>:
canvas:
canvas.before:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason to use canvas.before? I think canvas is probably a better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble with it since the usual way to change the background image via canvas is using canvas.before, and when you try to use a canvas.before on a Popup (which is a child class of ModalView), it is completely overlayed by this, and the only way to effectively nullify this is to use a transparent png as the background image.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @matham mentioned on discord, the canvas is itself ordered background to foreground, the point of canvas.before and canvas.after is to bypass that ordering when adding instructions in different places (in which case managing the single flattened canvas list is inconvenient). When you make a widget like this, you have full control over the ordering, so it's usually best to do everything on the normal canvas.

This is especially important for Kivy's own widgets, because these are building blocks that many apps will use. They generally want to avoid using the canvas.before and canvas.after specifically because that makes it harder for users to do their own drawing before and after the Kivy widget. Also note that 'drawing' encompasses more than displaying shapes, but also context instructions, see below.

Your change here is well motivated, but I think it's still the worse choice - if anything, the fact that the ModalView draws an opaque background image by default may be the bad part of the api. As I would see it, this change breaks the normal convention: you've specifically made canvas.before draw after the widget, which is the opposite of its normal behaviour. I understand why it may be initially surprising that drawing a background before everything else means it's behind the image that the widget displays...but isn't that what you should expect? That's why it's called canvas.before!

There may be other practical issues. For instance, users would normally expect that using a Rotate or Translate instruction on canvas.before would affect the widget, but this would not work here.

For these reasons, I think using canvas is the most consistent and preferable option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, setting the background_color to have 0 opacity should be a more convenient alternative to using a transparent png.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, you are right about the background_color, i was thinking about adding this with the way it used to behave (i had to do the hack of making the background transparent on my app to get it to work properly).
What do you think about making the opacity fadeout thing a canvas.before, and the background image itself canvas? Not asking for any usability reasons, just does that seem to make more sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial reaction is that even the fadeout should probably be on the canvas rather than canvas.before, simply because I don't see a major reason not to do it, but if you have a good reason for it then that could be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I dont have a good reason for putting it on canvas.before, just thought it made sense so I would suggest it, either way is fine by me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it back to just use canvas.

Copy link
Member

@inclement inclement left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @snuq, thanks for your patience in working through the issues.

I'm mildly concerned about this being a breaking change, but have no major objection to merging it if we're happy with that. @tshirtman how does the break look to you?

@matham matham added the Notes: API-break API was broken with backwards incompatibality label Aug 18, 2019
@misl6
Copy link
Member

misl6 commented Sep 6, 2019

I had the oppurtunity to check this PR on a project I'm working on, on my side it's working fine.

@tshirtman
Copy link
Member

Nice work @snuq, thanks for your patience in working through the issues.

I'm mildly concerned about this being a breaking change, but have no major objection to merging it if we're happy with that. @tshirtman how does the break look to you?

i think this change is indeed for the better, the current way certainly prevent some reusability of the widget, and the api is not clear, since this is a 2.0 i think i'm ok with such breaks. But i don't have a lot of kivy apps to maintain currently, so i'm not very impacted.

@tshirtman tshirtman merged commit 7036fde into kivy:master Nov 7, 2019
@welcome
Copy link

welcome bot commented Nov 7, 2019

Congrats on merging your first pull request! 🎉🎉🎉

@matham matham added this to the 2.0.0 milestone Oct 28, 2020
@matham matham changed the title Updating ModalView to improve theming ModalView: Updating ModalView to improve theming Dec 8, 2020
@matham matham added the Component: Widgets kivy/uix, style.kv label Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Widgets kivy/uix, style.kv Notes: API-break API was broken with backwards incompatibality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants