FontButton

English

FontButtonはOS標準のフォント選択画面を開き、FontDescriptorを返します。

表示例

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

実行例

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

使い方

  • fontは現在選択されているFontDescriptorを返します。
  • 新しい選択はon_changedで処理します。受け取った記述子は コールバック後も保持できます。
  • ブロック形式のfontも使えます。どの形式でも記述子のfreeは不要です。

APIリファレンス · Galleryソース