View Single Post
06-24-09, 06:44 PM   #11
spiel2001
nUI's Author
 
spiel2001's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 7,724
Xyrstal --

There's actually a mechanism built into the info panel plugin system already to make this more "automatic" -- the "plugin.sizeChanged" method passes you in a scale as well as height and width of the container.

There are a couple of options.

1) You can set the button size in that method using something like button.SetWidth( btnWidth * scale ) and find a value for btnWidth that makes it fit... then as the scale increases or decreases, hopefully the button would, too.

2) Take the width argument and divide it by the number of buttons you want to display across the panel and use the result to set the button height and width... that way the buttons always fit exactly across the width of the panel even if the panel size changes -- you can, of course, subtract a bit from the width to add that as a gap between the buttons, as well.

You could do something like this...

Code:
plugin.sizeChanged = function( scale, height, width )
    
    local cellWidth = width / 6;
    local btnSize = cellWidth * 0.95;
    local btnGap = cellWidth * 0.05;
    local verticalOffset = 0; -- how far up or down from center to put the button

    for i=1,6 do
        button[i]:SetWidth( btnSize );
        button[i]:SetHeight( btnSize );
    end

    button[1]:SetPoint( "RIGHT", button[2], "LEFT", -btnGap, 0 );
    button[2]:SetPoint( "RIGHT", button[3], "LEFT", -btnGap, 0 );
    button[3]:SetPoint( "RIGHT", plugin.container, "CENTER", -btnGap/2, verticalOffset );
    button[4]:SetPoint( "LEFT", plugin.container, "CENTER", btnGap/2, verticalOffset );
    button[5]:SetPoint( "LEFT", button[4], "RIGHT", btnGap, 0 );
    button[6]:SetPoint( "LEFT", button[5], "RIGHT", btnGap, 0 );
end
With something of that nature, no matter how much the size of the plugin changes, it will always center 6 buttons across the width of the window with a small gap between each button. You can probably figure out what I'm doing from there to tweak it.

This way your plugin works at all resolutions without the user having to tweak anything.

PS: Note... I'm using button[i] as a symbol for your buttons... I haven't looked at how you have it coded, so I'm generalizing. button[1] is your first button, button[2] your second button and so on.
__________________

What people don't get is that I am, ultimately, an artist at heart.
My brush has two colors, 1 and 0, and my canvas is made of silicon.



Official nUI Web Site: http://www.nUIaddon.com
Official nUI Support Forum: http://forums.nUIaddon.com
My day job: http://www.presidio.com/

Last edited by spiel2001 : 06-25-09 at 08:36 AM.