Pyroxenium / Basalt

A UI Framework for CC:Tweaked
MIT License
194 stars 38 forks source link

bug: Container.removeChild does not work with strings #108

Closed WorldChallenge1 closed 7 months ago

WorldChallenge1 commented 7 months ago

Describe the bug

When trying to use the function removeChild with an ID of an element this gives an error

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://basalt.madefor.cc/#/objects/Container/removeChild
  2. Copy the example
  3. Run it
  4. See error in the 1st screenshot

Expected behavior

The specified children of the container gets removed.

Probable cause

The problems seems to be that when passing a string it tries to call the method getName() which is a method of basalt Object's (2nd screenshot)

Screenshots

Code_gCAWxLm3vT brave_BbiDgzqQDV

Checklist

[x] I am running the latest version.

WorldChallenge1 commented 7 months ago

Also when passing the object it does work

local basalt = require("basalt")

local main = basalt.createFrame()
local container = main:addFrame("container")
local button = container:addButton("removableButton")
    :setPosition(2, 2)
    :setText("Remove me")

main:addButton()
    :setPosition(2, 4)
    :setText("Remove the button above")
    :onClick(function()
        local removed = container:removeChild(button)
        if removed then
            basalt.debug("Button removed!")
        else
            basalt.debug("Button not found!")
        end
    end)

basalt.autoUpdate()

Code_7nCkHqcEcI

In a related note Flexbox seems to not work at all either way

local basalt = require("basalt")

local main = basalt.createFrame()
local container = main:addFlexbox("container")
local button = container:addButton("removableButton")
    :setPosition(2, 2)
    :setText("Remove me")

main:addButton()
    :setPosition(2, 4)
    :setText("Remove the button above")
    :onClick(function()
        local removed = container:removeChild("removableButton")
        if removed then
            basalt.debug("Button removed!")
        else
            basalt.debug("Button not found!")
        end
    end)

basalt.autoUpdate()

Code_68sACyIajk

Using the object it doesn't crash but it is unable to find the child

local basalt = require("basalt")

local main = basalt.createFrame()
local container = main:addFlexbox("container")
local button = container:addButton("removableButton")
    :setPosition(2, 2)
    :setText("Remove me")

main:addButton()
    :setPosition(2, 4)
    :setText("Remove the button above")
    :onClick(function()
        local removed = container:removeChild(button)
        if removed then
            basalt.debug("Button removed!")
        else
            basalt.debug("Button not found!")
        end
    end)

basalt.autoUpdate()

Code_ayYKcZ8HdS

NoryiE commented 7 months ago

Hey, i think it is fixed now. I didn't try the flexbox. Thank you for the report!

WorldChallenge1 commented 7 months ago

Downloaded the source and tried all the examples and they all worked without problems. Thanks!