Как сделать вкладки? на imgui

KOHTOP

Участник
Автор темы
138
17
Версия MoonLoader
.027.0-preview
Как сделать вкладки? Допустим на стартовой вкладке там у меня будут кнопки и т.д
На второй вкладке чекбоксы, а на третьей комбобоксы
 

MLycoris

Режим чтения
Проверенный
1,810
1,856
Тут шаблон 3.5 с 13 по 20 какую-то строку
 
  • Нравится
Реакции: riverya4life и YarikVL

KOHTOP

Участник
Автор темы
138
17
Тут шаблон 3.5 с 13 по 20 какую-то строку
И как мне добавить вкладку в этот код? Скрипт не запускается при добавление вкладки


script:
function imgui.OnDrawFrame()

    if not main_window_state.v and not profile_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
        imgui.Begin(fa.ICON_USER .. " Profile " .. fa.ICON_USER, main_window_state)
        imgui.Text(u8'Arizona Helper ' .. fa.ICON_BOLT)


        if imgui.BeginChild('##545', imgui.ImVec2(110, 200), true) then
        if imgui.Button(fa.ICON_HOME .. ' Home', imgui.ImVec2(100,25)) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        if imgui.Button(fa.ICON_USER ..' Profile', imgui.ImVec2(100, 25)) then
            profile_window_state.v = not profile_window_state.v
            imgui.Process = profile_window_state.v
        end
        if imgui.Button(fa.ICON_KEYBOARD_O ..' KeyBinding', imgui.ImVec2(100, 25), botton_0) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        if imgui.Button(fa.ICON_SLIDERS ..' Settings', imgui.ImVec2(100, 25), button_1) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        if imgui.Button(fa.ICON_USER_PLUS ..' Author', imgui.ImVec2(100, 25), button_2) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        imgui.EndChild()
        end
        
        
    
        imgui.End()

    end
 

MLycoris

Режим чтения
Проверенный
1,810
1,856
И как мне добавить вкладку в этот код? Скрипт не запускается при добавление вкладки


script:
function imgui.OnDrawFrame()

    if not main_window_state.v and not profile_window_state.v then
        imgui.Process = false
    end

    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(500, 300), imgui.Cond.FirstUseEver)
        imgui.Begin(fa.ICON_USER .. " Profile " .. fa.ICON_USER, main_window_state)
        imgui.Text(u8'Arizona Helper ' .. fa.ICON_BOLT)


        if imgui.BeginChild('##545', imgui.ImVec2(110, 200), true) then
        if imgui.Button(fa.ICON_HOME .. ' Home', imgui.ImVec2(100,25)) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        if imgui.Button(fa.ICON_USER ..' Profile', imgui.ImVec2(100, 25)) then
            profile_window_state.v = not profile_window_state.v
            imgui.Process = profile_window_state.v
        end
        if imgui.Button(fa.ICON_KEYBOARD_O ..' KeyBinding', imgui.ImVec2(100, 25), botton_0) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        if imgui.Button(fa.ICON_SLIDERS ..' Settings', imgui.ImVec2(100, 25), button_1) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        if imgui.Button(fa.ICON_USER_PLUS ..' Author', imgui.ImVec2(100, 25), button_2) then
            sampAddChatMessage(tag .. 'Успешно!', -1)
        end
        imgui.EndChild()
        end
       
       
   
        imgui.End()

    end
А, у тебя имгуи, тогда не смогу помочь
 

why ega

РП игрок
Модератор
2,539
2,231
Как сделать вкладки? Допустим на стартовой вкладке там у меня будут кнопки и т.д
На второй вкладке чекбоксы, а на третьей комбобоксы
Можно бахнуть так, хз на сколько это поддрирживаемо, т.к. накидал на коленке
Код:
local pages = {
    elements = {
        "1 вкадка",
        "2 вкладка" -- список вкладок
    },
    render = {
        function()
            imgui.Text("Это первая вкладка")
        end,
        function()
            imgui.Text("Это вторая вкладка")
            imgui.Button("В ней есть кнопка")
        end -- содержимое вкладок
    }
}

local page = 1


if imgui.Begin("My Window") then
    imgui.BeginGroup()
        for i, element in pairs(pages.elements) do -- перебираем таблицу с названиями вкладок и отрисовываем кнопку под каждую из них
            if imgui.Button(element) then
                page = i -- если нажали на кнопку, переключаем вкладку
            end
        end
    imgui.EndGroup()
    imgui.SameLine()
    pages.render[page]() -- вызываем функцию отрисовки содержимого
    imgui.End()
end
 
  • Нравится
Реакции: riverya4life и MLycoris

schtolz

Известный
111
66
Lua:
require "lib.moonloader"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)


local menu = {true, -- первая вкладка будет активная, когда откроешь окно
    false,
    false,
    
}

function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand('test', function()
      main_window_state.v = not main_window_state.v
      imgui.Process = main_window_state.v
end)

while true do
  wait(0)
 
end
end



function imgui.OnDrawFrame()
    local resX, resY = getScreenResolution()
    if main_window_state.v then
        imgui.ShowCursor = true
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(435, 200), imgui.Cond.FirstUseEver)   
        imgui.Begin(u8"Тест", imgui.WindowFlags.NoCollapse, imgui.WindowFlags.NoResize)
        if imgui.Button(u8"Первая вкладка", imgui.ImVec2(135, 30)) then uu() menu[1] = true end imgui.SameLine()
        if imgui.Button(u8'Вторая вкладка', imgui.ImVec2(135, 30)) then uu() menu[2] = true end imgui.SameLine()
        if imgui.Button(u8'Третья вкладка', imgui.ImVec2(135, 30)) then uu() menu[3] = true end -- если вкладка последняя, тогда не нужно вставлять imgui.SameLine()
        imgui.Separator()
        imgui.NewLine()
        imgui.SameLine(3)
        if menu[1] then
        imgui.Text(u8"Ты нажал на первую вкладку")
        end
        if menu[2] then
        imgui.Text(u8"Ты нажал на вторую вкладку")
        end
        if menu [3] then
        imgui.Text(u8"Ты нажал на третью вкладку")
        end
        imgui.End()
end
end


function uu()
    for i = 0,3 do
        menu[i] = false
    end
end
 

wojciech?

Известный
206
120
Lua:
-- где-то в начале кода
local currentPage = 1

-- в onDrawFrame()
for index = 1, 3--[[количество вкладок]] do
    if imgui.Button(string.format("Page: %s", index)) then
        currentPage = index
    end
end

if currentPage == 1 then
    -- если открыта первая вкладка
elseif currentPage == 2 then
    -- если вторая
elseif currentPage == 3 then
    -- да, это если открыта третья вкладка
end