Module: RbSDL2::MessageBox
- Defined in:
- lib/rb_sdl2/message_box.rb
Defined Under Namespace
Modules: MessageBoxFlags
Classes: MessageBoxButtonDataArray, MessageBoxData
Constant Summary
collapse
- CONFIRMATION_OPTIONS =
{ buttons: { Cancel: false, OK: true }, default: true }.freeze
Class Method Summary
collapse
-
.alert(msg = nil, window = nil, level: nil, message: msg, title: nil) ⇒ Object
-
.confirm(*args, **opts) ⇒ Object
-
.dialog(msg = nil, window = nil, buttons:, message: msg, **opts) ⇒ Object
buttons: “label” | [“label”,…] | [[“label”, obj],…] | => obj,… buttons 1個以上のオブジェクトがあること。0個の場合はエラーになる。 colors: [[r,g,b],…] | nil 環境(例えば Win10)によっては colors は反映されない。 nil の場合はシステム設定のカラーが使用される。 ユーザがクリックしたボタンに応じたオブジェクトが戻る。 ユーザが Escape キーが押した場合(何も選択しなかった場合)ブロックが与えられていればブロックの評価内容が、 ブロックがなければ nil が戻る。.
-
.error(*args, title: :Error, **opts) ⇒ Object
-
.info(*args, title: :Information, **opts) ⇒ Object
-
.warn(*args, title: :Warning, **opts) ⇒ Object
Class Method Details
.alert(msg = nil, window = nil, level: nil, message: msg, title: nil) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/rb_sdl2/message_box.rb', line 70
def alert(msg = nil, window = nil, level: nil, message: msg, title: nil)
err = ::SDL2.SDL_ShowSimpleMessageBox(MessageBoxFlags.to_num(level),
title&.to_s&.encode(Encoding::UTF_8),
message&.to_s&.encode(Encoding::UTF_8),
window)
raise RbSDL2Error if err < 0
end
|
.confirm(*args, **opts) ⇒ Object
78
|
# File 'lib/rb_sdl2/message_box.rb', line 78
def confirm(*args, **opts) = dialog(*args, **opts.merge!(CONFIRMATION_OPTIONS))
|
.dialog(msg = nil, window = nil, buttons:, message: msg, **opts) ⇒ Object
buttons: “label” | [“label”,…] | [[“label”, obj],…] | => obj,… buttons 1個以上のオブジェクトがあること。0個の場合はエラーになる。colors: [[r,g,b],…] | nil 環境(例えば Win10)によっては colors は反映されない。 nil の場合はシステム設定のカラーが使用される。ユーザがクリックしたボタンに応じたオブジェクトが戻る。ユーザが Escape キーが押した場合(何も選択しなかった場合)ブロックが与えられていればブロックの評価内容が、ブロックがなければ nil が戻る。
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/rb_sdl2/message_box.rb', line 87
def dialog(msg = nil, window = nil, buttons:, message: msg, **opts)
button_data = *buttons
raise ArgumentError if button_data.empty?
if opts.key?(:default)
opts.merge!(return_key: button_data.index { |*, obj| obj == opts[:default] })
opts.delete(:default)
end
ptr = ::FFI::MemoryPointer.new(:int)
data = MessageBoxData.new(buttons: button_data, message: message, window: window, **opts)
err = ::SDL2.SDL_ShowMessageBox(data, ptr)
raise RbSDL2Error if err < 0
if (idx = ptr.read_int) < 0
block_given? ? yield : nil
else
button_data[idx]
end
end
|
.error(*args, title: :Error, **opts) ⇒ Object
108
109
110
|
# File 'lib/rb_sdl2/message_box.rb', line 108
def error(*args, title: :Error, **opts)
alert(*args, title: title, **opts.merge!(level: :error))
end
|
.info(*args, title: :Information, **opts) ⇒ Object
112
113
114
|
# File 'lib/rb_sdl2/message_box.rb', line 112
def info(*args, title: :Information, **opts)
alert(*args, title: title, **opts.merge!(level: :info))
end
|
.warn(*args, title: :Warning, **opts) ⇒ Object
116
117
118
|
# File 'lib/rb_sdl2/message_box.rb', line 116
def warn(*args, title: :Warning, **opts)
alert(*args, title: title, **opts.merge!(level: :warn))
end
|