ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Bug in SortHeaderGroup (https://www.esoui.com/forums/showthread.php?t=5289)

haggen 11/18/15 08:18 PM

Bug in SortHeaderGroup
 
I stumbled upon it when trying to set a default sorting for my add-on.

The bug is: 'OnHeaderClicked' is ignoring the initial direction given by ZO_SortHeader_Initialize.

Let's take a look:

File esoui\libraries\zo_sortheadergroup\zo_sortheadergroup.lua, from line 149 to 165
Lua Code:
  1. function ZO_SortHeaderGroup:OnHeaderClicked(header, suppressCallbacks, forceReselect)
  2.     if self:IsEnabled() then
  3.         local resetSortDir = false
  4.         if forceReselect or not self:IsCurrentSelectedHeader(header) then
  5.             self:DeselectHeader()
  6.             resetSortDir = true
  7.         end
  8.  
  9.         self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
  10.  
  11.         self:SelectHeader(header)
  12.    
  13.         if(not suppressCallbacks) then
  14.             self:FireCallbacks(self.HEADER_CLICKED, header.key, self.sortDirection)
  15.         end
  16.     end
  17. end

Upon first calling 'OnHeaderClicked' (whether by clicking on the header or calling 'SelectHeaderByKey'), the line that sets 'sortDirection' always gets true, no matter what. I think the problem is the use of 'x and y or z', since sortDirection is a boolean flag, it's tricky to use this ternary-ish conditional instead of a full body if/else.

Edit.

Yes! As I suspected, changing the line

Lua Code:
  1. self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection

to

Lua Code:
  1. if resetSortDir then
  2.   self.sortDirection = header.initialDirection
  3. else
  4.   self.sortDirection = not self.sortDirection
  5. end

Fixed the problem!

I always found 'x and y or z' smelly, a mine waiting to be detonated. :P

merlight 11/18/15 08:56 PM

You're totally right, that line doesn't do what it should. Btw http://www.esoui.com/forums/showpost...64&postcount=8 ^^

haggen 11/18/15 09:08 PM

Quote:

Originally Posted by merlight (Post 24318)
You're totally right, that line doesn't do what it should. Btw http://www.esoui.com/forums/showpost...64&postcount=8 ^^

Oh damn! I tried searching for "Header sort" and missed that =/ Well, it should have been fixed by now.

Another thing that bothers me is: if you check the sort function for comparing rows in a scroll list, it accepts a flag in the sort keys options called "isNumeric" to know when to compare numeric values. But, in esoui\ingame\mail\mailinbox_shared.lua it reads "numeric" (without the prefix 'is'). I think it's misspelled but since I never took the time to look for other instances I never reported. Well, I am now. :P

Edit.

I was reading the link you mentioned. I notice now that there are bugs everywhere around SORT_ORDER_UP and SORT_ORDER_DOWN, and I think it's because they're booleans. Wouldn't it be better if they used 0 and 1?

merlight 11/18/15 09:55 PM

Quote:

Originally Posted by haggen (Post 24319)
Another thing that bothers me is: if you check the sort function for comparing rows in a scroll list, it accepts a flag in the sort keys options called "isNumeric" to know when to compare numeric values. But, in esoui\ingame\mail\mailinbox_shared.lua it reads "numeric" (without the prefix 'is'). I think it's misspelled but since I never took the time to look for other instances I never reported. Well, I am now. :P

It's probably misspelled, but in this case it also doesn't matter. ZO_TableOrderingFunction checks "isNumeric" and converts the argument tonumber; but since those two "numeric" arguments in mailbox already are numbers, "isNumeric" isn't needed there.

Quote:

Originally Posted by haggen (Post 24319)
I was reading the link you mentioned. I notice now that there are bugs everywhere around SORT_ORDER_UP and SORT_ORDER_DOWN, and I think it's because they're booleans. Wouldn't it be better if they used 0 and 1?

Maybe, but then inversion (order = not order) would have to be rewritten (order = 1 - order), not only in ZO code, but also in add-ons. Better just fix the bad uses ;)


All times are GMT -6. The time now is 08:21 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI