Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Adding UI::Eventable to label #55

Open
friendlyuis opened this issue Nov 19, 2016 · 2 comments
Open

Idea: Adding UI::Eventable to label #55

friendlyuis opened this issue Nov 19, 2016 · 2 comments

Comments

@friendlyuis
Copy link

friendlyuis commented Nov 19, 2016

Hi All,

I was trying to make a simple menu system with lists//labels and realized there were no actual way of making it work (or at least, that I know of) so I started thinking, can't we make anything anything tap-able like UI::Button? Now I haven't tried this, but looking at the button.rb file, I found this:

def initialize(view)
@view = view
end

def onClick(button)
@view.trigger :tap
end
end

module UI
class Button < UI::Control
include Eventable

...

Does it mean all we have to do to make labels tap-able is add the first two methods and include UI::Control::Eventable in the Label Class? I tried to modify the label.rb files but they were read-only. Needless to say I haven't actually actioned anything yet.

If there's an obvious solution that already exists, I apologise in advance, I'm new to ruby, rubymotion and the mac ecosystem. lol. Figured I'd suggest it, just as food for thought. Let me know what you guys think.

@jjaffeux
Copy link
Contributor

jjaffeux commented Nov 20, 2016

You would need to do what we are doing on text_input https://github.com/HipByte/Flow/blob/master/flow/ui/cocoa/text_input.rb#L5

You would override on(event) to add a gesture recognizer on the label. At least this is how you could achieve this on iOS.

# in label class
include Eventable

def on(event, &block)
  case event
  when :tap
    tap = UITapGestureRecognizer.alloc.initWithTarget(self, action: "on_tap")
    proxy.addGestureRecognizer(tap)
  else
    raise "Expected event to be in : `:tap`"
  end

  super
end

def on_tap
  self.trigger(:tap)
end

Should work

@friendlyuis
Copy link
Author

friendlyuis commented Nov 20, 2016

Cool, that means if we did something similar(accessing the native API to the Android label class with https://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html) we'd get it cross platform. I'll provide update if and when I figure out how to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants