LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Tutorials & Other Helpful Information (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=21)
-   -   How to make a Window resizable (https://www.lotrointerface.com/forums/showthread.php?t=2006)

wmrojer 04-22-2013 07:54 AM

How to make a Window resizable
 
Since I see that a lot of plugins does not support rezising of there windows, and I really like to be able to resize them I'm writing a short guide on how to make windows resizable.

The Easy way:

First of the window must be of type Turbine.UI.Lotro.Window

This code is simplified and will not make a working window. It just shows the stuff that needed for the resizing to wrok.
Code:

ListWindow = class(Turbine.UI.Lotro.Window);

function ListWindow:Constructor()
        Turbine.UI.Lotro.Window.Constructor(self);

        self:SetSize(Settings.listWidth, Settings.listHeight);
        self:SetMaximumSize(500,1200);
        self:SetMinimumSize(300,200);
        self:SetResizable(true);
      --- Here should be the creation of our child controls
end

function ListWindow:SizeChanged(args)
        Settings.listWidth, Settings.listHeight = self:GetSize();
        -- Resize our child windows
        self.listTree:SetSize(Settings.listWidth-20,  Settings.listHeight-50);
        self.listScrollBar:SetHeight(Settings.listHeight-50);
        self.listScrollBar:SetLeft(Settings.listWidth-20);
end

self:SetMaximumSize(500,1200) defines the largest size we want to allow the window to be resized to.

self:SetMinimumSize(300,1200) defines the smallest size we want to all the window to be resized to.

self:SetResizable(true) is where the magic is. This tells Lotro that the user should be able to resize the window. Mouse pointer will automatically change when positioned over the lower and right border of the window.

function ListWindow:SeizeChanged(args) is where we catch the rezising of the window. Here we need to reposition and resize all our child controls.

It is actually this easy to make a window resizable. The biggest part is the SizeChanged method where we need to resize and reposition our child controls.

Wicky71 05-05-2013 01:31 PM

Window resizable extension
 
The code works fine, but when you load the plugin with the Plugin Manager it generates an error massage. After the first resizing it works fine.

The magic is to define the resizable controls bevor the size define of the window.

Code:

ListWindow = class(Turbine.UI.Lotro.Window);

function ListWindow:Constructor()
        Turbine.UI.Lotro.Window.Constructor(self);
--- define section for resizable controls

--- define section for resizable controls

        self:SetSize(Settings.listWidth, Settings.listHeight);
        self:SetMaximumSize(500,1200);
        self:SetMinimumSize(300,200);
        self:SetResizable(true);
      --- Here should be the creation of our child controls
end

function ListWindow:SizeChanged(args)
        Settings.listWidth, Settings.listHeight = self:GetSize();
        -- Resize our child windows
        self.listTree:SetSize(Settings.listWidth-20,  Settings.listHeight-50);
        self.listScrollBar:SetHeight(Settings.listHeight-50);
        self.listScrollBar:SetLeft(Settings.listWidth-20);
end

The reason is that "self:SetSize(Settings.listWidth, Settings.listHeight);" calls the function "SizeChangend". At this time the objects are still unknown in the plugin.

MercedMike 05-06-2013 08:28 AM

Resizing
 
I want to do the other way --

Have a window which is normally resizable open up at a different size than the usual default.

Can that be done?

Thanks!

Wicky71 05-06-2013 01:41 PM

Resizing
 
Quote:

I want to do the other way --

Have a window which is normally resizable open up at a different size than the usual default.

Can that be done?
The code "self:SetSize(Settings.listWidth, Settings.listHeight);" fix the size of the window.

"Settings.listWidth" and "Settings.listHeight" are variables loadet from the saved plugin options. It can also numbers are there

A usual default (standart size you mean?) does not exist.

Hope it helps


All times are GMT -5. The time now is 02:19 AM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI