flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
289 stars 25 forks source link

How to programmatically set a window to a dock position? Also make docked window unremovable there #92

Closed flamendless closed 3 years ago

chicogamedev commented 3 years ago

Same question here. I need this too.

flamendless commented 3 years ago

@chicogamedev just implemented this in commit c77087df531e48a2e834e90cef65541455f2c040

sample usage would be:

    Slab.BeginWindow("test", {Title = "test"})
        Slab.WindowToDoc("Left")
    Slab.EndWindow()

For now users are to handle when they want to remove the window to the dock by using boolean flag to control whether to call Slab.WindowToDoc. As you can see that this can also be used to permanently set a window to a dock.

Let me know if there's an issue with this. I may have missed out on some.

chicogamedev commented 3 years ago

Awesome !

I'll try it out. But is there a way to preset the size (Width) of the docked window ?

Or will it adapt on the W of the window?

Thanks

flamendless commented 3 years ago

@chicogamedev this is fixed now. Sample usage would be:

local flag = false
local flag2 = false
local flag3 = false

function love.update(dt)
    Slab.Update(dt)
    -- SlabTest.Begin()
    Slab.BeginWindow("test", {
        Title = "test",
        W = 320,
    })
        if not flag then
            Slab.WindowToDock("Left")
            flag = true
        end
    Slab.EndWindow()

    Slab.BeginWindow("test2", {
        Title = "test2",
        W = 160,
    })
        if not flag2 then
            Slab.WindowToDock("Right")
            flag2 = true
        end
    Slab.EndWindow()

    Slab.BeginWindow("test3", {
        Title = "test3",
        H = 120
    })
        if not flag3 then
            Slab.WindowToDock("Bottom")
            flag3 = true
        end
    Slab.EndWindow()
end

Right now W can only be used for Left and Right docks while H for Bottom

( i have to think more how to make it so that the flags are stored internally in Slab's side)