From 1c2240ee15b05f33556308a3859fdf3f218c9c56 Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Thu, 22 Oct 2009 14:58:20 -0500 Subject: [PATCH] Added filtering to ww_statFrame's editboxes (now allows only numbers) --- WeightsWatcher.xml | 15 +++++++++++++++ config.lua | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml index 27752f5..376a15c 100644 --- a/WeightsWatcher.xml +++ b/WeightsWatcher.xml @@ -90,6 +90,21 @@ self:SetTextInsets(5, 5, 0, 0) + + local text = self:GetText() + if self:GetNumber() ~= 0 or text:match("^[0.]+$") or text == "" then + self.number = text + end + + + if validateNumber(text, self:GetText()) then + self.number = self:GetText() + else + local cursorPosition = self:GetCursorPosition() - 1 + self:SetText(self.number) + self:SetCursorPosition(cursorPosition) + end + diff --git a/config.lua b/config.lua index 4b87262..bbc4cd9 100644 --- a/config.lua +++ b/config.lua @@ -27,6 +27,23 @@ function open_config() end end +function validateNumber(newChar, newText) + if string.find(newChar, "^[0-9]$") then + return true + elseif newChar == '.' then + local first = newText:find(".", 1, true) + local second = newText:find(".", first + 1, true) + if not second then + return true + end + elseif newChar == '-' then + if not string.find(newText, "-", 2) then + return true + end + end + return false +end + function scrollBarUpdate(scrollFrame, scrolledFrame, buttonTable, buttonHeight, initialOffset, numShown) local i local offset = FauxScrollFrame_GetOffset(scrollFrame) -- 1.7.9.5