Skip to content

Commit

Permalink
v1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaminariss committed Sep 26, 2019
1 parent bf35e37 commit 05864f8
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions widgets/EditBox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,32 +38,42 @@ 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();
else
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
Expand Down

0 comments on commit 05864f8

Please sign in to comment.