UI Alignments

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
MehdiZangenehBar
Posts: 78
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

UI Alignments

Post by MehdiZangenehBar »

Is it possible to align any control to the right side of the toolbar? it seems LM.GUI.ALIGN_RIGHT dosn't effect at all.
Also is it possible to change width of the button? It seems this one is also missed.

Code: Select all

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

ScriptName = "TestScript"

TestScript = {}

function TestScript:Name()
	return 'Name'
end

function TestScript:Version()
	return 'Version'
end

function TestScript:UILabel()
	return 'UILabel'
end

function TestScript:Creator()
	return 'Creator'
end

function TestScript:Description()
	return 'Description'
end


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

function TestScript:IsRelevant(moho)
	return true
end

function TestScript:IsEnabled(moho)
	return true
end

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

function TestScript:OnMouseDown(moho, mouseEvent)
end

function TestScript:DoLayout(moho, layout)
	local button = LM.GUI.Button('Button', 0)
	layout:AddChild(button, LM.GUI.ALIGN_RIGHT, 0)
end
User avatar
synthsin75
Posts: 10051
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: UI Alignments

Post by synthsin75 »

This works for my screen resolution, but if you change the size of the Moho window, you'd have to reselect the tool to update to the new window dimensions.

Code: Select all

function TestScript:DoLayout(moho, layout)
	local button = LM.GUI.Button('Button', 0)
	layout:AddPadding(moho.view:Width() + 300)
	layout:AddChild(button, LM.GUI.ALIGN_RIGHT, 0)
end
It's really using the workspace view dimensions, because Moho doesn't natively report the window size to the API.
This example is resolution dependent, so to really make it useful, you'd need to query the OS about the screen resolution and window size.
Makes aligning to the right fairly impractical, unless you just want to align to the right side of the workspace.

You make buttons smaller using negative padding. If you want to see a master class in this technique, check out Rai's Shapes Window tool: viewtopic.php?t=36508
Post Reply