about summary refs log tree commit diff stats
path: root/button.lua
blob: 42c44e3eecb0f9942bb5c6389cc3c7be46220ce0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- simple immediate-mode buttons

Button_handlers = {}

-- draw button and queue up event handlers
function button(name, params)
  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.x, params.y) end
  table.insert(Button_handlers, params)
end

-- process button event handlers
function propagate_to_button_handlers(x, y, mouse_button)
  for _,ev in ipairs(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 ev.onpress1() end
    end
  end
end
"n">BMFILE, str, autosave=False) bm.load() bm['a'] = 'fooo' self.assertEqual(bm['a'], 'fooo') def test_sharing_bookmarks_between_instances(self): bm = Bookmarks(BMFILE, str, autosave=True) bm2 = Bookmarks(BMFILE, str, autosave=True) bm.load() bm2.load() bm['a'] = 'fooo' self.assertRaises(KeyError, bm2.__getitem__, 'a') bm.save() bm2.load() self.assertEqual(bm['a'], bm2['a']) bm2['a'] = 'bar' bm.save() bm2.save() bm.load() bm2.load() self.assertEqual(bm['a'], bm2['a']) def test_messing_around(self): bm = Bookmarks(BMFILE, str, autosave=False) bm2 = Bookmarks(BMFILE, str, autosave=False) bm.load() bm['a'] = 'car' bm2.load() self.assertRaises(KeyError, bm2.__getitem__, 'a') bm2.save() bm.update() bm.save() bm.load() bm2.load() self.assertEqual(bm['a'], bm2['a']) if __name__ == '__main__': unittest.main()