How to handle adjusting gui elements with window resizing

Post Reply
User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

How to handle adjusting gui elements with window resizing

Post by demonnic »

The included pkg provides a framework for handling window resize events in mudlet. Explanation will be forthcoming... I'm sleep deprived and don't wanna muddle it up. =)

windowresize.xml
(498 Bytes) Downloaded 680 times

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: How to handle adjusting gui elements with window resizing

Post by demonnic »

Ok, I am going to take a stab at explaining this now.

This pkg adds a single script item, windowresize. It is setup in such a way that it calls the event windowresize whenever you resize your window. This is significant, because it allows you to call functions to move/resize your miniconsoles, labels, etc. when you resize your window.

For each gui element you have, you will want to write a function which handles the logic for where and how big to draw the element. For example, in the tabbed chat package I added to that thread, I created the following function

Code: Select all

function resize_chat_tabs()
  local global_width, global_height = getMainWindowSize()
  global_chatWidth = global_width
  global_chatTabWidth = 0.20 * global_chatWidth

  global_chatPosX = 0
  global_chatPosY = 0
  resizeWindow("buttonall", global_chatTabWidth, global_chatTabHeight)
  resizeWindow("buttonguild", global_chatTabWidth, global_chatTabHeight)
  resizeWindow("buttoncity", global_chatTabWidth, global_chatTabHeight)
  resizeWindow("buttonmarket", global_chatTabWidth, global_chatTabHeight)
  resizeWindow("buttonweb", global_chatTabWidth, global_chatTabHeight)
  moveWindow("buttonall", global_chatPosX, global_chatPosY)
  moveWindow("buttonguild", global_chatPosX + global_chatTabWidth, global_chatPosY)
  moveWindow("buttoncity", global_chatPosX + global_chatTabWidth * 2, global_chatPosY)
  moveWindow("buttonmarket", global_chatPosX + global_chatTabWidth * 3, global_chatPosY)
  moveWindow(buttonweb", global_chatPosX + global_chatTabWidth * 4, global_chatPosY)
  resizeWindow("chatall", global_chatWidth, global_chatHeight)
  resizeWindow("chatguild", global_chatWidth, global_chatHeight)
  resizeWindow("chatcity", global_chatWidth, global_chatHeight)
  resizeWindow("chatmarket", global_chatWidth, global_chatHeight)
  resizeWindow("chatweb", global_chatWidth, global_chatHeight)

end
Which recalculates the window and tab widths, etc, based on the new main window dimensions. You then place it within the function definition for windowresize() in this package, and it will be called whenever you resize the window. This would look like so:

Code: Select all

function windowsresize()
  resize_chat_tabs()
end

You can then add a function for each gui element in your setup, so that they are all called whenever the window is resized.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: How to handle adjusting gui elements with window resizing

Post by demonnic »

testing new forum functionality
Code: [show] | [select all] lua
    function resize_chat_tabs()
      local global_width, global_height = getMainWindowSize()
      global_chatWidth = global_width
      global_chatTabWidth = 0.20 * global_chatWidth

      global_chatPosX = 0
      global_chatPosY = 0
      resizeWindow("buttonall", global_chatTabWidth, global_chatTabHeight)
      resizeWindow("buttonguild", global_chatTabWidth, global_chatTabHeight)
      resizeWindow("buttoncity", global_chatTabWidth, global_chatTabHeight)
      resizeWindow("buttonmarket", global_chatTabWidth, global_chatTabHeight)
      resizeWindow("buttonweb", global_chatTabWidth, global_chatTabHeight)
      moveWindow("buttonall", global_chatPosX, global_chatPosY)
      moveWindow("buttonguild", global_chatPosX + global_chatTabWidth, global_chatPosY)
      moveWindow("buttoncity", global_chatPosX + global_chatTabWidth * 2, global_chatPosY)
      moveWindow("buttonmarket", global_chatPosX + global_chatTabWidth * 3, global_chatPosY)
      moveWindow(buttonweb", global_chatPosX + global_chatTabWidth * 4, global_chatPosY)
      resizeWindow("chatall", global_chatWidth, global_chatHeight)
      resizeWindow("chatguild", global_chatWidth, global_chatHeight)
      resizeWindow("chatcity", global_chatWidth, global_chatHeight)
      resizeWindow("chatmarket", global_chatWidth, global_chatHeight)
      resizeWindow("chatweb", global_chatWidth, global_chatHeight)

    end


guy
Posts: 26
Joined: Wed Mar 03, 2010 5:41 am
Location: Seattle

Re: How to handle adjusting gui elements with window resizing

Post by guy »

How is this different than overwriting handleWindowResizeEvent() as described in the manual?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: How to handle adjusting gui elements with window resizing

Post by demonnic »

Functionally, it's quite similar. However, if you overwrite that function multiple times with multiple packages, only the one which is rewritten last will take effect.

The upcoming release will, I believe, make this obsolete in any case.

guy
Posts: 26
Joined: Wed Mar 03, 2010 5:41 am
Location: Seattle

Re: How to handle adjusting gui elements with window resizing

Post by guy »

Ah ok. Has there been any work towards a general purpose layout manager? I've got some ideas for one, but if there's already a work in progress I'd rather hack on it.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: How to handle adjusting gui elements with window resizing

Post by Vadi »

Nay. I've got some ideas as well, PM me on forums or IRC

guy
Posts: 26
Joined: Wed Mar 03, 2010 5:41 am
Location: Seattle

Re: How to handle adjusting gui elements with window resizing

Post by guy »

Wrote you a PM but it's just sitting in the outbox and doesn't show up in sent. Problem or expected?

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: How to handle adjusting gui elements with window resizing

Post by Vadi »

Well, I did receive it.

Post Reply