diff --git a/button.lua b/button.lua index c063ffa..f365654 100644 --- a/button.lua +++ b/button.lua @@ -6,6 +6,7 @@ return function(core, text, ...) local opt, x,y,w,h = core.getOptionsAndSize(...) opt.id = opt.id or text opt.font = opt.font or love.graphics.getFont() + opt.color = opt.color or core.theme.color w = w or opt.font:getWidth(text) + 4 h = h or opt.font:getHeight() + 4 @@ -18,6 +19,10 @@ return function(core, text, ...) hit = core:mouseReleasedOn(opt.id), hovered = core:isHovered(opt.id), entered = core:isHovered(opt.id) and not core:wasHovered(opt.id), - left = not core:isHovered(opt.id) and core:wasHovered(opt.id) + left = not core:isHovered(opt.id) and core:wasHovered(opt.id), + x = x, + y = y, + w = w, + h = h } end diff --git a/core.lua b/core.lua index 5b4d2ee..f2442bc 100644 --- a/core.lua +++ b/core.lua @@ -100,7 +100,7 @@ function suit:mouseInRect(x,y,w,h) end function suit:registerMouseHit(id, ul_x, ul_y, hit) - if hit(self.mouse_x - ul_x, self.mouse_y - ul_y) then + if not self.hovered and hit(self.mouse_x - ul_x, self.mouse_y - ul_y) then self.hovered = id if self.active == nil and self.mouse_button_down then self.active = id @@ -176,15 +176,24 @@ function suit:keyPressedOn(id, key) end -- state update -function suit:enterFrame() +function suit:enterFrame(mouseX, mouseY) if not self.mouse_button_down then self.active = nil elseif self.active == nil then self.active = NONE end + local mx = mouseX + local my = mouseY + + if mx == nil then + mx = love.mouse.getX() + end + if my == nil then + my = love.mouse.getY() + end self.hovered_last, self.hovered = self.hovered, nil - self:updateMouse(love.mouse.getX(), love.mouse.getY(), love.mouse.isDown(1)) + self:updateMouse(mx, my, love.mouse.isDown(1)) self.key_down, self.textchar = nil, "" self:grabKeyboardFocus(NONE) self.hit = nil @@ -204,14 +213,14 @@ function suit:registerDraw(f, ...) end function suit:draw() - self:exitFrame() + -- self:exitFrame() -- CALL these manually in your update method love.graphics.push('all') for i = self.draw_queue.n,1,-1 do self.draw_queue[i]() end love.graphics.pop() self.draw_queue.n = 0 - self:enterFrame() + -- self:enterFrame() -- CALL these manually in your update method end return suit diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 51605f3..3f0e560 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -5,7 +5,7 @@ Before actually getting started, it is important to understand the motivation and mechanics behind SUIT: - **Immediate mode is better than retained mode** -- **Layout does not care about widgets** +- **Layout should not care about content** - **Less is more** Immediate mode? @@ -68,11 +68,11 @@ to design a user interface. SUIT is not a complete GUI library: It does not take control of the runtime. You have to do everything yourself [1]_. -**SUIT is not good at word processors!** +**SUIT is not good at processing words!** -Hello, World ------------- +Hello, World! +------------- SUITing up is is straightforward: Define your GUI in ``love.update()``, and draw it in ``love.draw()``:: @@ -96,15 +96,19 @@ draw it in ``love.draw()``:: suit.draw() end -This will produce this UI (after clicking the button): +This will produce this UI: .. image:: _static/hello-world.gif -As written above, the two widgets are each created by a function call +The two widgets (the button and the label) are each created by a function call (:func:`suit.Button