下の画像で、上のボタンがfloat_wnd_set_imgui_builder()で作成したもの、下の日本語がfloat_wnd_set_ondrow()で作成したもの。同じウインドウに共存して表示することができる。

functionを別々にしたもの。
filename.lua
x
12
12
1
wnd = float_wnd_create(280, 120, 1, true)
2
float_wnd_set_title(wnd, "imgui Button")
3
float_wnd_set_imgui_builder(wnd, "button_demo")
4
float_wnd_set_ondraw(wnd, "on_draw")
5
float_wnd_set_onclose(wnd, "closed_demo")
6
7
function button_demo(wnd, x, y)
8
imgui.Button("Push Me")
9
end
10
function on_draw(wnd, x, y)
11
draw_string(x, y + 50, "DCバッテリースイッチをオンにする", "white")
12
end
float_wnd_set_imgui_builder()の中にfloat_wnd_set_ondrow()を入れても同じように動作する。
filename.lua
1
12
12
1
wnd = float_wnd_create(280, 120, 1, true)
2
float_wnd_set_title(wnd, "imgui Button")
3
float_wnd_set_imgui_builder(wnd, "button_demo")
4
float_wnd_set_ondraw(wnd, "on_draw")
5
float_wnd_set_onclose(wnd, "closed_demo")
6
7
function button_demo(wnd, x, y)
8
imgui.Button("Push Me")
9
function on_draw(wnd, x, y)
10
draw_string(x, y + 50, "DCバッテリースイッチをオンにする", "white")
11
end
12
end
これはあくまで、float_wnd_set_imgui_builder()があってfloat_wnd_set_ondrow()が動作するようで、逆にするとウインドウは表示されるが中身が表示されなくなる。
ondrawで作成したフォントが左下が起点になる問題
左下が起点になると、ウインドウを広げると左はいいが天地のテキストが下を基準に移動してしまう。上から起点にする必要がある。以下のようにウインドウを広げても左上が起点になっているのでテキストは移動しない。


float_wnd_get_geometryを使うことで左右上下の位置を取得できるので「y + (winTop – winBottom)」でyの位置を上からにすることが出来る。
filename.lua
1
15
15
1
wnd = float_wnd_create(280, 220, 1, true)
2
float_wnd_set_title(wnd, "imgui Button")
3
float_wnd_set_ondraw(wnd, "on_draw")
4
float_wnd_set_onclose(wnd, "closed_demo")
5
6
-- xとyはウィンドウの原点、つまり左下、 xは右に増加し、yは上に増加する。
7
function on_draw(wnd, x, y)
8
--以下により左上が原点になる(winRight, winBottomを指定すると右下が原点?)
9
--winLeftとwinRightで左右のウインドウ幅を取得している。左が原点なのでこれは使わず「x」が使用されている。
10
--天地の場合、上を原点にするので「winTop - winBottom」で天地幅を取得して「y」に天が原点になるように設定されている。white yellow magenta grey green red cyan
11
winLeft, winTop, winRight, winBottom = float_wnd_get_geometry(wnd)
12
draw_string(x + 30, y + (winTop - winBottom) - (20 * 2), "DCバッテリースイッチをオンにする", "white")
13
-----------------------------------------
14
end
15
inputと日本語も使える

filename.lua
1
52
52
1
require("graphics")
2
3
local winLeft, winTop, winRight, winBottom = 0, 0, 0, 0 -- float_wnd_get_geometry (fw & os)
4
local line_number_1 = true
5
6
function build_demo(demo_wnd, x, y)
7
-- imguiでできる最も簡単なことは、テキストを描画することです。
8
imgui.TextUnformatted("Hello, World!")
9
10
local changed, newText = imgui.InputText("Text", "input", 20)
11
if changed then
12
text = newText
13
end
14
------------/////////draw関数ウインドウ///////////----------------------------------------------
15
function on_draw()
16
winLeft, winTop, winRight, winBottom = float_wnd_get_geometry(demo_wnd) --テキスト位置を設定するので重要
17
18
if line_number_1 == true then
19
graphics.set_color(1, 0, 0, 1) --赤
20
else
21
graphics.set_color(0, 1, 0, 1) --黄緑
22
end
23
graphics.draw_filled_circle(x + 20, y + (winTop - winBottom) + 3 - (20 * 5), 5) --円
24
draw_string(x + 30, y + (winTop - winBottom) - (20 * 5), "DCバッテリースイッチをオンにする",
25
"white")
26
end -- function on_draw
27
28
------------/////////draw関数ウインドウ///////////----------------------------------------------
29
end
30
31
function on_click(demo_wnd, x, y, state)
32
--ボタンダウンのマウスイベントのみを気にします
33
if (state == 1) then
34
if (x >= 2 and x <= 27 and y >= winTop - winBottom - 44 - (20 * 0) and y <= winTop - winBottom - 30 - (20 * 0)) then
35
--logMsg("in setTitle statement")
36
if line_number_1 == true then --つまり黄緑マルが表示されていたら
37
line_number_1 = false --赤マルを表示
38
else
39
line_number_1 = true --そうでないなら黄緑マルを表示
40
end
41
end
42
end -- IF state
43
end -- function on_click
44
45
-- width, height, decoration style as per XPLMCreateWindowEx. 1 for solid background, 3 for transparent
46
--demo_wnd = float_wnd_create(800, 600, 1, true)
47
demo_wnd = float_wnd_create(400, 400, 1, true)
48
float_wnd_set_title(demo_wnd, "FlyWithLua Test")
49
float_wnd_set_ondraw(demo_wnd, "on_draw")
50
float_wnd_set_imgui_builder(demo_wnd, "build_demo")
51
float_wnd_set_onclick(demo_wnd, "on_click")
52
float_wnd_set_onclose(demo_wnd, "on_close")