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:
@@ -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,36 +51,39 @@ 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
|
||||||
local relX, relY = self:getRelativePosition(x, y)
|
if self.get("draggable") then
|
||||||
local draggingMap = self.get("draggingMap")
|
local relX, relY = self:getRelativePosition(x, y)
|
||||||
|
local draggingMap = self.get("draggingMap")
|
||||||
|
|
||||||
for _, map in ipairs(draggingMap) do
|
for _, map in ipairs(draggingMap) do
|
||||||
local width = map.width or 1
|
local width = map.width or 1
|
||||||
local height = map.height or 1
|
local height = map.height or 1
|
||||||
|
|
||||||
if type(width) == "string" and width == "width" then
|
if type(width) == "string" and width == "width" then
|
||||||
width = self.get("width")
|
width = self.get("width")
|
||||||
elseif type(width) == "function" then
|
elseif type(width) == "function" then
|
||||||
width = width(self)
|
width = width(self)
|
||||||
end
|
end
|
||||||
if type(height) == "string" and height == "height" then
|
if type(height) == "string" and height == "height" then
|
||||||
height = self.get("height")
|
height = self.get("height")
|
||||||
elseif type(height) == "function" then
|
elseif type(height) == "function" then
|
||||||
height = height(self)
|
height = height(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
local mapY = map.y or 1
|
local mapY = map.y or 1
|
||||||
if relX >= map.x and relX <= map.x + width - 1 and
|
if relX >= map.x and relX <= map.x + width - 1 and
|
||||||
relY >= mapY and relY <= mapY + height - 1 then
|
relY >= mapY and relY <= mapY + height - 1 then
|
||||||
self.dragStartX = x - self.get("x")
|
self.dragStartX = x - self.get("x")
|
||||||
self.dragStartY = y - self.get("y")
|
self.dragStartY = y - self.get("y")
|
||||||
self.dragging = true
|
self.dragging = true
|
||||||
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
|
||||||
|
|||||||
@@ -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"))
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user