Page 1 of 1

Update UI

Posted: Sat Apr 27, 2024 2:56 pm
by MehdiZangenehBar
is it possible to add item to the toolbar, outside DoLayout event? on UpdateWidget?

Re: Update UI

Posted: Sat Apr 27, 2024 6:42 pm
by synthsin75
You have to get it to reevaluate the DoLayout function.
I do this in my switch icons script by jumping to/from frame zero.

Re: Update UI

Posted: Sat Apr 27, 2024 8:44 pm
by MehdiZangenehBar
Are you sure changing frame to zero will trigger DoLayout?

Code: Select all

-- **************************************************
-- General information about this script
-- **************************************************

ScriptName = "Test_Script"

Test_Script = {}

function Test_Script:Name()
	return 'Test Script'
end

function Test_Script:Version()
	return '1.0'
end

function Test_Script:UILabel()
	return 'Test Script'
end

function Test_Script:Creator()
	return 'Test'
end

function Test_Script:Description()
	return 'Test'
end


-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************

function Test_Script:IsRelevant(moho)
	print('IsRelevant')
	return true
end

function Test_Script:IsEnabled(moho)
	print('IsEnabled')
	return true
end

-- **************************************************
-- Events
-- **************************************************

function Test_Script:OnMouseDown(moho, mouseEvent)
	print('OnMouseDown')
end

function Test_Script:UpdateWidgets(moho)
	print('UpdateWidgets')
end

function Test_Script:HandleMessage(msg)
	print('HandleMessage')
end

function Test_Script:DoLayout(moho, layout)
	print('DoLayout')

	local simple_dialog = LM.GUI.SimpleDialog('', {})
	local popup_dialog = LM.GUI.PopupDialog('Test', true, 0)
	popup_dialog:SetDialog(simple_dialog)
	layout:AddChild(popup_dialog, LM.GUI.ALIGN_LEFT, 0)

end

Re: Update UI

Posted: Sat Apr 27, 2024 8:45 pm
by MehdiZangenehBar
And I don't know where is your script.

Re: Update UI

Posted: Sat Apr 27, 2024 9:05 pm
by synthsin75
Here's the script: viewtopic.php?t=34078

At line 596, in the HandleMessage function, I do this:

Code: Select all

	if (msg == self.UPDATE or msg == self.ALT_UPDATE or msg == self.DELETE) then
		local frame = moho.frame
		if (frame == 0) then
			moho:SetCurFrame(1)
		else
			moho:SetCurFrame(0)
		end
		moho:SetCurFrame(frame)
	end

Re: Update UI

Posted: Sat Apr 27, 2024 10:50 pm
by MehdiZangenehBar
I run your script and still changing layer selection will not update the UI.
However your solution works in updatewidgets for me. nice trick, thanks!

Re: Update UI

Posted: Sun Apr 28, 2024 2:04 am
by MehdiZangenehBar
I did some other test and realized your code dosn't work when we change from group to another group. So I mixed with the layer creation and deletion:

Code: Select all

			local current_frame = moho.frame
			moho:SetCurFrame(0)
			local temp_layer = moho:CreateNewLayer(MOHO.LT_SWITCH, false)
			moho:SetCurFrame(1)
			moho:SetCurFrame(0)
			moho:DeleteLayer(temp_layer)
			moho:SetCurFrame(current_frame)

Re: Update UI

Posted: Sun Apr 28, 2024 5:20 am
by synthsin75
Yeah, I have a note in the code about group layer selections. I believe that problem was introduced in a later version of Moho, after I initially wrote the script.
I'll have to see about incorporating your layer creation hack.

Thanks.

Re: Update UI

Posted: Sun Apr 28, 2024 1:11 pm
by MehdiZangenehBar
Yea, and I created a boolean flag to prevent dependency loop and prevent UpdateWidget- DoLayout events call himself multiple times.
Another improvement would be to check the layer type and create different layer type to force the update.