From d980e14c1b6bd38da2fa85a508dfd0bff6a73ed7 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Wed, 27 Apr 2016 12:03:24 -0700 Subject: [PATCH] close #29 renaming margin --- demo/main.lua | 2 +- demo/pop/elements/element.lua | 24 ++++++++++----------- demo/pop/elements/text.lua | 4 ++-- lib/pop/elements/element.lua | 24 ++++++++++----------- lib/pop/elements/text.lua | 4 ++-- src/pop/elements/element.moon | 24 ++++++++++----------- src/pop/elements/text.moon | 4 ++-- src/pop/extensions/streamlined_get_set.moon | 12 ----------- 8 files changed, 43 insertions(+), 55 deletions(-) diff --git a/demo/main.lua b/demo/main.lua index 18caf6d..e4247d1 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -23,7 +23,7 @@ function love.load() pop.text(nil, "Here's some test text in the bottom right corner!"):align("right", "bottom") pop.skin(pop.text("Here's easier-to-code test text in the center!"):align("center", "center", true)) -- 'true' means align to pixel! w = pop.box(nil, {255, 255, 255, 255}):align(false, "bottom"):setSize(150, 150) - b = pop.box(w, {0, 0, 0, 255}):setMargin(5):setSize(100, 100) + b = pop.box(w, {0, 0, 0, 255}):margin(5):setSize(100, 100) --]] --c:move(100) diff --git a/demo/pop/elements/element.lua b/demo/pop/elements/element.lua index e2a6aee..169f88c 100644 --- a/demo/pop/elements/element.lua +++ b/demo/pop/elements/element.lua @@ -180,19 +180,19 @@ do self.y = self.parent.y local _exp_0 = self.horizontal if "left" == _exp_0 then - self.x = self.x + self.margin + self.x = self.x + self.spacing elseif "center" == _exp_0 then self.x = self.x + ((self.parent.w - self.w) / 2) elseif "right" == _exp_0 then - self.x = self.x + (self.parent.w - self.w - self.margin) + self.x = self.x + (self.parent.w - self.w - self.spacing) end local _exp_1 = self.vertical if "top" == _exp_1 then - self.y = self.y + self.margin + self.y = self.y + self.spacing elseif "center" == _exp_1 then self.y = self.y + ((self.parent.h - self.h) / 2) elseif "bottom" == _exp_1 then - self.y = self.y + (self.parent.h - self.h - self.margin) + self.y = self.y + (self.parent.h - self.h - self.spacing) end if toPixel then self.x = floor(self.x) @@ -222,19 +222,19 @@ do getAlignment = function(self) return self.horizontal, self.vertical end, - setMargin = function(self, margin) - self.margin = margin + setMargin = function(self, spacing) + self.spacing = spacing self:align() return self end, getMargin = function(self) - return self.margin + return self.spacing end, fill = function(self) - self.x = self.parent.x + self.margin - self.y = self.parent.y + self.margin - self.w = self.parent.w - self.margin * 2 - self.h = self.parent.h - self.margin * 2 + self.x = self.parent.x + self.spacing + self.y = self.parent.y + self.spacing + self.w = self.parent.w - self.spacing * 2 + self.h = self.parent.h - self.spacing * 2 end, delete = function(self) for k, v in ipairs(self.child) do @@ -252,7 +252,7 @@ do self.child = { } self.w = 0 self.h = 0 - self.margin = 0 + self.spacing = 0 if parent then self.x = parent.x self.y = parent.y diff --git a/demo/pop/elements/text.lua b/demo/pop/elements/text.lua index 9d5df18..a81af09 100644 --- a/demo/pop/elements/text.lua +++ b/demo/pop/elements/text.lua @@ -35,13 +35,13 @@ do if "center" == _exp_0 then self.x = self.x - ((w - self.w) / 2) elseif "right" == _exp_0 then - self.x = self.x - (w - self.w - self.margin) + self.x = self.x - (w - self.w - self.spacing) end local _exp_1 = self.vertical if "center" == _exp_1 then self.y = self.y - ((h - self.h) / 2) elseif "bottom" == _exp_1 then - self.y = self.y - (h - self.h - self.margin) + self.y = self.y - (h - self.h - self.spacing) end self.w = w self.h = h diff --git a/lib/pop/elements/element.lua b/lib/pop/elements/element.lua index e2a6aee..169f88c 100644 --- a/lib/pop/elements/element.lua +++ b/lib/pop/elements/element.lua @@ -180,19 +180,19 @@ do self.y = self.parent.y local _exp_0 = self.horizontal if "left" == _exp_0 then - self.x = self.x + self.margin + self.x = self.x + self.spacing elseif "center" == _exp_0 then self.x = self.x + ((self.parent.w - self.w) / 2) elseif "right" == _exp_0 then - self.x = self.x + (self.parent.w - self.w - self.margin) + self.x = self.x + (self.parent.w - self.w - self.spacing) end local _exp_1 = self.vertical if "top" == _exp_1 then - self.y = self.y + self.margin + self.y = self.y + self.spacing elseif "center" == _exp_1 then self.y = self.y + ((self.parent.h - self.h) / 2) elseif "bottom" == _exp_1 then - self.y = self.y + (self.parent.h - self.h - self.margin) + self.y = self.y + (self.parent.h - self.h - self.spacing) end if toPixel then self.x = floor(self.x) @@ -222,19 +222,19 @@ do getAlignment = function(self) return self.horizontal, self.vertical end, - setMargin = function(self, margin) - self.margin = margin + setMargin = function(self, spacing) + self.spacing = spacing self:align() return self end, getMargin = function(self) - return self.margin + return self.spacing end, fill = function(self) - self.x = self.parent.x + self.margin - self.y = self.parent.y + self.margin - self.w = self.parent.w - self.margin * 2 - self.h = self.parent.h - self.margin * 2 + self.x = self.parent.x + self.spacing + self.y = self.parent.y + self.spacing + self.w = self.parent.w - self.spacing * 2 + self.h = self.parent.h - self.spacing * 2 end, delete = function(self) for k, v in ipairs(self.child) do @@ -252,7 +252,7 @@ do self.child = { } self.w = 0 self.h = 0 - self.margin = 0 + self.spacing = 0 if parent then self.x = parent.x self.y = parent.y diff --git a/lib/pop/elements/text.lua b/lib/pop/elements/text.lua index 9d5df18..a81af09 100644 --- a/lib/pop/elements/text.lua +++ b/lib/pop/elements/text.lua @@ -35,13 +35,13 @@ do if "center" == _exp_0 then self.x = self.x - ((w - self.w) / 2) elseif "right" == _exp_0 then - self.x = self.x - (w - self.w - self.margin) + self.x = self.x - (w - self.w - self.spacing) end local _exp_1 = self.vertical if "center" == _exp_1 then self.y = self.y - ((h - self.h) / 2) elseif "bottom" == _exp_1 then - self.y = self.y - (h - self.h - self.margin) + self.y = self.y - (h - self.h - self.spacing) end self.w = w self.h = h diff --git a/src/pop/elements/element.moon b/src/pop/elements/element.moon index 312c9f0..26a606b 100644 --- a/src/pop/elements/element.moon +++ b/src/pop/elements/element.moon @@ -11,7 +11,7 @@ class element @w = 0 @h = 0 - @margin = 0 + @spacing = 0 if parent @x = parent.x @@ -205,19 +205,19 @@ class element switch @horizontal when "left" - @x += @margin + @x += @spacing when "center" @x += (@parent.w - @w)/2 when "right" - @x += @parent.w - @w - @margin + @x += @parent.w - @w - @spacing switch @vertical when "top" - @y += @margin + @y += @spacing when "center" @y += (@parent.h - @h)/2 when "bottom" - @y += @parent.h - @h - @margin + @y += @parent.h - @h - @spacing if toPixel @x = floor @x @@ -246,19 +246,19 @@ class element getAlignment: => return @horizontal, @vertical - setMargin: (margin) => - @margin = margin + setMargin: (spacing) => + @spacing = spacing @align! return @ getMargin: => - return @margin + return @spacing fill: => - @x = @parent.x + @margin - @y = @parent.y + @margin - @w = @parent.w - @margin*2 - @h = @parent.h - @margin*2 + @x = @parent.x + @spacing + @y = @parent.y + @spacing + @w = @parent.w - @spacing*2 + @h = @parent.h - @spacing*2 delete: => for k,v in ipairs @child diff --git a/src/pop/elements/text.moon b/src/pop/elements/text.moon index 48324f9..9736595 100644 --- a/src/pop/elements/text.moon +++ b/src/pop/elements/text.moon @@ -47,13 +47,13 @@ class text extends element when "center" @x -= (w - @w)/2 when "right" - @x -= w - @w - @margin + @x -= w - @w - @spacing switch @vertical when "center" @y -= (h - @h)/2 when "bottom" - @y -= h - @h - @margin + @y -= h - @h - @spacing @w = w @h = h diff --git a/src/pop/extensions/streamlined_get_set.moon b/src/pop/extensions/streamlined_get_set.moon index 5391baf..0593142 100644 --- a/src/pop/extensions/streamlined_get_set.moon +++ b/src/pop/extensions/streamlined_get_set.moon @@ -39,24 +39,12 @@ element.__base.alignment = (horizontal, vertical) => else return @getAlignment! --- why is this bit here? Oo element.__base.margin = (m) => if m return @setMargin m else return @getMargin! ---oldinit = element.__init --- ---element.__init = (...) -> --- object = oldinit ... --- value = object.margin --- --- object.margin = setmetatable {:value}, { --- __call: (...) -> --- print ... --- } - element.__base.resize = element.__base.adjustSize -- box.__base.background -- can't be done!