Window Element
Window is a module that provides functionality for creating and managing GUI windows.
It handles window creation, event management, and provides signals for various window interactions.
Window Element Element LuaRT Element
Constructor
Window.new() Function
Window.new(WindowProperties)
- Creates a new window instance with the specified properties.
Parameters:
-
titlestring- Title of the Window.
-
styleEnum.WindowStyle- Style of the Window.
-
widthnumber- Width of the Window.
-
heightnumber- Height of the Window.
-
allowdropboolean?- Whether the Window is a drag and drop target.
-
cursorEnum.CursorStyle?- Mouse cursor image when hovering over the Window.
-
xnumber?- Horizontal position of the Window.
-
ynumber?- Vertical position of the Window.
-
enabledboolean?- Whether the Window responds to events.
-
visibleboolean?- Whether the Window appears onscreen.
-
transparencynumber?- Window's transparency intensity.
-
childstable?- READONLY: List of child widgets of the Window.
-
parentWindow?- READONLY: Parent Window. Probably
"root",checkWeo Corefor parent handling.
- READONLY: Parent Window. Probably
-
monitortable?- READONLY: Monitor in which the Window is located.
-
topmostboolean?- Whether the Window stays above others.
-
fullscreenboolean?- Whether the Window is fullscreen.
-
fontstring?- Font family.
-
fontstylestring?- Font style.
-
fontsizenumber?- Font size.
-
bgcolornumber?LinearGradient?RadialGradient?- Background color of the Window,it's pointless after creating a
RenderSurfaceelement.
- Background color of the Window,it's pointless after creating a
-
traytooltipstring?- Tooltip for the tray icon.
-
iconstring?- Icon path for the tray icon.
Please use
(Window):loadicon(path,index)to load the icon instead of this property.
Signals
(Window).Shown Signal
- Fires when the window is shown.
(Window).Hidden Signal
- Fires when the window is hidden.
(Window).Closed Signal
- Fires when the window is closed.
(Window).Moved Signal
- Fires when the window is moved.
Parameters:
- position Vector2— new window position
(Window).Resized Signal
- Fires when the window is resized.
Parameters:
- width number— new window width
- height number— new window height
(Window).MouseButton1Click Signal
- Fires when left mouse button is clicked on the window.
Parameters:
- position Vector2— click position relative to window
(Window).MouseButton2Click Signal
- Fires when right mouse button is clicked on the window.
Parameters:
- position Vector2— click position relative to window
(Window).MouseHover Signal
- Fires when mouse hovers over the window.
Parameters:
- position Vector2— hover position relative to window
- buttons table— mouse buttons state
- Table containing mouse button states:
left— Left mouse button state.middle— Middle mouse button state.right— Right mouse button state.control— Control key state.shift— Shift key state.
- Table containing mouse button states:
(Window).KeyDown Signal
- Fires when a keyboard key is pressed while window has focus.
Parameters:
- key string— the pressed key
(Window).Created Signal
- Fires when the window is successfully created.
(Window).MouseButtonDown Signal
- Fires when left mouse button is pressed down.
Parameters:
- position Vector2— mouse position relative to window
- buttons table— mouse buttons state
- Table containing mouse button states:
left— Left mouse button state.middle— Middle mouse button state.right— Right mouse button state.control— Control key state.shift— Shift key state.
- Table containing mouse button states:
(Window).MouseButtonUp Signal
- Fires when left mouse button is released.
Parameters:
- position Vector2— mouse position relative to window
- buttons table— mouse buttons state
- Table containing mouse button states:
left— Left mouse button state.middle— Middle mouse button state.right— Right mouse button state.control— Control key state.shift— Shift key state.
- Table containing mouse button states:
(Window).Minimized Signal
- Fires when the window is minimized.
(Window).Maximized Signal
- Fires when the window is maximized.
(Window).Restored Signal
- Fires when the window is restored from minimized/maximized state.
(Window).ContentDropped Signal
- Fires when content is dropped onto the window (drag-and-drop).
Parameters:
- kind string— type of dropped content
"text"|"files"|"unknown" - content any— the dropped content
string|{[index] = File}|nil
(Window).ThemeChanged Signal
- Fires when the system theme changes.
Parameters:
- theme string—
"dark"or"light"
System Tray Signals
- Check
(Window):loadtrayicon(path, index)and(Window).traytooltip.
(Window).TrayClicked Signal
- Fires when the system tray icon is clicked.
(Window).TrayDoubleClicked Signal
- Fires when the system tray icon is double-clicked.
(Window).TrayMouseHover Signal
- Fires when mouse hovers over the system tray icon.
(Window).TrayMouse2Click Signal
- Fires when right mouse button is clicked on the system tray icon.
Methods
- These methods are provided by LuaRT itself.
(Window):center()
- Centers the window on its parent.
(Window):show() Method
Windows that created by Weo starts shown by default.
- Makes the window visible.
(Window):hide() Method
- Hides the window.
(Window):showmodal() Method
(Window):showmodal(child)
- Shows another window as modal.
Parameters:
- child — the window to show as modal
(Window):minimize() Method
- Minimizes the window to the taskbar.
(Window):maximize() Method
- Maximizes the window.
(Window):restore() Method
- Restores previous size and position.
(Window):startmoving() Method
- Begins dragging the window.
(Window):popup() Method
(Window):popup(menu)
- Shows a popup menu (LuaRT Element) at the mouse position.
Parameters:
- menu — the menu to display
(Window):shortcut() Method
(Window):shortcut(key, callback, ctrl, shift, alt)
- Registers a keyboard shortcut.
Please use
Input Serviceto register keyboard shortcuts, not this method.
Parameters:
- key — the key to register
- callback — function to call when shortcut is triggered
- ctrl — whether Ctrl key is required (boolean)
- shift — whether Shift key is required (boolean)
- alt — whether Alt key is required (boolean)
(Window):loadicon() Method
(Window):loadicon(path, index)
- Loads an icon for the window.
Parameters:
- path — path to the icon file
- index — index of the icon in the file
Returns:
booleanboolean
(Window):notify() Method
(Window):notify(title, message, iconstyle)
- Sends a Windows notification.
Please use
Notifyto send notifications, not this method.
Parameters:
- title — notification title
- message — notification message
- iconstyle — style of the notification icon
Returns:
booleanboolean
(Window):loadtrayicon() Method
(Window):loadtrayicon(path, index)
- Loads a tray icon.
Parameters:
- path — path to the icon file
- index — index of the icon in the file
Returns:
booleanboolean
(Window):status() Method
(Window):status(...)
- Displays messages in the status bar.
Parameters:
- ... — variable arguments for status messages
(Window):tofront() Method
- Brings the window to front.
(Window):toback() Method
- Sends the window to back.
Example
local Weo = require("Weo.core.Weo")
local window = Window.new {
style = Enum.WindowStyle.Dialog,
title = "Weo",
width = 640,
height = 480,
allowdrop = true,
}
window.MouseButton1Click:Connect(function(Position)
window:status("X: " .. Position.x .. " Y: " .. Position.y, "LMB")
end)
window.MouseButton2Click:Connect(function(Position)
window:status("X: " .. Position.x .. " Y: " .. Position.y, "RMB")
end)
Input.InputBegan:Connect(function(input)
if input.InputType == Enum.InputType.Keyboard then
if input.InputCode == Enum.VirtualKeyCodes.Key.ESCAPE then
UpdateService:Kill()
end
end
end)
UpdateService.Heartbeat:Connect(function(DeltaTime)
window:status("FPS: " .. math.floor(1 / DeltaTime))
end)
UpdateService:Run(100)
Notes
- See LuaRT Window Documentation for details.
- The
parentproperty is automatically set to "root" if the parent equals the window itself. SeeWeo Corefor parent handling. RenderSurfacestops updating:onPaint()after the window hidden and shown again. It's a known bug in LuaRT 2.0.1 x64 and not an issue of Weo.- You can force
(RenderSurface):Refresh(force : boolean)to updateRenderSurfacewithUpdateService.Heartbeat, but performance is not guaranteed since this is a workaround for the issue.
- You can force