как использовать ImGuiTextEditCallbackData

John_Feat

Новичок
Автор темы
17
1
Версия MoonLoader
.026-beta
Взял кусок отсюда https://www.blast.hk/threads/163452/
Посмотрел возможное решение здесь https://www.blast.hk/threads/66391/
Все равно не понял как используется. Нужно изменить положение курсора в поле mimgui.InputText()
Помогите пожалуйста.
Вот что имею
Lua:
ffi.cdef[[
    struct ImGuiTextEditCallbackData
    {
        ImGuiInputTextFlags EventFlag;      // One of ImGuiInputTextFlags_Callback* // Read-only
        ImGuiInputTextFlags Flags;          // What user passed to InputText()      // Read-only
        void*               UserData;       // What user passed to InputText()      // Read-only
        bool                ReadOnly;       // Read-only mode                       // Read-only

        // CharFilter event:
        ImWchar             EventChar;      // Character input                      // Read-write (replace character or set to zero)

        // Completion,History,Always events:
        // If you modify the buffer contents make sure you update 'BufTextLen' and set 'BufDirty' to true.
        ImGuiKey            EventKey;       // Key pressed (Up/Down/TAB)            // Read-only
        char*               Buf;            // Current text buffer                  // Read-write (pointed data only, can't replace the actual pointer)
        int                 BufTextLen;     // Current text length in bytes         // Read-write
        int                 BufSize;        // Maximum text length in bytes         // Read-only
        bool                BufDirty;       // Set if you modify Buf/BufTextLen!!   // Write
        int                 CursorPos;      //                                      // Read-write
        int                 SelectionStart; //                                      // Read-write (== to SelectionEnd when no selection)
        int                 SelectionEnd;   //             
                                
        void     DeleteChars (int pos, int bytes_count);
        bool     HasSelection () const;
        void     InsertChars (int pos, const char *text, const char *);
    };
]]

function edit_callback(data)
    
    return 0
end

local edit_callback = ffi.cast('int (*)(ImGuiInputTextCallbackData* data)', edit_callback)
 

FixZer

Активный
126
36
Взял кусок отсюда https://www.blast.hk/threads/163452/
Посмотрел возможное решение здесь https://www.blast.hk/threads/66391/
Все равно не понял как используется. Нужно изменить положение курсора в поле mimgui.InputText()
Помогите пожалуйста.
Вот что имею
Lua:
ffi.cdef[[
    struct ImGuiTextEditCallbackData
    {
        ImGuiInputTextFlags EventFlag;      // One of ImGuiInputTextFlags_Callback* // Read-only
        ImGuiInputTextFlags Flags;          // What user passed to InputText()      // Read-only
        void*               UserData;       // What user passed to InputText()      // Read-only
        bool                ReadOnly;       // Read-only mode                       // Read-only

        // CharFilter event:
        ImWchar             EventChar;      // Character input                      // Read-write (replace character or set to zero)

        // Completion,History,Always events:
        // If you modify the buffer contents make sure you update 'BufTextLen' and set 'BufDirty' to true.
        ImGuiKey            EventKey;       // Key pressed (Up/Down/TAB)            // Read-only
        char*               Buf;            // Current text buffer                  // Read-write (pointed data only, can't replace the actual pointer)
        int                 BufTextLen;     // Current text length in bytes         // Read-write
        int                 BufSize;        // Maximum text length in bytes         // Read-only
        bool                BufDirty;       // Set if you modify Buf/BufTextLen!!   // Write
        int                 CursorPos;      //                                      // Read-write
        int                 SelectionStart; //                                      // Read-write (== to SelectionEnd when no selection)
        int                 SelectionEnd;   //            
                               
        void     DeleteChars (int pos, int bytes_count);
        bool     HasSelection () const;
        void     InsertChars (int pos, const char *text, const char *);
    };
]]

function edit_callback(data)
   
    return 0
end

local edit_callback = ffi.cast('int (*)(ImGuiInputTextCallbackData* data)', edit_callback)
 
  • Нравится
Реакции: Z3roKwq

FixZer

Активный
126
36
Lua:
local ffi = require 'ffi'

local u8 = encoding.UTF8
local sendMessages = {}
local lastSelectedMessage = 1

local inputChat = imgui.new.char[290]()

if imgui.InputText("##inputtext", inputChat, ffi.sizeof(inputChat) - 1, imgui.InputTextFlags.CallbackHistory + imgui.InputTextFlags.CallbackCompletion, TextEditCallback) then
    sampSetChatInputText(u8:decode(ffi.string(inputChat)))
end

function TextEditCallback(data)
    if data.EventFlag == 128 then
        if data.EventKey == 3 --[[UP]] then
            if sendMessages[lastSelectedMessage - 1] ~= nil then
                data:DeleteChars(0, data.BufTextLen)
                data:InsertChars(0, u8(sendMessages[lastSelectedMessage - 1]))
                sampSetChatInputText(sendMessages[lastSelectedMessage - 1])
                lastSelectedMessage = lastSelectedMessage - 1
            end
        elseif data.EventKey == 4 then
            if sendMessages[lastSelectedMessage + 1] ~= nil then
                data:DeleteChars(0, data.BufTextLen)
                data:InsertChars(0, u8(sendMessages[lastSelectedMessage + 1]))
                sampSetChatInputText(sendMessages[lastSelectedMessage + 1])
                lastSelectedMessage = lastSelectedMessage + 1
            else
                data:DeleteChars(0, data.BufTextLen)
                data:InsertChars(0, '')
                sampSetChatInputText('')
                lastSelectedMessage = #sendMessages + 1
            end
        end
    elseif data.EventFlag == 64 then
        data:DeleteChars(0, data.BufTextLen)
        data:InsertChars(0, u8(sampGetChatInputText()))
    end
    return 0
end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1696504440654.png