From bbca9b5a3e77e821e1aa926578cbf2db94bd921c Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Sun, 3 Apr 2016 00:47:07 -0700 Subject: [PATCH] fixed window title displacement --- demo/main.lua | 4 +++- demo/pop/elements/element.lua | 3 +++ demo/pop/elements/window.lua | 10 +++++----- demo/pop/extensions/streamlined_get_set.lua | 7 +++++++ lib/pop/elements/element.lua | 3 +++ lib/pop/elements/window.lua | 10 +++++----- lib/pop/extensions/streamlined_get_set.lua | 7 +++++++ src/pop/elements/element.moon | 3 +++ src/pop/elements/window.moon | 14 +++++++++----- src/pop/extensions/streamlined_get_set.moon | 7 +++++++ 10 files changed, 52 insertions(+), 16 deletions(-) diff --git a/demo/main.lua b/demo/main.lua index 5cfa46a..e857148 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -37,7 +37,9 @@ function love.load() w2:setHeight(500) w2:move(0, -175) w2.title:align("center") - w2:size(200, 120) + w2:position(0, 0) + --w2:setAlignment("right") + w2:size(200, 120):position(90, 70) --w2:align("center") --w2:setAlignment("center"):align("center") diff --git a/demo/pop/elements/element.lua b/demo/pop/elements/element.lua index 60ab9df..8af555a 100644 --- a/demo/pop/elements/element.lua +++ b/demo/pop/elements/element.lua @@ -189,6 +189,9 @@ do end return self end, + getAlignment = function(self) + return self.horizontal, self.vertical + end, setMargin = function(self, margin) self.margin = margin self:align() diff --git a/demo/pop/elements/window.lua b/demo/pop/elements/window.lua index 173471f..f791a16 100644 --- a/demo/pop/elements/window.lua +++ b/demo/pop/elements/window.lua @@ -58,6 +58,7 @@ do self.window:setWidth(w) self.w = w self.x = self.x + x + self.title:align() end if h then h = h - self.head:getHeight() @@ -72,7 +73,6 @@ do self.y = self.y + y end self.head:move(x, y) - self.title:move(x, y) self.window:move(x, y) return self end, @@ -88,8 +88,8 @@ do self.window:setWidth(w) self.w = w self.x = self.x + x + self.title:align() self.head:move(x) - self.title:move(x) self.window:move(x) return self end, @@ -105,9 +105,9 @@ do self.window:setHeight(h) self.h = h + self.head:getHeight() self.y = self.y + y - self.head:move(x, y) - self.title:move(x, y) - self.window:move(x, y) + self.head:move(nil, y) + self.title:move(nil, y) + self.window:move(nil, y) return self end } diff --git a/demo/pop/extensions/streamlined_get_set.lua b/demo/pop/extensions/streamlined_get_set.lua index 7f95704..b23a6d2 100644 --- a/demo/pop/extensions/streamlined_get_set.lua +++ b/demo/pop/extensions/streamlined_get_set.lua @@ -35,6 +35,13 @@ element.__base.height = function(self, h) return self:getHeight() end end +element.__base.alignment = function(self, horizontal, vertical) + if horizontal or vertical then + return self:setAlignment(horizontal, vertical) + else + return self:getAlignment() + end +end element.__base.margin = function(self, m) if m then return self:setMargin(m) diff --git a/lib/pop/elements/element.lua b/lib/pop/elements/element.lua index 60ab9df..8af555a 100644 --- a/lib/pop/elements/element.lua +++ b/lib/pop/elements/element.lua @@ -189,6 +189,9 @@ do end return self end, + getAlignment = function(self) + return self.horizontal, self.vertical + end, setMargin = function(self, margin) self.margin = margin self:align() diff --git a/lib/pop/elements/window.lua b/lib/pop/elements/window.lua index 173471f..f791a16 100644 --- a/lib/pop/elements/window.lua +++ b/lib/pop/elements/window.lua @@ -58,6 +58,7 @@ do self.window:setWidth(w) self.w = w self.x = self.x + x + self.title:align() end if h then h = h - self.head:getHeight() @@ -72,7 +73,6 @@ do self.y = self.y + y end self.head:move(x, y) - self.title:move(x, y) self.window:move(x, y) return self end, @@ -88,8 +88,8 @@ do self.window:setWidth(w) self.w = w self.x = self.x + x + self.title:align() self.head:move(x) - self.title:move(x) self.window:move(x) return self end, @@ -105,9 +105,9 @@ do self.window:setHeight(h) self.h = h + self.head:getHeight() self.y = self.y + y - self.head:move(x, y) - self.title:move(x, y) - self.window:move(x, y) + self.head:move(nil, y) + self.title:move(nil, y) + self.window:move(nil, y) return self end } diff --git a/lib/pop/extensions/streamlined_get_set.lua b/lib/pop/extensions/streamlined_get_set.lua index 7f95704..b23a6d2 100644 --- a/lib/pop/extensions/streamlined_get_set.lua +++ b/lib/pop/extensions/streamlined_get_set.lua @@ -35,6 +35,13 @@ element.__base.height = function(self, h) return self:getHeight() end end +element.__base.alignment = function(self, horizontal, vertical) + if horizontal or vertical then + return self:setAlignment(horizontal, vertical) + else + return self:getAlignment() + end +end element.__base.margin = function(self, m) if m then return self:setMargin(m) diff --git a/src/pop/elements/element.moon b/src/pop/elements/element.moon index b3f8c83..9d5e3af 100644 --- a/src/pop/elements/element.moon +++ b/src/pop/elements/element.moon @@ -216,6 +216,9 @@ class element return @ + getAlignment: => + return @horizontal, @vertical + setMargin: (margin) => @margin = margin @align! diff --git a/src/pop/elements/window.moon b/src/pop/elements/window.moon index 3c2ea26..d576952 100644 --- a/src/pop/elements/window.moon +++ b/src/pop/elements/window.moon @@ -136,6 +136,8 @@ class window extends element @w = w @x += x + @title\align! + if h h = h - @head\getHeight! switch @vertical @@ -149,7 +151,7 @@ class window extends element @y += y @head\move x, y - @title\move x, y + --@title\move x, y @window\move x, y return @ @@ -168,8 +170,10 @@ class window extends element @w = w @x += x + @title\align! + @head\move x - @title\move x + --@title\move x @window\move x return @ @@ -188,8 +192,8 @@ class window extends element @h = h + @head\getHeight! @y += y - @head\move x, y - @title\move x, y - @window\move x, y + @head\move nil, y + @title\move nil, y + @window\move nil, y return @ diff --git a/src/pop/extensions/streamlined_get_set.moon b/src/pop/extensions/streamlined_get_set.moon index 3ffed7a..be6d72b 100644 --- a/src/pop/extensions/streamlined_get_set.moon +++ b/src/pop/extensions/streamlined_get_set.moon @@ -31,6 +31,13 @@ element.__base.height = (h) => else return @getHeight! +element.__base.alignment = (horizontal, vertical) => + if horizontal or vertical + return @setAlignment horizontal, vertical + else + return @getAlignment! + +-- why is this bit here? Oo element.__base.margin = (m) => if m return @setMargin m