From 05864f8e1679882ebf3380c7f24d7dbe46c93fcc Mon Sep 17 00:00:00 2001 From: Pawel Date: Thu, 26 Sep 2019 02:12:30 +0200 Subject: [PATCH] v1.6.2 --- widgets/EditBox.lua | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/widgets/EditBox.lua b/widgets/EditBox.lua index 8dc15ce..db802ed 100644 --- a/widgets/EditBox.lua +++ b/widgets/EditBox.lua @@ -4,7 +4,7 @@ if not StdUi then return; end -local module, version = 'EditBox', 4; +local module, version = 'EditBox', 5; if not StdUi:UpgradeNeeded(module, version) then return end; --- @return EditBox @@ -38,24 +38,26 @@ function StdUi:SimpleEditBox(parent, width, height, text) return editBox; end -function StdUi:SearchEditBox(parent, width, height, placeholderText) - local editBox = self:SimpleEditBox(parent, width, height, ''); +function StdUi:ApplyPlaceholder(widget, placeholderText, icon, iconColor) + widget.placeholder = {}; - local icon = self:Texture(editBox, 14, 14, [[Interface\Common\UI-Searchbox-Icon]]); - local c = self.config.font.color.disabled; - icon:SetVertexColor(c.r, c.g, c.b, c.a); - local label = self:Label(editBox, placeholderText); + local label = self:Label(widget, placeholderText); self:SetTextColor(label, 'disabled'); + widget.placeholder.label = label; + + if icon then + local texture = self:Texture(widget, 14, 14, icon); + local c = iconColor or self.config.font.color.disabled; + texture:SetVertexColor(c.r, c.g, c.b, c.a); + + self:GlueLeft(texture, widget, 5, 0, true); + self:GlueRight(label, texture, 2, 0); + widget.placeholder.icon = texture; + else + self:GlueLeft(label, widget, 2, 0, true); + end - self:GlueLeft(icon, editBox, 5, 0, true); - self:GlueRight(label, icon, 2, 0); - - editBox.placeholder = { - icon = icon, - label = label - }; - - editBox:SetScript('OnTextChanged', function(self) + widget:HookScript('OnTextChanged', function(self) if strlen(self:GetText()) > 0 then self.placeholder.icon:Hide(); self.placeholder.label:Hide(); @@ -63,7 +65,15 @@ function StdUi:SearchEditBox(parent, width, height, placeholderText) self.placeholder.icon:Show(); self.placeholder.label:Show(); end + end); +end + +function StdUi:SearchEditBox(parent, width, height, placeholderText) + local editBox = self:SimpleEditBox(parent, width, height, ''); + + self:ApplyPlaceholder(editBox, placeholderText, [[Interface\Common\UI-Searchbox-Icon]]); + editBox:SetScript('OnTextChanged', function(self) if self.OnValueChanged then self:OnValueChanged(self:GetText()); end