Oops, forgot to include the mailing-list.

John.


---------- Forwarded message ----------
From: John Kha <sir...@gmail.com>
Date: Sat, Dec 28, 2013 at 4:53 PM
Subject: Re: [PATCH] Fixed an issue with wibox-layout-align
To: Uli Schlachter <psyc...@znc.in>


On Sat, Dec 28, 2013 at 11:03 AM, Uli Schlachter <psyc...@znc.in> wrote:
> Hi,
>
> On 28.12.2013 11:40, John Kha wrote:
>> On further investigation flex does exactly what it should.
>
> Why? After thinking about this for 0.5 seconds, I don't see much of a 
> difference
> to align.
>
> [...]

Yeah, you were right, I was over thinking it.

>> +        total_size += self.dir == "y" and h or w
>
> Caught you cheating:
>
> $ lua5.1 -e 'a = 0 ; a += 5' ; lua5.2 -e 'a = 0 ; a += 5'
> lua5.1: (command line):1: '=' expected near '+'
> lua5.2: (command line):1: syntax error near '+'
>

Thought I fixed that, but then I forgot to commit the changes.

> (Also, I would prefer not having a new empty line in there, if the handling of
> "max" is done in one block instead of being split in two and if the first line
> of the commit message (the short summary) would have at most 50 characters. 
> Long
> descriptions go into the commit message's body (which has paragraphs wrapped 
> to
> 80 characters).)
>

I think the line break usage should be better now. I also changed some
variable names to be more informative. Hopefully my patching is
better, I haven't really used git, much, before (*gasp*)

> Cheers,
> Uli
> --
> "For saving the Earth.. and eating cheesecake!"
>
> --
> To unsubscribe, send mail to awesome-devel-unsubscr...@naquadah.org.



--
John C. Kha


-- 
John C. Kha
From d2bcf0c38e07bcf99e68d674637c580b44232998 Mon Sep 17 00:00:00 2001
From: sirkha <sir...@gmail.com>
Date: Sat, 28 Dec 2013 16:39:25 -0600
Subject: [PATCH] Improved flex and align layout fit functions.

lib/wibox/layout/
The fit functions of the align and flex functions will now give the minimum
needed: the sum of the fit function results from its sub widgits in its
direction and the largest result in the other direction. The flex layout
will still take into account max_widget_size.
---
 lib/wibox/layout/align.lua.in | 18 ++++++++++--------
 lib/wibox/layout/flex.lua.in  | 36 +++++++++++++++++-------------------
 2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/lib/wibox/layout/align.lua.in b/lib/wibox/layout/align.lua.in
index 8465560..98757f1 100644
--- a/lib/wibox/layout/align.lua.in
+++ b/lib/wibox/layout/align.lua.in
@@ -100,27 +100,29 @@ function align:set_third(widget)
 end
 
 --- Fit the align layout into the given space. The align layout will
--- take all available space in its direction and the maximum size of
--- it's all three inner widgets in the other axis.
+-- ask for the sum of the sizes of its sub-widgets in its direction
+-- and the largest sized sub widget in the other direction.
 -- @param orig_width The available width.
 -- @param orig_height The available height.
 function align:fit(orig_width, orig_height)
-    local used_max = 0
+    local used_in_dir = 0
+    local used_in_other = 0
 
     for k, v in pairs{self.first, self.second, self.third} do
         local w, h = base.fit_widget(v, orig_width, orig_height)
 
         local max = self.dir == "y" and w or h
-
-        if max > used_max then
-            used_max = max
+        if max > used_in_other then
+            used_in_other = max
         end
+        
+        used_in_dir = used_in_dir + (self.dir == "y" and h or w)
     end
 
     if self.dir == "y" then
-        return used_max, orig_height
+        return used_in_other, used_in_dir
     end
-    return orig_width, used_max
+    return used_in_dir, used_in_other
 end
 
 function align:reset()
diff --git a/lib/wibox/layout/flex.lua.in b/lib/wibox/layout/flex.lua.in
index 3b8e4c8..ebcd2dd 100644
--- a/lib/wibox/layout/flex.lua.in
+++ b/lib/wibox/layout/flex.lua.in
@@ -77,35 +77,33 @@ end
 -- @param orig_width The available width.
 -- @param orig_height The available height.
 function flex:fit(orig_width, orig_height)
-    local used_max = 0
-    local used_in_dir = self.dir == "y" and orig_height or orig_width
-
-    if self._max_widget_size then
-        used_in_dir = math.min(used_in_dir,
-            #self.widgets * self._max_widget_size)
-    end
+    local used_in_dir = 0
+    local used_in_other = 0
 
     -- Figure out the maximum size we can give out to sub-widgets
-    local sub_height = self.dir == "x" and orig_height or floor(used_in_dir / #self.widgets)
-    local sub_width  = self.dir == "y" and orig_width  or floor(used_in_dir / #self.widgets)
+    local sub_height = self.dir == "x" and orig_height or floor(orig_height / #self.widgets)
+    local sub_width  = self.dir == "y" and orig_width  or floor(orig_width / #self.widgets)
 
     for k, v in pairs(self.widgets) do
         local w, h = base.fit_widget(v, sub_width, sub_height)
-        local max
-        if self.dir == "y" then
-            max = w
-        else
-            max = h
-        end
-        if max > used_max then
-            used_max = max
+        
+        local max = self.dir == "y" and w or h
+        if max > used_in_other then
+            used_in_other = max
         end
+        
+        used_in_dir = used_in_dir + (self.dir == "y" and h or w)
+    end
+
+    if self._max_widget_size then
+        used_in_dir = math.min(used_in_dir,
+            #self.widgets * self._max_widget_size)
     end
 
     if self.dir == "y" then
-        return used_max, used_in_dir
+        return used_in_other, used_in_dir
     end
-    return used_in_dir, used_max
+    return used_in_dir, used_in_other
 end
 
 function flex:reset()
-- 
1.8.3.2

Reply via email to