Skip to content

Commit

Permalink
#1: The user can now edit its own list
Browse files Browse the repository at this point in the history
  • Loading branch information
AssisrMatheus committed Sep 16, 2019
1 parent 788fecb commit 7ef4cf9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 10 deletions.
63 changes: 53 additions & 10 deletions components/TodoChecklister.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ local TodoChecklisterFrame = core.TodoChecklisterFrame

local Constants = core.Constants
local ResponsiveFrame = core.ResponsiveFrame
local TableUtils = core.TableUtils;
local TableUtils = core.TableUtils

--------------------------------------
-- TodoChecklisterFrame functions
--------------------------------------
function TodoChecklisterFrame:AddItem(text)
if(text ~= "" and text ~= nil and text) then
table.insert(TodoChecklisterDB, #TodoChecklisterDB+1, { text=text, isChecked=false })
if(self.selectedItem == 0) then
table.insert(TodoChecklisterDB, #TodoChecklisterDB+1, { text=text, isChecked=false })
else
TodoChecklisterDB[self.selectedItem].text = text
self:ClearSelected()
end
self:OnUpdate()
end
end
Expand All @@ -31,17 +36,35 @@ end
function TodoChecklisterFrame:CheckItem(text)
local indexToCheck = TableUtils:IndexOf(TodoChecklisterDB, function(x) return x.text == text end)
if(indexToCheck > 0) then
local item = TodoChecklisterDB[indexToCheck];
TodoChecklisterDB[indexToCheck] = { text=item.text, isChecked=(not item.isChecked) };
local item = TodoChecklisterDB[indexToCheck]
TodoChecklisterDB[indexToCheck] = { text=item.text, isChecked=(not item.isChecked) }
self:OnUpdate()
end
end

function TodoChecklisterFrame:SelectItem(text, buttonFrame)
local indexToSelect = TableUtils:IndexOf(TodoChecklisterDB, function(x) return x.text == text end)

if(indexToSelect ~= self.selectedItem) then
self.selectedItem = indexToSelect
self.frame.TodoText:SetText(TodoChecklisterDB[self.selectedItem].text)
else
self:ClearSelected()
end

self:OnUpdate()
end

function TodoChecklisterFrame:ClearSelected()
self.selectedItem = 0
self.frame.TodoText:SetText("")
end

function TodoChecklisterFrame:Toggle()
if (self.frame:IsShown()) then
self.frame:Hide();
self.frame:Hide()
else
self.frame:Show();
self.frame:Show()
end
end

Expand Down Expand Up @@ -69,13 +92,26 @@ function TodoChecklisterFrame:OnUpdate()

-- Update button values
if (todoItem.isChecked) then
button.TodoContent.FontText:SetFontObject(GameFontDarkGraySmall);
button.TodoContent.FontText:SetFontObject(GameFontDarkGraySmall)
else
button.TodoContent.FontText:SetFontObject(GameFontNormalSmall);
button.TodoContent.FontText:SetFontObject(GameFontNormalSmall)
end
button.TodoContent:SetWidth(scrollFrame:GetWidth() - button.RemoveButton:GetWidth() - 30)
button.TodoContent.FontText:SetText(todoItem.text)

if (self.selectedItem == idx) then
local highlightColor = NORMAL_FONT_COLOR

if (todoItem.isChecked) then
highlightColor = DISABLED_FONT_COLOR
end

button.TodoContent.ButtonHighlightFrame.ButtonHighlightTexture:SetVertexColor(highlightColor.r, highlightColor.g, highlightColor.b)
button.TodoContent.ButtonHighlightFrame:Show()
else
button.TodoContent.ButtonHighlightFrame:Hide()
end

-- Update checkbox values
button.TodoCheckButton:SetChecked(todoItem.isChecked)

Expand All @@ -102,7 +138,7 @@ function TodoChecklisterFrame:OnLoad(frame)
HybridScrollFrame_CreateButtons(frame.ScrollFrame, "TodoItemTemplate")

-- Display the frame
self:Toggle();
self:Toggle()
end

function TodoChecklisterFrame:OnShow(frame)
Expand Down Expand Up @@ -131,7 +167,7 @@ function OnSaveItem(frame)

TodoChecklisterFrame:AddItem(text)
TodoChecklister.TodoText:SetText("")
TodoChecklister.TodoText:ClearFocus()
-- TodoChecklister.TodoText:ClearFocus()
end

function OnRemoveItem(frame)
Expand All @@ -146,4 +182,11 @@ function OnCheckItem(frame)
if (not text) then text = "" end

TodoChecklisterFrame:CheckItem(text)
end

function OnSelectItem(frame)
local text = frame:GetParent().TodoContent.FontText:GetText()
if (not text) then text = "" end

TodoChecklisterFrame:SelectItem(text, frame)
end
29 changes: 29 additions & 0 deletions components/TodoChecklister.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@
<FontString parentKey="FontText" inherits="GameFontNormalSmall" justifyH="LEFT"/>
</Layer>
</Layers>

<Scripts>
<OnMouseDown>
self.FontText:ClearAllPoints()
self.FontText:SetPoint("LEFT", self, "LEFT", 2, -2)
</OnMouseDown>
<OnMouseUp>
self.FontText:ClearAllPoints()
self.FontText:SetPoint("LEFT", self, "LEFT", 0, 0)
OnSelectItem(self)
</OnMouseUp>
</Scripts>

<Frames>
<Frame parentKey="ButtonHighlightFrame" name="$parentButtonHighlightFrame" hidden="true">
<Size>
<AbsDimension x="293" y="16"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativeTo="$parent" relativePoint="TOPLEFT" />
<Anchor point="BOTTOMRIGHT" relativeTo="$parent" relativePoint="BOTTOMRIGHT" />
</Anchors>
<Layers>
<Layer level="ARTWORK">
<Texture parentKey="ButtonHighlightTexture" name="$parentButtonHighlightTexture" file="Interface\QuestFrame\UI-QuestLogTitleHighlight" alphaMode="ADD"/>
</Layer>
</Layers>
</Frame>
</Frames>
</Button>

<Button parentKey="RemoveButton" name="$parentRemoveButton" inherits="CollapseButtonTemplate">
Expand Down

0 comments on commit 7ef4cf9

Please sign in to comment.