New Element
Added BigFont element Added Feature for Frames to be draggable like windows added element:prioritize() to make it more important in the container children-hirachy
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,4 +5,5 @@ test.xml
|
|||||||
ascii.lua
|
ascii.lua
|
||||||
tests
|
tests
|
||||||
testWorkflows
|
testWorkflows
|
||||||
basaltImage.lua
|
basaltImage.lua
|
||||||
|
.vscode
|
||||||
197
src/elements/BigFont.lua
Normal file
197
src/elements/BigFont.lua
Normal file
File diff suppressed because one or more lines are too long
@@ -1,4 +1,5 @@
|
|||||||
local elementManager = require("elementManager")
|
local elementManager = require("elementManager")
|
||||||
|
local VisualElement = elementManager.getElement("VisualElement")
|
||||||
local Container = elementManager.getElement("Container")
|
local Container = elementManager.getElement("Container")
|
||||||
---@configDescription A frame element that serves as a grouping container for other elements.
|
---@configDescription A frame element that serves as a grouping container for other elements.
|
||||||
|
|
||||||
@@ -7,6 +8,17 @@ local Container = elementManager.getElement("Container")
|
|||||||
local Frame = setmetatable({}, Container)
|
local Frame = setmetatable({}, Container)
|
||||||
Frame.__index = Frame
|
Frame.__index = Frame
|
||||||
|
|
||||||
|
---@property draggable boolean false Whether the frame is draggable
|
||||||
|
Frame.defineProperty(Frame, "draggable", {default = false, type = "boolean", setter=function(self, value)
|
||||||
|
if value then
|
||||||
|
self:listenEvent("mouse_click", true)
|
||||||
|
self:listenEvent("mouse_up", true)
|
||||||
|
self:listenEvent("mouse_drag", true)
|
||||||
|
end
|
||||||
|
end})
|
||||||
|
---@property draggingMap table {{x=1, y=1, width="width", height=1}} The map of dragging positions
|
||||||
|
Frame.defineProperty(Frame, "draggingMap", {default = {{x=1, y=1, width="width", height=1}}, type = "table"})
|
||||||
|
|
||||||
--- Creates a new Frame instance
|
--- Creates a new Frame instance
|
||||||
--- @shortDescription Creates a new Frame instance
|
--- @shortDescription Creates a new Frame instance
|
||||||
--- @return Frame self The newly created Frame instance
|
--- @return Frame self The newly created Frame instance
|
||||||
@@ -31,4 +43,77 @@ function Frame:init(props, basalt)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @shortDescription Handles mouse click events
|
||||||
|
--- @param button number The button that was clicked
|
||||||
|
--- @param x number The x position of the click
|
||||||
|
--- @param y number The y position of the click
|
||||||
|
--- @return boolean handled Whether the event was handled
|
||||||
|
--- @protected
|
||||||
|
function Frame:mouse_click(button, x, y)
|
||||||
|
if(VisualElement.mouse_click(self, button, x, y)) then
|
||||||
|
local relX, relY = self:getRelativePosition(x, y)
|
||||||
|
local draggingMap = self.get("draggingMap")
|
||||||
|
|
||||||
|
for _, map in ipairs(draggingMap) do
|
||||||
|
local width = map.width
|
||||||
|
local height = map.height or 1
|
||||||
|
|
||||||
|
if type(width) == "string" and width == "width" then
|
||||||
|
width = self.get("width")
|
||||||
|
elseif type(width) == "function" then
|
||||||
|
width = width(self)
|
||||||
|
end
|
||||||
|
if type(height) == "string" and height == "height" then
|
||||||
|
height = self.get("height")
|
||||||
|
elseif type(height) == "function" then
|
||||||
|
height = height(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
local mapY = map.y or 1
|
||||||
|
if relX >= map.x and relX <= map.x + width - 1 and
|
||||||
|
relY >= mapY and relY <= mapY + height - 1 then
|
||||||
|
self.dragStartX = x - self.get("x")
|
||||||
|
self.dragStartY = y - self.get("y")
|
||||||
|
self.dragging = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Container.mouse_click(self, button, x, y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @shortDescription Handles mouse drag events
|
||||||
|
--- @param button number The button that was clicked
|
||||||
|
--- @param x number The x position of the drag position
|
||||||
|
--- @param y number The y position of the drag position
|
||||||
|
--- @return boolean handled Whether the event was handled
|
||||||
|
--- @protected
|
||||||
|
function Frame:mouse_drag(button, x, y)
|
||||||
|
if self.get("clicked") and self.dragging then
|
||||||
|
local newX = x - self.dragStartX
|
||||||
|
local newY = y - self.dragStartY
|
||||||
|
|
||||||
|
self.set("x", newX)
|
||||||
|
self.set("y", newY)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if not self.dragging then
|
||||||
|
return Container.mouse_drag(self, button, x, y)
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @shortDescription Handles mouse release events
|
||||||
|
--- @param button number The button that was released
|
||||||
|
--- @param x number The x position of the release
|
||||||
|
--- @param y number The y position of the release
|
||||||
|
--- @return boolean handled Whether the event was handled
|
||||||
|
--- @protected
|
||||||
|
function Frame:mouse_release(button, x, y)
|
||||||
|
self.dragging = false
|
||||||
|
self.dragStartX = nil
|
||||||
|
self.dragStartY = nil
|
||||||
|
return Container.mouse_release(self, button, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
return Frame
|
return Frame
|
||||||
@@ -386,6 +386,20 @@ function VisualElement:setCursor(x, y, blink, color)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- This function is used to prioritize the element by moving it to the top of its parent's children.
|
||||||
|
--- It removes the element from its parent and adds it back, effectively changing its order.
|
||||||
|
--- @shortDescription Prioritizes the element by moving it to the top of its parent's children
|
||||||
|
--- @return VisualElement self The VisualElement instance
|
||||||
|
function VisualElement:prioritize()
|
||||||
|
if(self.parent)then
|
||||||
|
local parent = self.parent
|
||||||
|
parent:removeChild(self)
|
||||||
|
parent:addChild(self)
|
||||||
|
self:updateRender()
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- @shortDescription Renders the element
|
--- @shortDescription Renders the element
|
||||||
--- @protected
|
--- @protected
|
||||||
function VisualElement:render()
|
function VisualElement:render()
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ function Render:render()
|
|||||||
self.buffer.dirtyRects = {}
|
self.buffer.dirtyRects = {}
|
||||||
|
|
||||||
if self.blink then
|
if self.blink then
|
||||||
self.terminal.setTextColor(self.cursorColor)
|
self.terminal.setTextColor(self.cursorColor or colors.white)
|
||||||
self.terminal.setCursorPos(self.xCursor, self.yCursor)
|
self.terminal.setCursorPos(self.xCursor, self.yCursor)
|
||||||
self.terminal.setCursorBlink(true)
|
self.terminal.setCursorBlink(true)
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user