Another fix wave:

Added Input focussystem
Added Input focusedBackground and focusedForeground
VisualElement renamed from MouseUp to ClickUp (onClickUp)
Fixed Frame draggable Bug (not sending events to children on mouse y 1)
This commit is contained in:
Robert Jelic
2025-02-27 00:41:45 +01:00
parent ec5f800fc4
commit 6f0b98ab89
4 changed files with 48 additions and 29 deletions

View File

@@ -15,6 +15,7 @@ Frame.defineProperty(Frame, "draggable", {default = false, type = "boolean", set
self:listenEvent("mouse_up", true) self:listenEvent("mouse_up", true)
self:listenEvent("mouse_drag", true) self:listenEvent("mouse_drag", true)
end end
return value
end}) end})
---@property draggingMap table {} The map of dragging positions ---@property draggingMap table {} The map of dragging positions
Frame.defineProperty(Frame, "draggingMap", {default = {{x=1, y=1, width="width", height=1}}, type = "table"}) Frame.defineProperty(Frame, "draggingMap", {default = {{x=1, y=1, width="width", height=1}}, type = "table"})
@@ -50,7 +51,8 @@ end
--- @return boolean handled Whether the event was handled --- @return boolean handled Whether the event was handled
--- @protected --- @protected
function Frame:mouse_click(button, x, y) function Frame:mouse_click(button, x, y)
if(VisualElement.mouse_click(self, button, x, y)) then if VisualElement.mouse_click(self, button, x, y) then
if self.get("draggable") then
local relX, relY = self:getRelativePosition(x, y) local relX, relY = self:getRelativePosition(x, y)
local draggingMap = self.get("draggingMap") local draggingMap = self.get("draggingMap")
@@ -78,8 +80,10 @@ function Frame:mouse_click(button, x, y)
return true return true
end end
end end
end
return Container.mouse_click(self, button, x, y) return Container.mouse_click(self, button, x, y)
end end
return false
end end
--- @shortDescription Handles mouse release events --- @shortDescription Handles mouse release events

View File

@@ -20,8 +20,10 @@ Input.defineProperty(Input, "maxLength", {default = nil, type = "number"})
Input.defineProperty(Input, "placeholder", {default = "...", type = "string"}) Input.defineProperty(Input, "placeholder", {default = "...", type = "string"})
---@property placeholderColor color gray Color of the placeholder text ---@property placeholderColor color gray Color of the placeholder text
Input.defineProperty(Input, "placeholderColor", {default = colors.gray, type = "number"}) Input.defineProperty(Input, "placeholderColor", {default = colors.gray, type = "number"})
---@property focusedColor color blue Background color when input is focused ---@property focusedBackground color blue Background color when input is focused
Input.defineProperty(Input, "focusedColor", {default = colors.blue, type = "number"}) Input.defineProperty(Input, "focusedBackground", {default = colors.blue, type = "number"})
---@property focusedForeground color white Foreground color when input is focused
Input.defineProperty(Input, "focusedForeground", {default = colors.white, type = "number"})
---@property pattern string? nil Regular expression pattern for input validation ---@property pattern string? nil Regular expression pattern for input validation
Input.defineProperty(Input, "pattern", {default = nil, type = "string"}) Input.defineProperty(Input, "pattern", {default = nil, type = "string"})
---@property cursorColor number nil Color of the cursor ---@property cursorColor number nil Color of the cursor
@@ -164,6 +166,18 @@ function Input:updateViewport()
return self return self
end end
function Input:focus()
VisualElement.focus(self)
self:setCursor(self.get("cursorPos") - self.get("viewOffset"), 1, true, self.get("cursorColor") or self.get("foreground"))
self:updateRender()
end
function Input:blur()
VisualElement.blur(self)
self:setCursor(1, 1, false, self.get("cursorColor") or self.get("foreground"))
self:updateRender()
end
--- @shortDescription Renders the input element --- @shortDescription Renders the input element
--- @protected --- @protected
function Input:render() function Input:render()
@@ -171,10 +185,11 @@ function Input:render()
local viewOffset = self.get("viewOffset") local viewOffset = self.get("viewOffset")
local width = self.get("width") local width = self.get("width")
local placeholder = self.get("placeholder") local placeholder = self.get("placeholder")
local focusedColor = self.get("focusedColor") local focusedBg = self.get("focusedBackground")
local focusedFg = self.get("focusedForeground")
local focused = self.get("focused") local focused = self.get("focused")
local width, height = self.get("width"), self.get("height") local width, height = self.get("width"), self.get("height")
self:multiBlit(1, 1, width, height, " ", tHex[self.get("foreground")], tHex[focused and focusedColor or self.get("background")]) self:multiBlit(1, 1, width, height, " ", tHex[focused and focusedFg or self.get("foreground")], tHex[focused and focusedBg or self.get("background")])
if #text == 0 and #placeholder ~= 0 and self.get("focused") == false then if #text == 0 and #placeholder ~= 0 and self.get("focused") == false then
self:textFg(1, 1, placeholder:sub(1, width), self.get("placeholderColor")) self:textFg(1, 1, placeholder:sub(1, width), self.get("placeholderColor"))

View File

@@ -95,7 +95,7 @@ VisualElement.defineEvent(VisualElement, "focus")
VisualElement.defineEvent(VisualElement, "blur") VisualElement.defineEvent(VisualElement, "blur")
VisualElement.registerEventCallback(VisualElement, "Click", "mouse_click", "mouse_up") VisualElement.registerEventCallback(VisualElement, "Click", "mouse_click", "mouse_up")
VisualElement.registerEventCallback(VisualElement, "MouseUp", "mouse_up", "mouse_click") VisualElement.registerEventCallback(VisualElement, "ClickUp", "mouse_up", "mouse_click")
VisualElement.registerEventCallback(VisualElement, "Drag", "mouse_drag", "mouse_click", "mouse_up") VisualElement.registerEventCallback(VisualElement, "Drag", "mouse_drag", "mouse_click", "mouse_up")
VisualElement.registerEventCallback(VisualElement, "Scroll", "mouse_scroll") VisualElement.registerEventCallback(VisualElement, "Scroll", "mouse_scroll")
VisualElement.registerEventCallback(VisualElement, "Enter", "mouse_enter", "mouse_move") VisualElement.registerEventCallback(VisualElement, "Enter", "mouse_enter", "mouse_move")