omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    GridView

    Pythonista
    4
    7
    3646
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mikael
      mikael last edited by

      I find myself often creating small apps that need a clean UI, but nothing fancy, just boxes to show content in. Then I again code something quickly, placing a varying amount of squares on the screen with ad hoc math.

      Picture below is an example of such app, a dashboard for my e-Golf.

      GridView app sample image

      To avoid creating these types of screens over and over again, I created (yet another) GridView class. Its claim to fame lies in the fact that it does not scroll, neither do you need to set the size of the grid as fixed "x times y"; instead, you can just keep adding subviews to it, and it will use a bit of math to try to keep the layout as pleasing as possible.

      Basic usage is simple:

      gv = GridView()
      
      for view in my_views:
        gv.add_subview()
      

      GridView constructor takes a number of arguments, to fine-tune the layout:

      • gap - distance between boxes when tightly packed. Default is UIKit Standard 8 pt.
      • count_x, count_y - use these if you need to restrict the number of boxes in either direction.
      • pack_x, pack_y, pack - control the packing behaviour in either direction, or use the pack option to set both at ones. Picture below demonstrates different horizontal packing values. Default packing value in both directions is GridView.CENTER.

      GridView packing options

      Right now this class is part of the anchor module, but I might split it later.

      cvp 1 Reply Last reply Reply Quote 1
      • cvp
        cvp @mikael last edited by cvp

        @mikael 👍as usual in Finland

        mikael 1 Reply Last reply Reply Quote 0
        • jmv38
          jmv38 last edited by

          thank you
          when i run grid demo i have an error
          from lightanchor import *
          lightanchor is not present?

          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @jmv38 last edited by

            @jmv38, please change to just anchor, I will fix the source.

            1 Reply Last reply Reply Quote 0
            • mikael
              mikael @cvp last edited by

              @cvp, 😜

              1 Reply Last reply Reply Quote 0
              • jmv38
                jmv38 last edited by

                @mikael thank you, now it works

                1 Reply Last reply Reply Quote 0
                • sam rod
                  sam rod last edited by

                  it may work on a scrollview

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors