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

How to draw images on collectionView elements (rects) ? #500

Open
sgmihai opened this issue Aug 19, 2022 · 2 comments
Open

How to draw images on collectionView elements (rects) ? #500

sgmihai opened this issue Aug 19, 2022 · 2 comments

Comments

@sgmihai
Copy link

sgmihai commented Aug 19, 2022

I am trying to build a very basic gui mockup for my project, and I need a grid of images displayed (prefferably auto resizing to fit the collectionView, which should auto resize with the main window).
I tried modifying the https://github.com/yglukhov/nimx/blob/master/test/sample07_collections.nim code with what I found in https://github.com/yglukhov/nimx/blob/master/test/sample03_image.nim
but no success. Code I tried is here: https://play.nim-lang.org/#ix=480e
Basically I put

let c = currentContext()
c.drawImage(v.posters[i],result.frame)

in the last line of collectionView.viewForItem
I am not sure if it's the proper place or way to do this, in this context.
Result is this: https://i.imgur.com/eGEFGi4.png

I have no experience whatsoever with guis, and already spent half a day trying to figure it out, and another full day researching alternatives. In the end I think nimx is the shortest path to my goal. If only it had more complete and comprehensive docs.

@yglukhov
Copy link
Owner

CollectionViews are a bit outdated, as nimx is in the process of migration to new layout system. But what you're doing wrong is actually drawing the image in viewForItem while you should instead just return the view that will draw said image in its draw method. Smth along the lines of:

let imgView = newImageView(...)
# ... setup imgView
result.addSubview(imgView)

I couldn't play with your example as I could not find imdb dependency.

@sgmihai
Copy link
Author

sgmihai commented Aug 25, 2022

Complete code if you have time for it is here: https://drive.google.com/file/d/1Qq3DtlkfMkmMFSemHgRaiSRk6JDwnGw6/view?usp=sharing
compile gui_main.nim, as it was taken from your examples with the registerSample -> tabs.
first tab is gui_image.nim which has working loading of images (but no auto arranging)
gui_collections.nim is where I tried to achieve the results, the code above, and failed.

I see there is no draw method in that example, and not sure how to implement it, as I have no knowledge on the inner working of nimx, and the documentation is not helping there.

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

No branches or pull requests

2 participants