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.


    Flex and ui object initial settings - Chicken before egg?

    Pythonista
    flex
    3
    3
    2427
    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.
    • Phuket2
      Phuket2 last edited by

      @omz. Sorry in advance if this post is stupid. I am back to looking at flex attrs again. It's been some time since I was looking at these. But it seems to me there is a gap here in the logic. (Hmmm, cant believe I wrote that :) )
      I have re-wrote this msg a few times as i am finding hard to explain.

      I will try to explain:
      Let's say I want prepare a ui.View that will have a height = 60 and be the width of its superview and be anchored to its x,y coord. So I want to be able to set the flex attr and the height of the view. But as far as the width goes I dont know what the width will be.
      As far as I know this is not possible at the moment without using the layout method! I think that is correct. (Maybe I am wrong)
      But If thats correct, would it make sense to have sentinel values for width and height like -1 to depict the superview's width/height. Maybe that's really bad form, maybe new attrs could be added for the elasticity of the width/height of a form.

      Maybe I am in La La land again. But as far as I can tell/remember you cant fully define a views complete composition and elasticity without either first knowing its superview bounds or using the layout method. Would be nice if you could do this all ahead of time without any knowledge of the view or having to write a layout method. I guess that means more work for Pythonista under the hood.

      But I personally find in the current system it's not quite there. Hence the chicken and egg reference. Getting a little late here now, Hope what I have written makes sense

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

        Not ideal, but you can do this (without layout):

        from ui import *
        
        class MyView(View):
            def __init__(self):
                self.background_color = 'white'
                
                yellow = View(background_color='yellow', flex='RBW')
                yellow.frame = (20, 20, self.width - 20, 60)
                self.add_subview(yellow)
                
        v = MyView()
        v.present('fullscreen')
        
        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          One approach is to define everything based off a default width, then let present resize for you. I usually lazily do this:

          root=ui.View() #for now, default is 0,0,100,100
          v=ui.View(frame=(0, 0,root.width, 60))
          v.flex='w' # height, x, and y are fixed, in absolute pixels
          root.present() # will be resized

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