ファイルを読み書きして保存、保存前のキャンセルで前に戻すボタンまで作成
if not SUPPORTS_FLOATING_WINDOWS then
-- スクリプトが古いFlyWithLuaバージョンを停止しないようにするため
logMsg("imgui not supported by your FlyWithLua version")
return
end
local data_1 = ""
local data_2 = ""
local data_3 = ""
-- imguiはフローティングウィンドウ内でのみ機能するため、最初に作成する必要があります。
demo_wnd = float_wnd_create(200, 200, 1, true)
float_wnd_set_title(demo_wnd, "imgui TextEdit_Demo")
float_wnd_set_imgui_builder(demo_wnd, "build_demo")
--ファイル読み込みための関数、Cancelボタンに使用、この下に改めて読み込みのためにも使用。
local function file_read()
file = io.open(SCRIPT_DIRECTORY .. "read.txt", "r")
for line in file:lines() do
data_1, data_2, data_3 = string.match(line, "(.-)%,(.-)%,(.+)")
end
file:close() -- 最後にf:closeでファイルを閉じる
end
file_read()
--imguiでテキスト編集と編集したテキストを読み込み表示する関数
function build_demo(wnd, x, y)
--以下で書き込みは完全-------------------------------------------
-- ユーザーがテキストを入力できるようにする。
local changed, newText_1 = imgui.InputText("Text-1", data_1, 255) -- パラメーター:ラベル、現在のテキスト、許可される最大文字数
if changed then
data_1 = newText_1
end
local changed, newText_2 = imgui.InputText("Text-2", data_2, 255) -- パラメーター:ラベル、現在のテキスト、許可される最大文字数
if changed then
data_2 = newText_2
end
local changed, newText_3 = imgui.InputText("Text-3", data_3, 255) -- パラメーター:ラベル、現在のテキスト、許可される最大文字数
if changed then
data_3 = newText_3
end
-- Saveボタンでファイルに書き出す----------------------
if imgui.Button("Save", 50, 20) then
local file = io.open(SCRIPT_DIRECTORY .. "read.txt", "w")
file:write(data_1 .. ",")
file:write(data_2 .. ",")
file:write(data_3 .. "")
file:close()
end
if imgui.Button("Cancel", 50, 20) then
file_read()
end
end