Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Class: WebUI

smokingplaya edited this page May 25, 2024 · 6 revisions

WebUI is a technology that allows you to make UI through HTML/CSS/JS in Garry's Mod.
It is an abstraction over DHTML.

It implies that the player has a Chromium branch *

Methods

new (constructor)

@argument Name/ID (string) - unique ID of WebUI's panel @argument URL (string) - URL to HTML page, that will be rendered @argument SaveOnClose? (boolean) - if true, WebUI will not removed after :Close()

Example

local webui_panel = WebUI:new("Scoreboard", "https://autumngmod.ru/webui/scoreboard")

static Prepare

@description Returns the panel if it exists, or creates it and returns it.

@argument Name/ID (string) - unique ID of WebUI's panel @argument URL (string) - URL to HTML page, that will be rendered @argument SaveOnClose? (boolean) - if true, WebUI will not removed after :Close()

Example

local webui_panel = WebUI:new("Scoreboard", "https://autumngmod.ru/webui/scoreboard")

local ui_panel = WebUI.Prepare("Scoreboard", "https://autumngmod.ru/webui/scoreboard")
print(webui_panel == ui_panel) -- => output: true
-- same panels

Open

@description Creates/shows WebUI panel depending on the save_on_close parameter in the new constructor method

@argument Parent? (Panel) - The parent panel on which the WebUI will be opened. This is an optional parameter.

Example

local webui_panel = WebUI:new("Scoreboard", "https://autumngmod.ru/webui/scoreboard")
webui_panel:Open()

GetPanel

@description Returns DHTML panel of WebUI

PushTable

@description Adds Lua table in DHTML's javascript, as variable.

@argument VariableName (string) - name of variable in JavaScript @argument Table (table) - table, that will be pushed in JavaScript

Example

webui_panel:PushTable("example", {
     a = 4,
     is_funeral_the_best = true
})

Close

@description Closes/hides WebUI panel depending on the save_on_close parameter in the new constructor method

Clone this wiki locally