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
458 stars 15 forks source link

Consider adding the speed option to colour-the-circles .rb example #44

Open rubyFeedback opened 1 year ago

rubyFeedback commented 1 year ago

Colour the circles example allows us to click on a circle and colour fill it.

We can also designate the difficulty.

Would it be possible to also be able to set the speed, that is, how quickly a circle appears? If you want to retain hardcoded values for the difficulty then that is fine, so I am more proposing a separate "free-form variant" where we can say "speed at 5 new circles in 3 seconds" or something like that (e. g. the ratio of that).

Not sure where to set this, probably from the menu it makes the most sense, e. g. next to the difficulty slider, or in the same area.

Can we use tooltips in libui? Probably not, but I think tooltips would be quite convenient to quickly explain the options.

The example code I used was from here:

https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-libui/master/examples/color_the_circles.rb

At any rate, please feel free to proceed with the issue reques tin any way you see fit. Glimmer on!

PS: I am working through all glimmer examples right now, slowly. First on linux, then I want to test it on windows - the latter is a very nifty use case for ruby users. On linux I can use ruby-gtk3 directly, so this is interesting how it works on windows.

AndyObtiva commented 1 year ago

I’m watching a baseball game at Fenway Park right now, so I’ll send a more detailed response later.

But, I just wanted to note that this is just a sample, and I think the levels of difficulty it offers are good enough as variations. I don’t think changing the speed is important because adding more circles already forces the player to operate at a higher speed, so it’s almost the same thing, and is sufficient as such.

You are welcome to build your own standalone project though and add it on GitHub. You can also let me know here if you do so.

As for tooltips, you can add some inside an area control. For regular controls, that’s not supported in LibUI yet, but is in SWT.

Later.

AndyObtiva commented 1 year ago

OK, I opened an issue at the libui-ng project to support tooltips given that they are missing from it: https://github.com/libui-ng/libui-ng/issues/188

Otherwise, in Glimmer DSL for SWT if you are willing to use it instead, it is very simple to add tooltips to any controls using tool_tip_text (which displays automatically on mouse hover):

require 'glimmer-dsl-swt'

class HelloButton
  include Glimmer::UI::CustomShell

  attr_accessor :count

  before_body do
    self.count = 0
  end

  body {
    shell {
      text 'Hello, Button!'

      button {
        text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value}  " }]
        tool_tip_text 'Clicking this button increments the button count.'

        on_widget_selected do
          self.count += 1
        end
      }
    }
  }
end

HelloButton.launch
Screenshot 2023-04-02 at 10 41 15 AM

I am keeping this issue open until libui-ng supports tooltips and they are included in Glimmer DSL for LibUI.

AndyObtiva commented 1 year ago

I also mentioned you could already add a tooltip in Glimmer DSL for LibUI when using the area control.

Here is an example of how to do it (you can fine tune it by adding a time delay if you like):

require 'glimmer-dsl-libui'

include Glimmer

window('Basic Area', 400, 400) {
  margined true

  vertical_box {
    area { |area_proxy|
      rectangle(0, 0, 400, 400) { # stable implicit path shape, added declaratively
        fill r: 102, g: 102, b: 204, a: 1.0

        on_mouse_moved do |area_mouse_event|
          @last_move_time = Time.now

          if @tooltip_rectangle || @tooltip_text
            @tooltip_rectangle&.destroy
            @tooltip_text&.destroy
            area_proxy.queue_redraw_all
          end

          area_proxy.content {
            @tooltip_rectangle = rectangle(area_mouse_event[:x], area_mouse_event[:y], 100, 100) {
              fill r: 0, g: 255, b: 255, a: 1.0
            }
            @tooltip_text = text(area_mouse_event[:x] + 20, area_mouse_event[:y] + 20, 60) { # declarative stable text
              string('This is a tooltip!') {
                font family: 'Arial', size: (OS.mac? ? 14 : 11)
                color :black
              }
            }
          }

          Glimmer::LibUI.timer(3, repeat: false) do
            # ensure not to close tooltip if the user moves the mouse again
            # by comparing time to last move time
            if Time.now - @last_move_time >= 3
              @tooltip_rectangle&.destroy
              @tooltip_text&.destroy
              area_proxy.queue_redraw_all
            end
          end
        end
      }
    }
  }
}.show
Screenshot 2023-04-02 at 10 59 01 AM

The tooltip will follow the mouse cursor, and will disappear after 3 seconds of no mouse movement.