From b3d64c481bb1f5d928d89de48096866150ef3d6d Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 15 Nov 2021 09:55:54 +0100 Subject: [PATCH] Stuff --- src/lib/ui.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/ui.rb b/src/lib/ui.rb index 0057cfb..f1a7f90 100644 --- a/src/lib/ui.rb +++ b/src/lib/ui.rb @@ -72,13 +72,8 @@ class Button < UI @events = {} end - - def onclick - end - # TODO: make this work - # TODO: make this also work for KeyHooks - def set_onclick(name, &block) + def create_method(name, &block) self.class.send(:define_method, name, &block) end @@ -91,6 +86,14 @@ class Button < UI self.selected = inx && iny end + def add_event(event_sym, method_ptr) + self.events[event_sym] = method_ptr + end + + def onevent(event_sym, *args, **kwargs) + self.events[event_sym].(*args, **kwargs) + end + def render sel = self.hover? ? :selected : :default self.draw_rect(0, 0, self.width, self.height, self.colors[:background][sel])