physics
E. Almqvist 3 years ago
parent ae8a8d001c
commit b3d64c481b
  1. 15
      src/lib/ui.rb

@ -72,13 +72,8 @@ class Button < UI
@events = {} @events = {}
end end
def onclick
end
# TODO: make this work def create_method(name, &block)
# TODO: make this also work for KeyHooks
def set_onclick(name, &block)
self.class.send(:define_method, name, &block) self.class.send(:define_method, name, &block)
end end
@ -91,6 +86,14 @@ class Button < UI
self.selected = inx && iny self.selected = inx && iny
end 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 def render
sel = self.hover? ? :selected : :default sel = self.hover? ? :selected : :default
self.draw_rect(0, 0, self.width, self.height, self.colors[:background][sel]) self.draw_rect(0, 0, self.width, self.height, self.colors[:background][sel])

Loading…
Cancel
Save