about summary refs log tree commit diff stats
path: root/button.lua
blob: 7549169735600db9972f21a323b26210f07cea39 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- Simple immediate-mode buttons with (currently) just an onpress1 handler for
-- the left button.
--
-- Buttons can nest in principle, though I haven't actually used that yet.
--
-- Don't rely on the order in which handlers are run. Within any widget, all
-- applicable button handlers will run. If _any_ of them returns true, the
-- event will continue to propagate elsewhere in the widget.

-- draw button and queue up event handlers
function button(State, name, params)
  if State.button_handlers == nil then
    State.button_handlers = {}
  end
  love.graphics.setColor(params.color[1], params.color[2], params.color[3])
  love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
  if params.icon then params.icon(params) end
  table.insert(State.button_handlers, params)
end

-- process button event handlers
function mouse_press_consumed_by_any_button_handler(State, x, y, mouse_button)
  if State.button_handlers == nil then
    return
  end
  local button_pressed = false
  local consume_press = true
  for _,ev in ipairs(State.button_handlers) do
    if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
      if ev.onpress1 and mouse_button == 1 then
        button_pressed = true
        if ev.onpress1() then
          consume_press = false
        end
      end
    end
  end
  return button_pressed and consume_press
end
quot;: { "nan": "^2.3.5" }, "engines": { "node": ">=0.8.0" } }, "node_modules/irc": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/irc/-/irc-0.5.2.tgz", "integrity": "sha512-KnrvkV05Y71SWmRWHtnlWEIH7LA/YeDul6l7tncCGLNEw4B6Obtmkatb3ACnSLj0kOJ6UBiuhss9e+eRG3zlxw==", "dependencies": { "irc-colors": "^1.1.0" }, "engines": { "node": ">=0.10.0" }, "optionalDependencies": { "iconv": "~2.2.1", "node-icu-charset-detector": "~0.2.0" } }, "node_modules/irc-colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/irc-colors/-/irc-colors-1.5.0.tgz", "integrity": "sha512-HtszKchBQTcqw1DC09uD7i7vvMayHGM1OCo6AHt5pkgZEyo99ClhHTMJdf+Ezc9ovuNNxcH89QfyclGthjZJOw==", "engines": { "node": ">=6" } }, "node_modules/nan": { "version": "2.18.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", "optional": true }, "node_modules/node-icu-charset-detector": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/node-icu-charset-detector/-/node-icu-charset-detector-0.2.0.tgz", "integrity": "sha512-DYOFJ3NfKdxEi9hPbmoCss6WydGhJsxpSleUlZfAWEbZt3AU7JuxailgA9tnqQdsHiujfUY9VtDfWD9m0+ThtQ==", "hasInstallScript": true, "optional": true, "dependencies": { "nan": "^2.3.3" }, "engines": { "node": ">=0.6" } } }, "dependencies": { "iconv": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/iconv/-/iconv-2.2.3.tgz", "integrity": "sha512-evIiYeKdt5nEGYKNkQcGPQy781sYgbBKi3gEkt1s4CwteCdOHSjGGRyyp6lP8inYFZwvzG3lgjXEvGUC8nqQ5A==", "optional": true, "requires": { "nan": "^2.3.5" } }, "irc": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/irc/-/irc-0.5.2.tgz", "integrity": "sha512-KnrvkV05Y71SWmRWHtnlWEIH7LA/YeDul6l7tncCGLNEw4B6Obtmkatb3ACnSLj0kOJ6UBiuhss9e+eRG3zlxw==", "requires": { "iconv": "~2.2.1", "irc-colors": "^1.1.0", "node-icu-charset-detector": "~0.2.0" } }, "irc-colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/irc-colors/-/irc-colors-1.5.0.tgz", "integrity": "sha512-HtszKchBQTcqw1DC09uD7i7vvMayHGM1OCo6AHt5pkgZEyo99ClhHTMJdf+Ezc9ovuNNxcH89QfyclGthjZJOw==" }, "nan": { "version": "2.18.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", "optional": true }, "node-icu-charset-detector": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/node-icu-charset-detector/-/node-icu-charset-detector-0.2.0.tgz", "integrity": "sha512-DYOFJ3NfKdxEi9hPbmoCss6WydGhJsxpSleUlZfAWEbZt3AU7JuxailgA9tnqQdsHiujfUY9VtDfWD9m0+ThtQ==", "optional": true, "requires": { "nan": "^2.3.3" } } } }