Expose structs to Lua and write Lua type annotations #28
|
@ -1,4 +1,6 @@
|
|||
HAS_SETUP_WINDOW = false
|
||||
--local win = require "scripts.window"
|
||||
|
||||
local is_window_setup = false
|
||||
|
||||
---Return the userdata's name from its metatable.
|
||||
---
|
||||
|
@ -31,14 +33,16 @@ function on_init()
|
|||
end
|
||||
|
||||
function on_first()
|
||||
if not HAS_SETUP_WINDOW then
|
||||
world:view(function (w)
|
||||
if not is_window_setup then
|
||||
world:view(
|
||||
---@param w Window
|
||||
function (w)
|
||||
if w.cursor_grab == CursorGrabMode.NONE then
|
||||
w.cursor_grab = CursorGrabMode.LOCKED
|
||||
w.cursor_visible = false
|
||||
return w
|
||||
else
|
||||
HAS_SETUP_WINDOW = true
|
||||
is_window_setup = true
|
||||
print("Window setup")
|
||||
end
|
||||
end, Window)
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
---@class Window
|
||||
Window = {
|
||||
---Gets or sets the window's focus.
|
||||
---@type boolean
|
||||
focused = nil,
|
||||
---Gets or sets the window mode.
|
||||
---@type WindowMode
|
||||
window_mode = nil,
|
||||
---Gets or sets the position of the top-left corner of the window.
|
||||
---
|
||||
---The top-left hand corner of the desktop is not necessarily the same
|
||||
---as the screen. If the user uses a desktop with multiple monitors, the top-left
|
||||
---hand corner of the desktop is the top-left hand corner of the monitor at the
|
||||
---top-left of the desktop.
|
||||
---
|
||||
---If this is `nil`, the position will be chosen by the windowing manager at creation,
|
||||
---then set when the window is created.
|
||||
---
|
||||
---@type Vec2?
|
||||
position = nil,
|
||||
---@type Vec2
|
||||
physical_size = nil,
|
||||
---@type Vec2
|
||||
size = nil,
|
||||
---Gets/sets if the window has decorations.
|
||||
---@type boolean
|
||||
decorated = nil,
|
||||
---Gets/sets the window's current maximized state.
|
||||
---@type boolean
|
||||
maximized = nil,
|
||||
---Gets/sets the window's current minimized state.
|
||||
---
|
||||
---Is `nil` if the minimized state could not be determined.
|
||||
---
|
||||
---@type boolean?
|
||||
minimized = nil,
|
||||
---Gets/sets the window's current resizable state
|
||||
---@type boolean
|
||||
resizable = nil,
|
||||
---Gets/sets the window's current visibility state.
|
||||
---
|
||||
---Is `nil` when it could not be determined.
|
||||
---
|
||||
---@type boolean?
|
||||
visible = nil,
|
||||
|
||||
--TODO: resize_increments
|
||||
|
||||
---Gets the scale factor.
|
||||
---
|
||||
---You cannot set this field.
|
||||
---
|
||||
---@type number
|
||||
scale_factor = nil,
|
||||
---Gets/sets the window's blur state.
|
||||
---@type boolean
|
||||
blur = nil,
|
||||
|
||||
--TODO: cursor appearance
|
||||
|
||||
---Gets/sets the window's cursor grab mode.
|
||||
---@type CursorGrabMode
|
||||
cursor_grab = nil,
|
||||
---Gets/sets whether the window catches cursor events.
|
||||
---@type boolean
|
||||
cursor_hittest = nil,
|
||||
---Gets/sets the cursor's visibility.
|
||||
---@type boolean
|
||||
cursor_visible = nil,
|
||||
---Sets whether the window should get IME events.
|
||||
---
|
||||
---When IME is allowed, the window will receive Ime events, and during the preedit phase
|
||||
---the window will NOT get KeyboardInput events. The window should allow IME while
|
||||
---it is expecting text input.
|
||||
---
|
||||
---When IME is not allowed, the window won’t receive window ime events, and will receive
|
||||
---KeyboardInput events for every keypress instead. Not allowing IME is useful for games
|
||||
---for example. IME is not allowed by default.
|
||||
---
|
||||
---@type boolean
|
||||
ime_allowed = nil,
|
||||
---Gets/sets the minimum size of the window.
|
||||
---@type Vec2?
|
||||
min_size = nil,
|
||||
---Gets/sets the maximum size of the window.
|
||||
---@type Vec2?
|
||||
max_size = nil,
|
||||
---Gets/sets the current window theme.
|
||||
---
|
||||
---Specify `nil` to reset the theme to the system default. May also be `nil` on
|
||||
---unsupported platforms.
|
||||
---
|
||||
---@type WindowTheme?
|
||||
theme = nil,
|
||||
---Gets/sets the title of the window.
|
||||
---@type string
|
||||
title = nil,
|
||||
---Gets/sets the window's transparency state.
|
||||
---@type boolean
|
||||
transparent = nil,
|
||||
|
||||
--TODO: window_icon
|
||||
|
||||
---Change the window level.
|
||||
---@type WindowLevel
|
||||
window_level = nil,
|
||||
---Gets the window's occluded state (completely hidden from view).
|
||||
---@type boolean
|
||||
occluded = nil,
|
||||
---Gets/sets the cursor position in the window in logical coordinates.
|
||||
---
|
||||
---The value is `nil` when the cursor is not in the window.
|
||||
---
|
||||
---@type Vec2?
|
||||
cursor_position = nil,
|
||||
---Gets/sets the cursor position in the window in physical coordinates.
|
||||
---
|
||||
---The value is `nil` when the cursor is not in the window.
|
||||
---
|
||||
---@type Vec2?
|
||||
physical_cursor_position = nil,
|
||||
---Checks if the mouse is inside the window
|
||||
---@param self Window
|
||||
---@return boolean
|
||||
is_mouse_inside = function (self) return false end,
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
require "math.vec2"
|
||||
|
||||
require "ecs.window"
|
|
@ -0,0 +1,14 @@
|
|||
---@class Vec2
|
||||
Vec2 = {
|
||||
---The x coordinate
|
||||
---@type number
|
||||
x = nil,
|
||||
---The y coordinate
|
||||
---@type number
|
||||
y = nil,
|
||||
|
||||
---Create a new `Vec2`
|
||||
---@param x number
|
||||
---@param y number
|
||||
new = function (x, y) end
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
---@enum WindowMode
|
||||
WindowMode = {
|
||||
WNDOWED = "windowed",
|
||||
BORDERLESS_FULLSCREEN = "borderless_fullscreen",
|
||||
|
@ -5,17 +6,20 @@ WindowMode = {
|
|||
FULLSCREEN = "fullscreen",
|
||||
}
|
||||
|
||||
---@enum CursorGrabMode
|
||||
CursorGrabMode = {
|
||||
NONE = "none",
|
||||
CONFINED = "confined",
|
||||
LOCKED = "locked",
|
||||
}
|
||||
|
||||
---@enum WindowTheme
|
||||
WindowTheme = {
|
||||
LIGHT = "light",
|
||||
DARK = "dark",
|
||||
}
|
||||
|
||||
---@enum WindowLevel
|
||||
WindowLevel = {
|
||||
ALWAYS_ON_BOTTOM = "always_on_bottom",
|
||||
NORMAL = "normal",
|
||||
|
|
|
@ -135,10 +135,6 @@ wrap_lua_struct!(
|
|||
fields.add_field_method_get("scale_factor", |lua, this| {
|
||||
this.scale_factor.into_lua(lua)
|
||||
});
|
||||
fields.add_field_method_set("scale_factor", |_, this, val: f64| {
|
||||
this.scale_factor = val;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
fields.add_field_method_get("blur", |lua, this| {
|
||||
this.blur.into_lua(lua)
|
||||
|
|
Loading…
Reference in New Issue