diff --git a/core.lua b/core.lua index dd28cfe..9d399aa 100644 --- a/core.lua +++ b/core.lua @@ -111,7 +111,7 @@ function public.VARIABLES_LOADED() btn:SetWidth(65) btn:SetHeight(24) btn:SetText('Close') - btn:SetScript('OnClick', m._(m.frame.hide, m.frame)) + btn:SetScript('OnClick', m._(m.frame.Hide, m.frame)) public.close_button = btn end diff --git a/tabs/search/core.lua b/tabs/search/core.lua index c61cbaf..0daaad5 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -521,7 +521,7 @@ end function private.blizzard_level(str) if tonumber(str) then - return aux.util.round(max(1, min(60, tonumber(str)))) + return aux.util.round(aux.util.bound(1, 60, tonumber(str))) end end @@ -911,21 +911,39 @@ do function private.update_filter_display() text = aux.filter.indented_post_query_string(m.post_components) - m.filter_display:SetWidth(m.filter_display_width()) + m.filter_display:SetWidth(m.filter_display_size()) + m.set_filter_display_offset() m.filter_display:SetText(text) end - function private.filter_display_width() - local widest_line = 0 + function private.filter_display_size() + local font, font_size = m.filter_display:GetFont() + m.filter_display.measure:SetFont(font, font_size) + local lines = 0 + local width = 0 + for line in string.gfind(text, '

(.-)

') do - m.filter_display.measure:SetFont(m.filter_display:GetFont()) + lines = lines + 1 m.filter_display.measure:SetText(line) - widest_line = max(widest_line, m.filter_display.measure:GetStringWidth()) + width = max(width, m.filter_display.measure:GetStringWidth()) end - return widest_line + + return width, lines*font_size end end +function private.set_filter_display_offset(x_offset, y_offset) + local scroll_frame = m.filter_display:GetParent() + x_offset, y_offset = x_offset or scroll_frame:GetHorizontalScroll(), y_offset or scroll_frame:GetVerticalScroll() + local width, height = m.filter_display_size() + local x_lower_bound = min(0, scroll_frame:GetWidth() - width - 2) + local x_upper_bound = 0 + local y_lower_bound = 0 + local y_upper_bound = max(0, height - scroll_frame:GetHeight() + 2) + scroll_frame:SetHorizontalScroll(aux.util.bound(x_lower_bound, x_upper_bound, x_offset)) + scroll_frame:SetVerticalScroll(aux.util.bound(y_lower_bound, y_upper_bound, y_offset)) +end + function private.new_recent_search(filter_string, prettified) tinsert(aux_recent_searches, 1, { filter_string = filter_string, diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index 0d528b1..b536b28 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -535,7 +535,7 @@ function private.create_frames() scroll_frame:EnableMouseWheel(true) scroll_frame:SetScript('OnMouseWheel', function() local child = this:GetScrollChild() - child:SetFont('p', [[Fonts\ARIALN.TTF]], max(10, min(26, aux.util.select(2, child:GetFont()) + arg1*2))) + child:SetFont('p', [[Fonts\ARIALN.TTF]], aux.util.bound(10, 26, aux.util.select(2, child:GetFont()) + arg1*2)) m.update_filter_display() end) scroll_frame:RegisterForDrag('LeftButton') @@ -548,8 +548,8 @@ function private.create_frames() local new_x_offset = this.x_offset + x - this.x local new_y_offset = this.y_offset + y - this.y - this:SetHorizontalScroll(min(0, max((this:GetWidth() - m.filter_display_width())*m.filter_display:GetScale() - 2, new_x_offset - this.x_extra))) - this:SetVerticalScroll(max(0, new_y_offset - this.y_extra)) + m.set_filter_display_offset(new_x_offset - this.x_extra, new_y_offset - this.y_extra) + this.x_extra = max(this.x_extra, new_x_offset) this.y_extra = min(this.y_extra, new_y_offset) end) diff --git a/util/core.lua b/util/core.lua index 38a65df..a43a010 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,5 +1,9 @@ local m, public, private = aux.module'util' +function public.bound(lower_bound, upper_bound, number) + return max(lower_bound, min(upper_bound, number)) +end + function public.size(t) local x = 0 for _ in t do @@ -33,7 +37,10 @@ function public.values(t) end function public.select(i, ...) - return arg[i] + for _=1,i-1 do + tremove(arg, 1) + end + return unpack(arg) end function public.eq(t1, t2)