Sha256: f993e70f409ca860e25c6b9e66784f9e6d54732cca40550022f772932846c484
Contents?: true
Size: 1.26 KB
Versions: 7
Compression:
Stored size: 1.26 KB
Contents
# -*- coding: utf-8 -*- require 'reflex/view' module Reflex class Button < View has_model attr_accessor :text def initialize(*args, &block) self.data = false super self.text = self.name unless self.text end def content_bounds() f = window.painter.font return f.width(@text) + 2, f.height + 2 end def on_press(e) end def on_draw(e) e.painter.push fill: (pressing? ? :white : :none), stroke: :white do |p| p.rect e.bounds if @text p.fill pressing? ? :black : :white x = (e.bounds.w - p.font.w(@text)) / 2 y = (e.bounds.h - p.font.h) / 2 p.text @text, x, y end p.fill :none p.rect e.bounds end end def on_pointer(e) case e.type when :down self.capture += [:pointer] redraw when :up if pressing? self.capture -= [:pointer] if frame.move_to(0, 0).include? e.position self.data = true self.data = false end redraw end end end def on_data_update(e) on_press({}) if e.data end private def pressing?() capturing? :pointer end end# Button end# Reflex
Version data entries
7 entries across 7 versions & 1 rubygems