AndyObtiva / glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.
MIT License
497 stars 15 forks source link

Add on_click listener to a :text control. #56

Closed sergioro9 closed 11 months ago

sergioro9 commented 1 year ago

It seems that :on_click is not available for :text element. Could this be added in future versions? Alternatively, I could use :on_click in a :button but I need the button to look like plain text... I haven't found a button property that can do that.

AndyObtiva commented 1 year ago

Glimmer DSL for SWT actually supports this sort of behavior via general control listeners. All controls in it support on_mouse_down for example:

window {
  text {
    on_mouse_down do
      message_box {
        text 'Mouse Event'
        message 'Mouse Down'
      }.open
    end
  }
}.show
Screenshot 2023-09-01 at 3 32 39 PM

However, Glimmer DSL for LibUI does not support general mouse and keyboard event listeners. Each control has its own unique listeners only.

I just reported the need for supporting general control mouse listeners (and other general listeners) at the upstream libui-ng C library project: https://github.com/libui-ng/libui-ng/issues/219

Thank you for reporting this. In the meantime, you could try to accomplish your needs using Glimmer DSL for SWT or another Glimmer GUI toolkit that supports the feature you need.

cody271 commented 1 year ago

I need the button to look like plain text... I haven't found a button property that can do that.

What about a custom button control with area ? Here is an example:

require 'glimmer-dsl-libui'

include Glimmer

window('Area Label', 400, 400) {
  area {

    text(161, 40, 100) { # declarative stable text
      string('Click me!') {
        font family: 'Arial', size: (OS.mac? ? 14 : 11)
        color :white
      }
    }

    on_mouse_down do |area_mouse_event|
      msg_box('mouse event', 'mouse down')
    end
  }
}.show

area_label1 area_label2

AndyObtiva commented 1 year ago

@cody271 is a genius! Not only does he maintain the underlying libui-ng library in C, but he also writes great Ruby code too! (BTW, on_mouse_up could have been used too if the mouse up action is preferred as the trigger as that is closer to the button on_clicked behavior)