This commit is contained in:
NoryiE
2025-02-17 08:37:58 +00:00
parent 056897dd1b
commit ca2521d237
6 changed files with 98 additions and 45 deletions

View File

@@ -19,7 +19,7 @@ The base class for all UI elements in Basalt
|[BaseElement:destroy](#BaseElement:destroy)|-|
|[BaseElement:dispatchEvent](#BaseElement:dispatchEvent)|boolean?|
|[BaseElement:fireEvent](#BaseElement:fireEvent)|table|
|[BaseElement:getBaseFrame](#BaseElement:getBaseFrame)|-|
|[BaseElement:getBaseFrame](#BaseElement:getBaseFrame)|table|
|[BaseElement:handleEvent](#BaseElement:handleEvent)|boolean?|
|[BaseElement:init](#BaseElement:init)|table|
|[BaseElement:isType](#BaseElement:isType)|boolean|
@@ -56,6 +56,12 @@ local element = BaseElement.new("myId", basalt)
```
## BaseElement:destroy()
Destroys the element and cleans up all references
### Usage
```lua
element:destroy()
```
## BaseElement:dispatchEvent(event)
Handles all events
@@ -83,6 +89,10 @@ element:fireEvent("mouse_click", 1, 2)
```
## BaseElement:getBaseFrame()
Returns the base frame of the element
### Returns
* `table` `BaseFrame` The base frame of the element
## BaseElement:handleEvent(event)
The default event handler for all events
@@ -129,7 +139,7 @@ element:listenEvent("mouse_click", true)
```
## BaseElement:postInit()
Post initialization hook
Post initialization
### Returns
* `table` `self` The BaseElement instance

View File

@@ -6,6 +6,11 @@
|---|---|---|---|
|text|string|Button|Button text
## Events
|Event|Parameters|Description|
|---|---|---|
## Functions
|Method|Returns|Description|
@@ -14,7 +19,6 @@
|[Button:init](#Button:init)|-|
|[Button:render](#Button:render)|-|
@event mouse_click The event that is triggered when the button is clicked
## Button.new()
Creates a new Button instance

View File

@@ -22,6 +22,7 @@
|[Container:blit](#Container:blit)|Container|
|[Container:char](#Container:char)|boolean|
|[Container:clear](#Container:clear)|Container|
|[Container:destroy](#Container:destroy)|-|
|[Container:getChild](#Container:getChild)|Container?|
|[Container:handleEvent](#Container:handleEvent)|boolean|
|[Container:init](#Container:init)|-|
@@ -84,6 +85,8 @@ Clears the container
### Returns
* `Container` `self` The container instance
## Container:destroy()
## Container:getChild(path)
Removes a child from the container

View File

@@ -1,4 +1,3 @@
@alias color number
# VisualElement : BaseElement
## Properties
@@ -17,6 +16,28 @@
|focused|boolean|false|whether the element is focused
|visible|boolean|true|whether the element is visible
## Combined Properties
|Name|Properties|Description|
|---|---|---|
|position|{x|y}|Position of the element
|size|{width|height}|Size of the element
|color|{foreground|background}|Color of the element
## Events
|Event|Parameters|Description|
|---|---|---|
|onMouseClick|`button number, x number, y number`|Fired when the element is clicked|
|onMouseUp|`button number, x number, y number`|Fired when the mouse is released|
|onMouseRelease|`button number, x number, y number`|Fired when the mouse is released|
|onMouseDrag|`button number, x number, y number`|Fired when the mouse is dragged|
|onFocus|`-`|Fired when the element is focused|
|onBlur|`-`|Fired when the element is blurred|
|onKey|`key number, code number, isRepeat boolean`|Fired when a key is pressed|
|onKeyUp|`key number, code number`|Fired when a key is released|
|onChar|`char string`|Fired when a key is pressed|
## Functions
|Method|Returns|Description|
@@ -32,15 +53,11 @@
|[VisualElement:mouse_click](#VisualElement:mouse_click)|boolean|
|[VisualElement:mouse_release](#VisualElement:mouse_release)|boolean|
|[VisualElement:mouse_up](#VisualElement:mouse_up)|boolean|
|[VisualElement:multiBlit](#VisualElement:multiBlit)|-|
|[VisualElement:render](#VisualElement:render)|-|
|[VisualElement:setCursor](#VisualElement:setCursor)|-|
|[VisualElement:textBg](#VisualElement:textBg)|-|
|[VisualElement:textFg](#VisualElement:textFg)|-|
@combinedProperty position x y
@combinedProperty size width height
@combinedProperty color foreground background
## VisualElement.new(props, basalt)
Creates a new VisualElement instance
@@ -135,26 +152,9 @@ Handles a mouse up event
### Returns
* `boolean` `release` Whether the element was released on the element
## VisualElement:multiBlit(x, y, width, height, text, fg, bg)
Draws a text character/fg/bg at the specified position with a certain size, used in the rendering system
### Parameters
* `x` `number` The x position to draw
* `y` `number` The y position to draw
* `width` `number` The width of the element
* `height` `number` The height of the element
* `text` `string` The text char to draw
* `fg` `color` The foreground color
* `bg` `color` The background color
## VisualElement:render()
Renders the element
### Usage
```lua
element:render()
```
## VisualElement:setCursor(x, y, blink)
Sets the cursor position