From 98a2e8093e9c2730e539856cf441e8074496f643 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Fri, 5 Jul 2019 15:08:17 -0400 Subject: [PATCH] order the areas by size (and x + y) --- editor.lua | 21 ++++++++++++--------- layout.lua | 4 +++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/editor.lua b/editor.lua index 45d468a..a7349c0 100644 --- a/editor.lua +++ b/editor.lua @@ -183,15 +183,6 @@ function start_editor(data) cr:rectangle(sa.x, sa.y, sa.width, sa.height) cr:set_line_width(10.0) cr:stroke() - - cr:select_font_face(label_font_family, "normal", "normal") - cr:set_font_size(label_size) - cr:set_font_face(cr:get_font_face()) - msg = tostring(i) - ext = cr:text_extents(msg) - cr:set_source_rgba(0.75, 0.75, 0.75, 1) - cr:move_to(sa.x + sa.width / 2 - ext.width / 2 - ext.x_bearing, sa.y + sa.height / 2 - ext.height / 2 - ext.y_bearing) - cr:show_text(msg) cr:reset_clip() end @@ -543,6 +534,18 @@ function start_editor(data) for _, a in ipairs(closed_areas) do areas_with_gap[#areas_with_gap + 1] = shrink_area_with_gap(a, gap) end + table.sort( + areas_with_gap, + function (a1, a2) + local s1 = a1.width * a1.height + local s2 = a2.width * a2.height + if math.abs(s1 - s2) < 0.01 then + return (a1.x + a1.y) < (a2.x + a2.y) + else + return s1 < s2 + end + end + ) layout.set_regions(areas_with_gap) api.layout.arrange(screen) end diff --git a/layout.lua b/layout.lua index 17ba71a..324eb1c 100644 --- a/layout.lua +++ b/layout.lua @@ -11,7 +11,9 @@ function do_arrange(p, priv) if c.machi_region == nil then c.machi_region = 1 region = 1 - elseif c.machi_region > #regions or c.machi_region <= 1 then + elseif c.machi_region > #regions then + region = #regions + elseif c.machi_region <= 1 then region = 1 else region = c.machi_region