update doc/en/scripting/builtins/libgui.md

This commit is contained in:
MihailRis 2026-03-18 23:17:33 +03:00
parent 4e5c696fe5
commit 5eec1e470c
2 changed files with 56 additions and 28 deletions

View file

@ -9,25 +9,19 @@ print(document.some_button.text) -- where 'some_button' is an element id
document.some_button.text = "new text" document.some_button.text = "new text"
``` ```
```python ```lua
-- Returns translated text.
gui.str(text: str, context: str) -> str gui.str(text: str, context: str) -> str
```
Returns translated text. -- Returns size of the main container (window).
```python
gui.get_viewport() -> {int, int} gui.get_viewport() -> {int, int}
```
Returns size of the main container (window). -- Returns environment (global variables table) of the specified document.
```python
gui.get_env(document: str) -> table gui.get_env(document: str) -> table
``` ```
Returns environment (global variables table) of the specified document.
```lua ```lua
-- Returns information about all loaded locales (res/texts/*).
gui.get_locales_info() -> table of tables { gui.get_locales_info() -> table of tables {
name: str name: str
} }
@ -38,8 +32,6 @@ gui.get_locales_info() -> table of tables {
-- } -- }
``` ```
Returns information about all loaded locales (res/texts/\*).
## Frames ## Frames
```lua ```lua
@ -71,18 +63,18 @@ gui.set_active_frame(
) )
``` ```
## Markup
```lua ```lua
-- Removes markup from text.
gui.clear_markup( gui.clear_markup(
-- markup language ("md" - Markdown) -- markup language ("md" - Markdown)
language: str, language: str,
-- text with markup -- text with markup
text: str text: str
) -> str ) -> str
```
Removes markup from text. -- Escapes markup in text.
```lua
gui.escape_markup( gui.escape_markup(
-- markup language ("md" - Markdown) -- markup language ("md" - Markdown)
language: str, language: str,
@ -91,20 +83,44 @@ gui.escape_markup(
) -> str ) -> str
``` ```
Escapes markup in text.
## Dialog windows
```lua ```lua
-- Displays a message box. Doesn't stop code execution.
gui.show_message(
message: string -- message (not automatically translated, use gui.str(...))
on_ok: function() -> nil -- called when closing
)
-- Asks for confirmation of the action. Doesn't stop code execution.
gui.ask(
-- message (not automatically translated, use gui.str(...))
message: string,
-- function called on confirmation
on_confirm: function() -> nil,
-- function called on rejection/cancellation
[optional] on_deny: function() -> nil,
-- confirm button text (default: "Yes")
-- use an empty string for the default value if you want to specify no_text.
[optional] yes_text: string
-- reject button text (default: "No")
[optional] no_text: string
)
```
## Dialog menu pages (legacy)
```lua
-- Displays a message box. Non-blocking.
gui.alert( gui.alert(
-- message (not automatically translated, use gui.str(...)) -- message (not automatically translated, use gui.str(...))
message: str, message: str,
-- function called on close -- function called on close
on_ok: function() -> nil on_ok: function() -> nil
) )
```
Displays a message box. **Non-blocking**. -- Requests confirmation from the user for an action. Non-blocking.
```lua
gui.confirm( gui.confirm(
-- message (does not translate automatically, use gui.str(...)) -- message (does not translate automatically, use gui.str(...))
message: str, message: str,
@ -120,9 +136,10 @@ gui.confirm(
) )
``` ```
Requests confirmation from the user for an action. **Non-blocking**. ## Documents and templates
```lua ```lua
-- Loads a UI document with its script, returns the name of the document if successfully loaded.
gui.load_document( gui.load_document(
-- Path to the xml file of the page. Example: `core:layouts/pages/main.xml` -- Path to the xml file of the page. Example: `core:layouts/pages/main.xml`
path: str, path: str,
@ -130,13 +147,24 @@ gui.load_document(
name: str name: str
-- Table of parameters passed to the on_open event -- Table of parameters passed to the on_open event
args: table args: table
) --> str ) -> str
-- Loads a template into the layout
gui.template(
-- template name in /layouts/templates without path and extension
name: str,
-- variable table (can be used in markup)
-- * Ex: <label>%{text}</label>
-- * text in this case is the value from params with the text key
params: table,
-- table, available in events as the global variable DATA
[optional] data: table
) -> str
``` ```
Loads a UI document with its script, returns the name of the document if successfully loaded. ## Root document
```lua ```lua
-- Root UI document
gui.root: Document gui.root: Document
``` ```
Root UI document

View file

@ -149,7 +149,7 @@ gui.load_document(
-- Загружает шаблон в лояут -- Загружает шаблон в лояут
gui.template( gui.template(
-- имя шаблона в layouts/templates без пути и расширения -- имя шаблона в /layouts/templates без пути и расширения
name: string, name: string,
-- таблица переменных (может быть использована в разметке) -- таблица переменных (может быть использована в разметке)
-- * Пр: <label>%{text}</label> -- * Пр: <label>%{text}</label>