From 5b67180f8948420281e3850907322443364f5b7f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 25 Oct 2021 17:08:17 +0200 Subject: [PATCH] onpress buttons etc --- src/lib/ui.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/ui.rb b/src/lib/ui.rb index c3dd4f3..29a37cb 100644 --- a/src/lib/ui.rb +++ b/src/lib/ui.rb @@ -74,10 +74,20 @@ class Button < UI def hover? inx = window.mouse_x >= self.x && window.mouse_x <= self.x + self.width + self.padding[:x] iny = window.mouse_y >= self.y && window.mouse_y <= self.y + self.height + self.padding[:y] + # doing `n in (a..b).to....` is too slow + # hence the ugly syntax above self.selected = inx && iny end + def method_ptr=(self, new_ptr) + # TODO: make a method pointer for button presses etc + end + + def onclick(id) + self.method_ptr.call(id, *args, **kwargs) + end + def render sel = self.hover? ? :selected : :default self.draw_rect(0, 0, self.width, self.height, self.colors[:background][sel])