drawing in custom views
Sorry for what is likely a dumb question, but I'd appreciate any help I can get:
To start: my wife asked me to build a simple "behavior tracker" for the kids, which seemed like a good first project for me. System is simple: kids start out green, and based on user input they can move through yellow to red (and back) based on their behavior throughout the day. Ultimately, I'd like to have an archive/calendar view that we can look back at to show the kids how they ended each day, but right now am just trying to get the basic functionality working.
I've got a view built in the UI builder that has a couple different subviews built in to it. I've been able to successfully capture the appropriate touch events that enables me to touch each subview's area, and with swipes either way it adjusts the color, somewhat similar to a slider, but based on the x coordinate of the touch event.
I'd like to have an oval (or maybe even an image at some point, so the kids can choose an icon or little avatar) drawn in the subview when the user lifts their finger, so the last position has a visual mark to identify the last set position (in addition to the color, which already works), but I can't for the life of me get one to draw. Can anyone help me out with this?
Much appreciate it!
What gave you tried?
Have you tried the example in ImageContext or Drawing Contexts in the ui docs?
I can duplicate the image context example, but I need the image drawn into my view, not the console, and I can't get that to work. My overridden draw method inside the custom view class works fine, but I can't get that to behave how I'd like it (it just draws my oval once, and it's a one shot deal, every time the code is run. I thought an easy solution might be to pass some arguments into that draw method, but no joy.
I'd looked at the sketch example, but some of the interaction between the various types of views is a little over my head, so I haven't been able to use that to any advantage yet.
Can you please put some sample code into a GitHub repo so that we can debug it together?
iietdpctep - It Is Easier To Debug Python Code Than English Prose.
Doh! Code is here: https://gist.github.com/ffafacbf6bbe02f94cf2
I added comments on the gist.
Instantiating the self.path did the trick. After going back thru the docs, that totally makes sense...never would have gotten there on my own tho. Thanks a ton!