Added sorting highlights and arrows.

Jayden Platell [04-08-14 - 22:31]
Added sorting highlights and arrows.
Filename
Librarian.lua
Librarian.xml
diff --git a/Librarian.lua b/Librarian.lua
index e575735..c6943e1 100644
--- a/Librarian.lua
+++ b/Librarian.lua
@@ -10,6 +10,9 @@ ZO_CreateStringId("SI_LIBRARIAN_SORT_TYPE_TITLE", "Title")
 ZO_CreateStringId("SI_LIBRARIAN_MARK_UNREAD", "Mark as Unread")
 ZO_CreateStringId("SI_LIBRARIAN_MARK_READ", "Mark as Read")

+local SORT_ARROW_UP = "EsoUI/Art/Miscellaneous/list_sortUp.dds"
+local SORT_ARROW_DOWN = "EsoUI/Art/Miscellaneous/list_sortDown.dds"
+
 local previousBook
 local scrollChild
 local sortField = "Found"
@@ -19,7 +22,7 @@ function Librarian:Initialise()
  	scrollChild = LibrarianFrameScrollContainer:GetNamedChild("ScrollChild")
 	self.savedVars = ZO_SavedVars:New("Librarian_SavedVariables", 1, nil, self.defaults, nil)

-	self:LayoutBooks()
+	self:SortBooks()

 	self:InitializeKeybindStripDescriptors()
 	self:InitializeScene()
@@ -154,19 +157,28 @@ function Librarian:SortBy(control)
 		sortAscending = true
 	end

+	self:SortBooks()
+end
+
+function Librarian:SortBooks()
+	local control
+
 	if sortField == "Unread" then
+		control = LibrarianFrameSortByUnread
 		if sortAscending then
 			table.sort(self.savedVars.books, function(a, b) return a.unread and not b.unread end)
 		else
 			table.sort(self.savedVars.books, function(a, b) return not a.unread and b.unread end)
 		end
 	elseif sortField == "Found" then
+		control = LibrarianFrameSortByTime
 		if sortAscending then
 			table.sort(self.savedVars.books, function(a, b) return a.timeStamp < b.timeStamp end)
 		else
 			table.sort(self.savedVars.books, function(a, b) return a.timeStamp > b.timeStamp end)
 		end
 	elseif sortField == "Title" then
+		control = LibrarianFrameSortByTitle
 		if sortAscending then
 			table.sort(self.savedVars.books, function(a, b) return a.title < b.title end)
 		else
@@ -174,6 +186,18 @@ function Librarian:SortBy(control)
 		end
 	end

+	LibrarianFrameSortByUnread:GetNamedChild("Arrow"):SetHidden(true)
+	LibrarianFrameSortByTime:GetNamedChild("Arrow"):SetHidden(true)
+	LibrarianFrameSortByTitle:GetNamedChild("Arrow"):SetHidden(true)
+
+	local arrow = control:GetNamedChild("Arrow")
+	if sortAscending then
+		arrow:SetTexture(SORT_ARROW_DOWN)
+	else
+		arrow:SetTexture(SORT_ARROW_UP)
+	end
+	arrow:SetHidden(false)
+
 	self:LayoutBooks()
 end

diff --git a/Librarian.xml b/Librarian.xml
index 512ae2a..d89ecc1 100644
--- a/Librarian.xml
+++ b/Librarian.xml
@@ -21,21 +21,31 @@
                     <Anchor point="TOPLEFT" relativeTo="$(parent)" offsetX="19" />
                 </Texture>
                 <Label name="$(parent)Found" font="ZoFontWinH2" wrapMode="ELLIPSIS">
-                    <Anchor point="TOPLEFT" relativeTo="$(parent)" offsetX="80" offsetY="1" />
+                    <Anchor point="TOPLEFT" relativeTo="$(parent)" offsetX="90" offsetY="1" />
                 </Label>
                 <Label name="$(parent)Title" font="ZoFontWinH2" wrapMode="ELLIPSIS">
-                    <Anchor point="TOPLEFT" relativeTo="$(parent)" offsetX="270" offsetY="1" />
+                    <Anchor point="TOPLEFT" relativeTo="$(parent)" offsetX="290" offsetY="1" />
                 </Label>
             </Controls>
         </Button>
-        <Button name="SortHeader" resizeToFitDescendents="true" virtual="true">
+        <Button name="SortHeader" virtual="true">
             <OnMouseUp>
                 Librarian:SortBy(self)
             </OnMouseUp>
+            <OnMouseEnter>
+                self:GetNamedChild("Name"):SetColor(ZO_HIGHLIGHT_TEXT:UnpackRGBA())
+            </OnMouseEnter>
+            <OnMouseExit>
+                self:GetNamedChild("Name"):SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
+            </OnMouseExit>
             <Controls>
                 <Label name="$(parent)Name" font="ZoFontGame" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_NORMAL" modifyTextType="UPPERCASE" horizontalAlignment="CENTER" verticalAlignment="CENTER" wrapMode="ELLIPSIS">
-                    <AnchorFill />
+                    <Anchor point="TOPLEFT" />
                 </Label>
+                <Texture name="$(parent)Arrow" hidden="true" layer="TEXT">
+                    <Dimensions x="16" y="16"/>
+                    <Anchor point="TOPLEFT" relativeTo="$(parent)Name" relativePoint="TOPRIGHT" offsetY="2" />
+                </Texture>
             </Controls>
         </Button>
         <TopLevelControl name="LibrarianFrame" inherits="ZO_RightPanelFootPrint"  hidden="true">
@@ -45,7 +55,7 @@
                     <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" relativePoint="TOPRIGHT" offsetY="0" />
                     <Controls>
                         <Button name="$(parent)Unread" inherits="SortHeader">
-                            <Dimensions x="80" y="20" />
+                            <Dimensions x="90" y="20" />
                             <Anchor point="TOPLEFT" />
                             <OnInitialized>
                                 Librarian:InitialiseSortHeader(self, SI_LIBRARIAN_SORT_TYPE_UNREAD, "Unread")
@@ -53,7 +63,7 @@
                         </Button>
                         <Button name="$(parent)Time" inherits="SortHeader">
                             <Dimensions x="200" y="20" />
-                            <Anchor point="TOPLEFT" relativeTo="$(parent)Unread" relativePoint="TOPRIGHT" />
+                            <Anchor point="TOPLEFT" offsetX="90" />
                             <OnInitialized>
                                 Librarian:InitialiseSortHeader(self, SI_LIBRARIAN_SORT_TYPE_FOUND, "Found")
                             </OnInitialized>