FontButton

日本語

FontButton opens the native font chooser and reports a FontDescriptor.

Appearance

FontButton on Ubuntu
Ubuntu
FontButton on Windows
Windows
FontButton on macOS
macOS

Runnable example

require "uing"

UIng.init

window = UIng::Window.new("FontButton Example", 300, 100, margined: true)
window.on_closing do
  UIng.quit
  true
end

font_button = UIng::FontButton.new
selected_font = font_button.font
font_button.on_changed do |font_descriptor|
  previous_font = selected_font
  selected_font = font_descriptor
  window.msg_box(
    "Font Changed",
    "Previous: #{previous_font.family}\nFamily: #{selected_font.family}\nSize: #{selected_font.size}"
  )
end

window.child = font_button
window.show

UIng.main
UIng.uninit

Usage notes

  • font returns the currently selected FontDescriptor.
  • Handle a new choice with on_changed. Its descriptor can be retained after the callback.
  • The block-based font form is also available. None of these descriptors needs free.

API reference · Gallery source