onpress buttons etc

pull/1/head
E. Almqvist 3 years ago
parent 5314974bd5
commit 5b67180f89
  1. 10
      src/lib/ui.rb

@ -74,10 +74,20 @@ class Button < UI
def hover? def hover?
inx = window.mouse_x >= self.x && window.mouse_x <= self.x + self.width + self.padding[:x] 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] 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 self.selected = inx && iny
end 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 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