diff --git a/src/elements/Frame.lua b/src/elements/Frame.lua index cd2b827..15a91de 100644 --- a/src/elements/Frame.lua +++ b/src/elements/Frame.lua @@ -15,6 +15,7 @@ Frame.defineProperty(Frame, "draggable", {default = false, type = "boolean", set self:listenEvent("mouse_up", true) self:listenEvent("mouse_drag", true) end + return value end}) ---@property draggingMap table {} The map of dragging positions 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 --- @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") + if VisualElement.mouse_click(self, button, x, y) then + if self.get("draggable") then + local relX, relY = self:getRelativePosition(x, y) + local draggingMap = self.get("draggingMap") - for _, map in ipairs(draggingMap) do - local width = map.width or 1 - local height = map.height or 1 + for _, map in ipairs(draggingMap) do + local width = map.width or 1 + 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 + 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 + 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 end return Container.mouse_click(self, button, x, y) end + return false end --- @shortDescription Handles mouse release events diff --git a/src/elements/Image.lua b/src/elements/Image.lua index ff883e9..ed646bc 100644 --- a/src/elements/Image.lua +++ b/src/elements/Image.lua @@ -353,4 +353,4 @@ function Image:render() end end -return Image +return Image \ No newline at end of file diff --git a/src/elements/Input.lua b/src/elements/Input.lua index d31fe1a..95325aa 100644 --- a/src/elements/Input.lua +++ b/src/elements/Input.lua @@ -20,8 +20,10 @@ Input.defineProperty(Input, "maxLength", {default = nil, type = "number"}) Input.defineProperty(Input, "placeholder", {default = "...", type = "string"}) ---@property placeholderColor color gray Color of the placeholder text Input.defineProperty(Input, "placeholderColor", {default = colors.gray, type = "number"}) ----@property focusedColor color blue Background color when input is focused -Input.defineProperty(Input, "focusedColor", {default = colors.blue, type = "number"}) +---@property focusedBackground color blue Background color when input is focused +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 Input.defineProperty(Input, "pattern", {default = nil, type = "string"}) ---@property cursorColor number nil Color of the cursor @@ -164,6 +166,18 @@ function Input:updateViewport() return self 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 --- @protected function Input:render() @@ -171,10 +185,11 @@ function Input:render() local viewOffset = self.get("viewOffset") local width = self.get("width") 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 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 self:textFg(1, 1, placeholder:sub(1, width), self.get("placeholderColor")) diff --git a/src/elements/VisualElement.lua b/src/elements/VisualElement.lua index d91fe66..b3be31b 100644 --- a/src/elements/VisualElement.lua +++ b/src/elements/VisualElement.lua @@ -95,7 +95,7 @@ VisualElement.defineEvent(VisualElement, "focus") VisualElement.defineEvent(VisualElement, "blur") 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, "Scroll", "mouse_scroll") VisualElement.registerEventCallback(VisualElement, "Enter", "mouse_enter", "mouse_move")