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

I want to write a button to mimic the close button and trigger WM_CLOSE. #43

Closed Vucius closed 1 year ago

Vucius commented 1 year ago

Code:

require 'glimmer-dsl-libui'

class MyWindow

  include Glimmer

  def initialize

    @window = window('Example Window', 300, 200) { |rrr|
      on_closing {
        puts 'Closing window...'
# **************
# do something
# *************
      }

      button('Close') {
        on_clicked do
          rrr.destroy
        end
      }

    }
  end
  def show
    @window.show
  end
end

MyWindow.new.show

The problem is that when rrr.destroy is executed, the window is closed but the program does not capture WM_CLOSE or exit. If I add the statement LibUI.quit after rrr.destroy, the program will exit directly. So I would like to know how to trigger sending a WM_CLOSE message to the program. I am currently using on_destroy instead of on_closing. Although it has accomplished my task, I am still curious about how to trigger on_closing. Thank you.

AndyObtiva commented 1 year ago

on_closing is only triggered when you click the "x" button in the top-left corner of the window (or top-right depending on the operating system) to close it. There is no other way to programmatically trigger it. That is the reason why I added support for on_destroy in Glimmer DSL for LibUI. It's because there is no way to hook into on_closing if you close the window programmatically by calling window_object.destroy. Using LibUI.quit is the correct way to exit if you want to programmatically end the LibUI app after closing the window.

Given that you already have the solution, I am closing this issue. But, if you have further questions or are not satisifed with the answer, feel free to reply or even re-open the issue.

Vucius commented 1 year ago

on_closing is only triggered when you click the "x" button in the top-left corner of the window (or top-right depending on the operating system) to close it. There is no other way to programmatically trigger it. That is the reason why I added support for on_destroy in Glimmer DSL for LibUI. It's because there is no way to hook into on_closing if you close the window programmatically by calling window_object.destroy. Using LibUI.quit is the correct way to exit if you want to programmatically end the LibUI app after closing the window.

Given that you already have the solution, I am closing this issue. But, if you have further questions or are not satisifed with the answer, feel free to reply or even re-open the issue.

Thank you for your explanation.Moving forward, I checked both the Glimmer DSL API and Go UI (Golang LibUI) API Documentation and did not find any methods for controlling window position. I wanted to ask if there are currently no related methods available. In the past, when using TK, I was able to control window position by obtaining the screen size.

AndyObtiva commented 1 year ago

Setting the window position is an upcoming feature in LibUI-NG: https://github.com/libui-ng/libui-ng/pull/62

Once it is released, it can be included in Glimmer DSL for LibUI.