Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange behavior when toggling drawing #40

Open
Subbeh opened this issue Sep 14, 2024 · 0 comments
Open

strange behavior when toggling drawing #40

Subbeh opened this issue Sep 14, 2024 · 0 comments

Comments

@Subbeh
Copy link

Subbeh commented Sep 14, 2024

I've been looking at this problem for a couple of days, and I'm really starting to doubt my sanity.

The following snippet is a simplified example that uses some questionable logic that makes more sense in the full context.

I have a button, an icon and a text item. The button toggles the icon and text to be drawn and triggers a function.
The toggling of the visibility works, but the function is only triggered when drawing = false.

local enabled = true
local reset_item

local function init_bar()
	local menu_icon = sbar.add("item", "menu.icon", {
		icon = {
			string = "M",
		},
	})

	local item_icon = sbar.add("item", "menu.item.icon", {
		icon = {
			string = "I",
		},
	})

	sbar.add("item", "menu.item.text", {
		label = "TEXT",
	})

	item_icon:subscribe({ "reset_items" }, reset_item)

	menu_icon:subscribe("mouse.clicked", function()
		enabled = not enabled -- inverse the boolean
		sbar.set("/menu\\.item\\..*/", { drawing = enabled }) -- toggle the menu visibility
		print("drawing = " .. tostring(enabled)) -- debug statement showing the value of "enabled"

		sbar.trigger("reset_items") -- trigger the reset_items function (DOES NOT RUN WHEN enabled = true)
	end)
end

reset_item = function()
	print("TEST")
end

init_bar()

The output when I press the button, setting drawing = false:

drawing = false
TEST

The output when I press the button, setting drawing = true:

drawing = true

I'm expecting the output to show TEST when drawing is set back to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant