imgui flags

IlyaHL2

Активный
Автор темы
210
53
Версия MoonLoader
.026-beta
Решил попробовать воспользоваться флагами без ветвления
С ветвлением:
            if not zag and not freezepos and not autosize then  -- 0
                imgui.Begin(u8'Окно', window)

            elseif not zag and not freezepos and autosize then  -- авто-размер
                imgui.Begin(u8'Окно', window, imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize )

            elseif not zag and freezepos and not autosize then  -- заморозка поз
                imgui.Begin(u8'Окно', window, imgui.WindowFlags.NoMove)

Но выдает ошибку т.к один из флагов имеет значение false
Без ветвлением:
local imgui = require 'imgui'
local key = require 'vkeys'

local main_window_state = imgui.ImBool(false)
local nobar = imgui.WindowFlags.NoTitleBar
local free = imgui.WindowFlags.NoMove
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.Begin('My window', main_window_state, nobar+free)
            imgui.Text('Hello world')
        imgui.End()
    end
end

function main()
    while true do wait(0)
        if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v print(main_window_state.v) end
        if wasKeyPressed(key.VK_L) then nobar = not nobar print('выкл бар',nobar) end
        if wasKeyPressed(key.VK_O) then free = not free print('заморозк',free) end
        imgui.Process = main_window_state.v
    end
end
 
  • Нравится
Реакции: Andrinall
Решение
Решил попробовать воспользоваться флагами без ветвления
С ветвлением:
            if not zag and not freezepos and not autosize then  -- 0
                imgui.Begin(u8'Окно', window)

            elseif not zag and not freezepos and autosize then  -- авто-размер
                imgui.Begin(u8'Окно', window, imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize )

            elseif not zag and freezepos and not autosize then  -- заморозка поз
                imgui.Begin(u8'Окно', window, imgui.WindowFlags.NoMove)

Но выдает ошибку т.к один из флагов имеет значение false
Без ветвлением:
local imgui = require 'imgui'
local key = require 'vkeys'

local main_window_state = imgui.ImBool(false)
local nobar = imgui.WindowFlags.NoTitleBar
local free...

Andrinall

Известный
681
532
Решил попробовать воспользоваться флагами без ветвления
С ветвлением:
            if not zag and not freezepos and not autosize then  -- 0
                imgui.Begin(u8'Окно', window)

            elseif not zag and not freezepos and autosize then  -- авто-размер
                imgui.Begin(u8'Окно', window, imgui.WindowFlags.NoResize + imgui.WindowFlags.AlwaysAutoResize )

            elseif not zag and freezepos and not autosize then  -- заморозка поз
                imgui.Begin(u8'Окно', window, imgui.WindowFlags.NoMove)

Но выдает ошибку т.к один из флагов имеет значение false
Без ветвлением:
local imgui = require 'imgui'
local key = require 'vkeys'

local main_window_state = imgui.ImBool(false)
local nobar = imgui.WindowFlags.NoTitleBar
local free = imgui.WindowFlags.NoMove
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.Begin('My window', main_window_state, nobar+free)
            imgui.Text('Hello world')
        imgui.End()
    end
end

function main()
    while true do wait(0)
        if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v print(main_window_state.v) end
        if wasKeyPressed(key.VK_L) then nobar = not nobar print('выкл бар',nobar) end
        if wasKeyPressed(key.VK_O) then free = not free print('заморозк',free) end
        imgui.Process = main_window_state.v
    end
end
Lua:
local imgui = require 'imgui'
local key = require 'vkeys'

local main_window_state = imgui.ImBool(false)
local nobar, free = false, false

function imgui.OnDrawFrame()
    if main_window_state.v then
        local flags = ((nobar and imgui.WindowFlags.NoTitleBar or 0) + (free and imgui.WindowFlags.NoMove or 0))
        -- вместо объявления переменной можно это сунуть прямо в imgui.Begin, но тогда будет ещё хуже смотреться :)
        imgui.Begin('My window', main_window_state, flags)
            imgui.Text('Hello world')
        imgui.End()
    end
end
function main()
    while true do wait(0)
        if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v print(main_window_state.v) end
        if wasKeyPressed(key.VK_L) then nobar = not nobar print('выкл бар',nobar) end
        if wasKeyPressed(key.VK_O) then free = not free print('заморозк',free) end
        imgui.Process = main_window_state.v
    end
end
Как-то так. Конечно не проверял, но в теории всё должно работать.

UPD: Про тернарные выражения можешь посмотреть тут, например:
 
Последнее редактирование:
  • Нравится
Реакции: IlyaHL2

IlyaHL2

Активный
Автор темы
210
53
Lua:
local imgui = require 'imgui'
local key = require 'vkeys'

local main_window_state = imgui.ImBool(false)
local nobar, free = false, false

function imgui.OnDrawFrame()
    if main_window_state.v then
        local flags = ((nobar and imgui.WindowFlags.NoTitleBar or 0) + (free and imgui.WindowFlags.NoMove or 0))
        -- вместо объявления переменной можно это сунуть прямо в imgui.Begin, но тогда будет ещё хуже смотреться :)
        imgui.Begin('My window', main_window_state, flags)
            imgui.Text('Hello world')
        imgui.End()
    end
end
function main()
    while true do wait(0)
        if wasKeyPressed(key.VK_X) then main_window_state.v = not main_window_state.v print(main_window_state.v) end
        if wasKeyPressed(key.VK_L) then nobar = not nobar print('выкл бар',nobar) end
        if wasKeyPressed(key.VK_O) then free = not free print('заморозк',free) end
        imgui.Process = main_window_state.v
    end
end
Как-то так. Конечно не проверял, но в теории всё должно работать.

UPD: Про тернарные выражения можешь посмотреть тут, например:
Вот колдун ...
 
  • Ха-ха
Реакции: Andrinall