robotools / vanilla

A Pythonic wrapper around Cocoa.
MIT License
78 stars 28 forks source link

Dont use the contentView to add to rules but the _nsObject itself #121

Closed typemytype closed 4 years ago

typemytype commented 4 years ago

similar to what happens with a posSize approache: the child view, the _nsobject view, is added to the parent contentview

fixes #120

typemytype commented 4 years ago

there are still some weird things going on with vanilla.Tabs. Will check on a different OS...

typemytype commented 4 years ago

This seems to work:

see how the last addAutoPosSizeRules is called after opening of the window, otherwise a VanillaTabItem does not know his bounds to apply those rules.

class TabViewAutoLayout:

    def __init__(self):
        self.w = Window((250, 296))
        self.w.tab = Tabs("auto", ["hello", "world"])

        tabRules = [
            # Horizontal
            "H:|-border-[text]-border-|",
            # Vertical
            "V:|-border-[text]-border-|"
        ]
        rules = [
            # Horizontal
            "H:|-border-[tab]-border-|",
            # Vertical
            "V:|-border-[tab]-border-|"
        ]
        metrics = {
            "border" : 10,
        }

        hello = self.w.tab[0]
        hello.text = TextBox("auto", "hello")
        #hello.text = TextBox((10, 10, -10, 22), "hello")
        hello.addAutoPosSizeRules(tabRules, metrics) 

        world = self.w.tab[1]
        world.text = TextBox("auto", "world")
        world.addAutoPosSizeRules(tabRules, metrics) 

        self.w.open()        
        self.w.addAutoPosSizeRules(rules, metrics)    

TabViewAutoLayout()

Screen Shot 2020-06-30 at 13 43 20

typemytype commented 4 years ago

this also works well: the second tab view expands the windows

class TabViewAutoLayout:

    def __init__(self):
        self.w = Window((250, 296))
        self.w.tab = Tabs("auto", ["hello", "world"])

        tabRules = [
            # Horizontal
            "H:|-border-[text]-border-|",
            # Vertical
            "V:|-border-[text]-border-|"
        ]
        rules = [
            # Horizontal
            "H:|-border-[tab]-border-|",
            # Vertical
            "V:|-border-[tab]-border-|"
        ]
        metrics = {
            "border" : 10,
        }

        hello = self.w.tab[0]
        hello.text = TextBox("auto", "hello")
        #hello.text = TextBox((10, 10, -10, 22), "hello")
        hello.addAutoPosSizeRules(tabRules, metrics) 

        tabWorldRules = [
            # Horizontal
            "H:|-border-[text]-border-|",
            "H:|-border-[text2]-border-|",
            # Vertical
            "V:|-border-[text]-border-[text2]-border-|"
        ]
        world = self.w.tab[1]
        world.text = TextBox("auto", "world")
        world.text2 = TextBox("auto", "world")
        world.addAutoPosSizeRules(tabWorldRules, metrics) 

        self.w.open()     
        self.w.addAutoPosSizeRules(rules, metrics)       

TabViewAutoLayout()