Window Management, Space, and Beyond
txUI can act as a full screen app for most applications but will seamlessly turn into a window manager with draggable windows and focussing built in.
Space
The 'background' of the txUI application is called 'space'. You can access the color variable in Controller.
txUI.Controller.spaceColor = colors.lightBlue
This line will set the space color to light blue.
Multi-window mode
txUI needs to know that you want multi-window mode to allow for more than one screen. This needs to be properly set for windows to be rendered correctly and the window logic run smoothly.
txUI.Controller.multiWindow = true
This line will enable multi-window mode.
Adding the first window
local w, h = term.getSize()
local window = txUI.Window:new({w = w - 5; h = h - 5; draggable = true; hasShadow = true; bgColor = colors.white; tlColor = colors.lightGray; shadowColor = colors.gray;})
txUI.Controller:addWindow(window)
You should be somewhat familiar with what these few lines are doing, I'll just be explaining some new parameters we can mess with in Window. 'draggable' defines whether you can drag this window with the title bar. 'hasShadow' defines whether the window has a shadow to increase ease of layer differentiation. 'shadowColor' is the color of the window's shadow.
If you try running your app at this point, you might notice that nothing happens. This is because the controller hasn't been told it's ready to start yet.
txUI.Controller:startUpdateCycle()
This line will start the Controller's update cycle.
coda
Keep this line at the end of the program. Your program might not run otherwise!
Now the app should start and render the window we just made. However, there doesn't seem to be a way to leave the app...
Closing a window
We're going to add the classic 'x' button to close a window.
window:addComponent(txUI.Button:new({x = 1; y = 1; w = 1; h = 1; action = (function(self) txUI.Controller:closeWindow(self.parent); end); textColor = colors.white; bgColor = window.tlColor; text = "x";}))
This line will add a close window button to window. Even if a window is already added to the Controller, you will still be able to add components to it.
Take Action
Note the action function and how it accomplishes closing the window.
Adding a second window
The code for creating the second window is much more compact since the Controller can clone components for you.
txUI.Controller:addWindow(txUI.Controller:cloneComponent(window))
This line clones the component and adds it to the Controller in one fell swoop.
The final touch
The app already does what it's supposed to but we can still add a bit of flare to keep things fresh.
txUI.Controller:addComponent(txUI.Label:new({x = 1; y = 9; w = w; text = "txUI Windows!"; textColor = colors.white; bgColor = colors.lightBlue;}))
This line adds a light label to the Controller.
Controller to Major Tom
Components added to the Controller will be rendered in space.
If nothing happens at this point, don't forget:
txUI.Controller:startUpdateCycle()
Updated less than a minute ago