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.


    Make subview fit to parent view frame?

    Pythonista
    size subvi view frame parent
    2
    2
    1880
    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.
    • shinyformica
      shinyformica last edited by

      Having trouble finding any topics on here which address this: I have a parent View which I present as a sheet, and I programmatically add a subview to it, but I want that subview to be constrained to the size of its parent view.

      I thought that setting the subview flex to 'WH' might do it, or setting the parent view's content_mode to ui.CONTENT_SCALE_TO_FILL might do it. But the subview always sets its size to whatever its frame is set to, and doesn't fill or shrink to the parent view.

      Here's ultra-simplistic code:

      v = ui.load_view("base_view.pyui")
      
      sub = ui.Button()
      sub.frame(0,0,100,30)
      sub.title = "Button"
      sub.flex = "WH"
      sub.border_width = 1
      
      v.add_subview(sub)
      v.present("sheet")
      

      base_view.pyui is just a View with a size, no content, no custom View class.
      This loads and presents fine, the button is visible at the assigned size and position...but I want a way to make sure it sizes itself to the parent view automatically (not by directly setting its frame to that of its parent). Is this doable?

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

        @shinyformica, if I understand your requirement right, it is as simple as:

        button.frame = v.bounds
        button.flex = 'WH'
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors