gurt.width(), gurt.height()

This commit is contained in:
Face
2025-09-09 18:19:36 +03:00
parent bb0f4f102a
commit 03f4db7a84
4 changed files with 66 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
[Website](https://gurted.com/) | [Docs](https://docs.gurted.com/) | [License](LICENSE) | [YouTube video](https://www.youtube.com)
Gurted is an ecosystem similar to the World Wide Web, it features:
- ⚡ A custom protocol (TCP-based) named `GURT://` with mendatory TLS secutity with a [spec](docs.gurted.com)
- ⚡ A custom protocol (TCP-based) named `GURT://` with mandatory TLS security with a [spec](docs.gurted.com)
- 🌐 A custom **wayfinder** (browser) written in Rust and GDScript with [Godot](https://godotengine.org/)
- 📄 A custom engine for HTML, CSS, and ***Lua*** (no JavaScript)
- 🏷️ A custom **DNS** that allows users to create domains with TLDs such as `.based`, `.aura`, `.twin`, and many more

View File

@@ -112,6 +112,25 @@ end
-- Get all values for a parameter (for repeated params)
local tags = gurt.location.query.getAll('tag')
```
### gurt.width()
Gets the available width of the site page viewport in pixels.
```lua
local pageWidth = gurt.width()
trace.log('Page width: ' .. pageWidth .. ' pixels')
```
### gurt.height()
Gets the available height of the site page viewport in pixels.
```lua
local pageHeight = gurt.height()
trace.log('Page height: ' .. pageHeight .. ' pixels')
```
## Global: trace
The global trace table for logging messages to the console.

View File

@@ -359,6 +359,12 @@ func _setup_threaded_gurt_api():
lua_vm.lua_setfield(-2, "on")
lua_vm.lua_setfield(-2, "body")
lua_vm.lua_pushcallable(_gurt_get_width_handler, "gurt.width")
lua_vm.lua_setfield(-2, "width")
lua_vm.lua_pushcallable(_gurt_get_height_handler, "gurt.height")
lua_vm.lua_setfield(-2, "height")
lua_vm.lua_setglobal("gurt")
func _setup_additional_lua_apis():
@@ -499,9 +505,46 @@ func _set_interval_handler(vm: LuauVM) -> int:
func get_current_href() -> String:
var main_node = Engine.get_main_loop().current_scene
return main_node.current_domain
func _gurt_get_width_handler(vm: LuauVM) -> int:
var result = [0.0]
call_deferred("_get_width_sync", result)
while result[0] == 0.0:
OS.delay_msec(1)
vm.lua_pushnumber(result[0])
return 1
func _gurt_get_height_handler(vm: LuauVM) -> int:
var result = [0.0]
call_deferred("_get_height_sync", result)
while result[0] == 0.0:
OS.delay_msec(1)
vm.lua_pushnumber(result[0])
return 1
func _get_width_sync(result: Array):
var main_node = Engine.get_main_loop().current_scene
if main_node:
return main_node.current_domain
return ""
var active_tab = main_node.get_active_tab()
if active_tab and active_tab.website_container:
result[0] = active_tab.website_container.size.x
else:
result[0] = 1024.0
else:
result[0] = 1024.0
func _get_height_sync(result: Array):
var main_node = Engine.get_main_loop().current_scene
if main_node:
var active_tab = main_node.get_active_tab()
if active_tab and active_tab.website_container:
result[0] = active_tab.website_container.size.y
else:
result[0] = 768.0
else:
result[0] = 768.0
func _gurt_select_handler(vm: LuauVM) -> int:
var selector: String = vm.luaL_checkstring(1)

View File

@@ -272,7 +272,7 @@
<CardContent>
<pre class="bg-muted text-foreground overflow-x-auto rounded-lg p-4 text-sm"><code class="language-lua">{`<script>
local heading = gurt.select('h1')
heading:text('Dynamic Content!')
heading.text = 'Dynamic Content!'
local new_div = gurt.create('div', {
style = 'bg-blue-500 p-4 rounded'