Информация ImGui сниппеты и частые вопросы

LilGkey

Новичок
4
1
Нет я вообще про весь интерфейс, кнопки то понятно, мне нужно узнать как в одном Imgui окне сдлать слева допустим: Настройки, Биндер

Стандартный Имгуи Интерфейс не такой красивый как тот который на картинке, я бы хотел узнать как именно его сделать
 

Double Tap Inside

Известный
Автор темы
Проверенный
1,897
1,245
Нет я вообще про весь интерфейс, кнопки то понятно, мне нужно узнать как в одном Imgui окне сдлать слева допустим: Настройки, Биндер

Стандартный Имгуи Интерфейс не такой красивый как тот который на картинке, я бы хотел узнать как именно его сделать

вот тема этого скрипта, код открыт - развлекайся.
 
  • Нравится
Реакции: LilGkey

platinov

Новичок
14
0
где взять вот такие смайлики, фотографии, я не шарю что это, но мне понравилось и хочу добавить
1661931932962.png
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,747
11,157
где взять вот такие смайлики, фотографии, я не шарю что это, но мне понравилось и хочу добавить
Посмотреть вложение 166255
 

askfmaskfaosflas

Потрачен
1,089
512
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Работа со шрифтами [Скоро будет]
Lua:
lua_thread.create(function()
            wait(0)
            imgui.SwitchContext()
            imgui.GetIO().Fonts:Clear()
            glyph_ranges_cyrillic = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
            imgui.GetIO().Fonts:AddFontFromFileTTF(getWorkingDirectory() .. '\\resource\\fonts\\montserrat.ttf', 15.0, nil, glyph_ranges_cyrillic)
            imgui.RebuildFonts()
        end)
 

ewin

Известный
675
369
Добрый день, можно как то перемещать картинки или элементы в имгуи через ПКМ.
 
  • Нравится
Реакции: Moorell

MLycoris

Помидорный диетолог
Проверенный
1,768
1,787
Цветной imgui.Separator()

imgui.ColSeparator("HEX", прозрачность)

прозрачность от 1 до 99, если не вписана, то автоматом ставит 100
1681505550917.png


Lua:
function imgui.ColSeparator(hex,trans)
    local r,g,b = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
    if tonumber(trans) ~= nil and tonumber(trans) < 101 and tonumber(trans) > 0 then
        a = trans
    else a = 100 end
    imgui.PushStyleColor(imgui.Col.Separator, imgui.ImVec4(r/255, g/255, b/255, a/100))
    local colsep = imgui.Separator()
    imgui.PopStyleColor(1)
    return colsep
end
Lua:
local imgui = require 'mimgui'
local WinState = imgui.new.bool()

imgui.OnFrame(function() return WinState[0] end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(500,500), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(245, 498), imgui.Cond.Always)
        imgui.Begin('##Window', WinState, imgui.WindowFlags.NoResize)
        imgui.Separator()
        imgui.Text('Rainbow')
        imgui.ColSeparator("FF0000")
        imgui.ColSeparator("FFA500")
        imgui.ColSeparator("FFFF00")
        imgui.ColSeparator("008000")
        imgui.ColSeparator("0000FF")
        imgui.ColSeparator("4B0082")
        imgui.ColSeparator("EE82EE")
        for i = 1,99 do
            imgui.ColSeparator("FF0000",i)
        end
        imgui.End()
    end
)

function main()
    sampRegisterChatCommand('cmd', function() WinState[0] = not WinState[0] end)
    wait(-1)
end

function imgui.ColSeparator(hex,trans)
    local r,g,b = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
    if tonumber(trans) ~= nil and tonumber(trans) < 101 and tonumber(trans) > 0 then
        a = trans
    else a = 100 end
    imgui.PushStyleColor(imgui.Col.Separator, imgui.ImVec4(r/255, g/255, b/255, a/100))
    local colsep = imgui.Separator()
    imgui.PopStyleColor(1)
    return colsep
end
 

ewin

Известный
675
369
Цветной imgui.Text и imgui.Button

Использование:

imgui.TextHex(text, hex, ? opacity)
imgui.ButtonHex(text, imgui.ImVec2(x, y) hex, opacity, size)

Код:
function imgui.TextHex(text, hex, trans)
    imgui.PushStyleColor(imgui.Col.Text, imgui.ImVec4(tonumber(hex:sub(1, 2), 16) / 255, tonumber(hex:sub(5, 6), 16) / 255, tonumber(hex:sub(5, 6), 16) / 255, (tonumber(trans) ~= nil and tonumber(trans) < 101 and tonumber(trans) > 0 and tonumber(trans)) or 100 / 100))
    local colsep = imgui.Text(text)
    imgui.PopStyleColor(1)
    return colsep
end

function imgui.ButtonHex(label, size, hex, trans)
    local r,g,b,a = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)), (tonumber(trans) ~= nil and tonumber(trans) < 101 and tonumber(trans) > 0 and tonumber(trans)) or 100
    imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(r / 255, g / 255, b / 255, a / 60))
    imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(r / 255, g / 255, b / 255, a / 80))
    imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(r / 255, g / 255, b / 255, a / 100))
    local button = imgui.Button(lable, size)
    imgui.PopStyleColor(3)
    return button
end

Пример использования:
imgui.TextHex("gay", "a8329d")
imgui.ButtonHex("gay", imgui.ImVec2(100, 20), "a8329d")

upd: рофла ради, из-за сниппета выше
 
Последнее редактирование:
  • Эм
  • Нравится
Реакции: qdIbp, Cosmo и _raz0r

UBP

Известный
320
157
1710582878696.png

Lua:
local sliderValue = imgui.new.float(50)
CustomModernSlider("Мой слайдер", sliderValue, 0, 100)

Lua:
function CustomModernSlider(label, value, min, max)
    local ImVec2 = imgui.ImVec2
    local ImVec4 = imgui.ImVec4

    -- Начало новой строки и отображение метки
    imgui.Text(label)
    imgui.SameLine()

    local cursorPos = imgui.GetCursorScreenPos()
    local sliderLength = 200
    local sliderHeight = 4
    local knobRadius = 8
    local lineStart = ImVec2(cursorPos.x, cursorPos.y + knobRadius)
    local lineEnd = ImVec2(cursorPos.x + sliderLength, cursorPos.y + knobRadius)

    -- Рассчитываем позицию ползунка на основе текущего значения
    local fraction = (value[0] - min) / (max - min)
    local knobPos = ImVec2(cursorPos.x + fraction * sliderLength, cursorPos.y + knobRadius)

    local drawList = imgui.GetWindowDrawList()
    -- Рисуем линию слайдера
    drawList:AddLine(lineStart, lineEnd, imgui.ColorConvertFloat4ToU32(ImVec4(0.2, 0.2, 0.2, 1)), sliderHeight)
    -- Рисуем ползунок
    drawList:AddCircleFilled(knobPos, knobRadius, imgui.ColorConvertFloat4ToU32(ImVec4(1, 1, 1, 1)))

    -- Обработка ввода
    local mousePos = imgui.GetMousePos()
    local isHoveredOrDragged = mousePos.x >= lineStart.x and mousePos.x <= lineEnd.x and mousePos.y >= (lineStart.y - knobRadius) and mousePos.y <= (lineStart.y + knobRadius)
    local isActive = false

    if isHoveredOrDragged and imgui.IsMouseDown(0) then
        local newValue = min + ((mousePos.x - lineStart.x) / sliderLength) * (max - min)
        value[0] = math.min(math.max(newValue, min), max) -- Ограничиваем значение диапазоном
        isActive = true
    end

    -- Отображение текущего значения в подсказке при наведении или изменении
    if isHoveredOrDragged or isActive then
        imgui.SetTooltip(string.format("%s: %.2f", label, value[0]))
    end

    return isActive
end

1710583440768.png

Lua:
drawCircularProgressBar(window_center.x, window_center.y, 50, 45, 100, {0.4, 0.6, 0.9, 1})
Lua:
function drawCircularProgressBar(x, y, radius, percent, segments, color)
    local draw_list = imgui.GetWindowDrawList()
    local centre = imgui.ImVec2(x, y)
    local start_angle = -math.pi / 2
    local end_angle = start_angle + (2 * math.pi * percent / 100)
    local segment_count = segments

    -- Основной круг прогресс-бара
    draw_list:AddCircleFilled(centre, radius, imgui.ColorConvertFloat4ToU32(imgui.ImVec4(color[1], color[2], color[3], color[4] * 0.5)), segment_count)
    -- Заполненная часть прогресс-бара
    draw_list:PathArcTo(centre, radius - 1, start_angle, end_angle, segment_count)
    draw_list:PathStroke(imgui.ColorConvertFloat4ToU32(imgui.ImVec4(color[1], color[2], color[3], color[4])), false, 2.0)

    -- Текст в центре круга
    local text = string.format("%d%%", percent)
    local text_size = imgui.CalcTextSize(text)
    draw_list:AddText(imgui.ImVec2(centre.x - text_size.x / 2, centre.y - text_size.y / 2), imgui.ColorConvertFloat4ToU32(imgui.ImVec4(1, 1, 1, 1)), text)
end


1710589130195.png


Lua:
local isChecked = imgui.new.bool(false)

drawAnimatedCard( "Test checkbox", isChecked) -- Вызываем функцию рисования карточки


Lua:
-- Время начала и окончания наведения
hover_start_time = 0
hover_end_time = 0

-- Обновляем время начала и окончания наведения
function updateHoverTime(isHovered)
    local time = os.clock()
    if isHovered then
        if hover_start_time == 0 then
            hover_start_time = time
        end
        hover_end_time = 0
    else
        if hover_end_time == 0 then
            hover_end_time = time
        end
        hover_start_time = 0
    end
end

function drawAnimatedCard(text, isChecked)

    local draw_list = imgui.GetWindowDrawList()
    local cursor_pos = imgui.GetCursorScreenPos()
    local card_size = imgui.ImVec2(300, 50)
    local padding = 10
    local checkbox_size = 20
    local bubble_radius = 2.5
    local num_bubbles = 23
    local bg_color = imgui.ImVec4(0.1, 0.1, 0.1, 1)
    local hover_bg_color = imgui.ImVec4(0.2, 0.6, 1, 0)
    local isHovered = imgui.IsMouseHoveringRect(cursor_pos, imgui.ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y))
    local time = os.clock()

    -- Анимация появления и исчезновения фона
    local hover_anim_time = 0.5 -- Время анимации в секундах
    local hover_state = isHovered and math.min((time - hover_start_time) / hover_anim_time, 1) or math.max(1 - (time - hover_end_time) / hover_anim_time, 0)
    hover_bg_color.w = hover_state * 0.3 -- Плавное изменение альфа-канала фона

    -- Рисуем фон карточки
    local current_bg_color = isHovered and hover_bg_color or bg_color
    draw_list:AddRectFilled(cursor_pos, imgui.ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y), imgui.ColorConvertFloat4ToU32(current_bg_color), 5.0)

     -- Рисуем анимированные шарики, если курсор наведен
     if hover_state > 0 then
        local time_since_hover = os.clock() - hover_start_time
        for i = 1, num_bubbles do
            -- Уникальный угол для каждого шарика
            local angle = (i / num_bubbles) * 2 * math.pi*3
            -- Случайное расстояние от центра, зависящее от времени и индекса шарика
            local distance = math.sin(time_since_hover + i) * (card_size.x / 4 - bubble_radius)*2
            local bubble_x = cursor_pos.x + card_size.x / 2 + math.cos(angle) * distance
            local bubble_y = cursor_pos.y + card_size.y / 2 + math.sin(angle) * distance
            -- Ограничиваем шарики внутри карточки
            bubble_x = math.max(cursor_pos.x + bubble_radius, math.min(cursor_pos.x + card_size.x - bubble_radius, bubble_x))
            bubble_y = math.max(cursor_pos.y + bubble_radius, math.min(cursor_pos.y + card_size.y - bubble_radius, bubble_y))
            local bubble_color = imgui.ImVec4(1, 1, 1, hover_state * 0.5) -- Цвет шариков с плавным исчезновением
            draw_list:AddCircleFilled(imgui.ImVec2(bubble_x, bubble_y), bubble_radius, imgui.ColorConvertFloat4ToU32(bubble_color))
        end
    end

    -- Рисуем текст
    local text_pos = imgui.ImVec2(cursor_pos.x + padding, cursor_pos.y + card_size.y * 0.5 - imgui.CalcTextSize(text).y * 0.5)
    draw_list:AddText(text_pos, imgui.ColorConvertFloat4ToU32(imgui.ImVec4(1, 1, 1, 1)), text)
    imgui.AlignTextToFramePadding()
    -- Рисуем чекбокс
    local checkbox_pos = imgui.ImVec2(cursor_pos.x + card_size.x - checkbox_size - padding, cursor_pos.y + (card_size.y - checkbox_size) * 0.5)
    imgui.SetCursorScreenPos(checkbox_pos)
    imgui.Checkbox("##checkbox", isChecked)

    -- Сдвигаем курсор после рисования карточки
    imgui.SetCursorScreenPos(imgui.ImVec2(cursor_pos.x, cursor_pos.y + card_size.y + padding))
end


1710592476847.png


Lua:
drawCustomPanel("Справа", 'right', 400,50,15)
drawCustomPanel("Слева", 'left', 400,50,15)
drawCustomPanel("Сверху", 'top', 400,50,15)


Lua:
-- Функция для рисования панели с заголовком и синей полосой
function drawCustomPanel(title, side, sizeX, sizeY, stripe_width)
    local ImVec4 = imgui.ImVec4
    local draw_list = imgui.GetWindowDrawList()
    local cursor_pos = imgui.GetCursorScreenPos()
    local blue_stripe_width = stripe_width or 10
    local panel_color = ImVec4(1, 1, 1, 1) -- Цвет панели
    local blue_color = ImVec4(0, 0.478, 1, 1) -- Цвет синей полосы
    local rounding = 5.0 -- Радиус закругления углов

    -- Рисуем панель с закругленными углами
    draw_list:AddRectFilled(cursor_pos, imgui.ImVec2(cursor_pos.x + sizeX, cursor_pos.y + sizeY), imgui.ColorConvertFloat4ToU32(panel_color), rounding)

    -- Рисуем синюю полосу с закругленными углами в зависимости от выбранной стороны
    if side == "left" then
        draw_list:AddRectFilled(cursor_pos, imgui.ImVec2(cursor_pos.x + blue_stripe_width+1, cursor_pos.y + sizeY), imgui.ColorConvertFloat4ToU32(blue_color), rounding, 1 + 4)
    elseif side == "right" then
        local stripe_pos = imgui.ImVec2(cursor_pos.x + sizeX - blue_stripe_width, cursor_pos.y)
        draw_list:AddRectFilled(stripe_pos, imgui.ImVec2(stripe_pos.x + blue_stripe_width+1, stripe_pos.y + sizeY), imgui.ColorConvertFloat4ToU32(blue_color), rounding, 2 + 8)
    elseif side == "top" then
        draw_list:AddRectFilled(cursor_pos, imgui.ImVec2(cursor_pos.x + sizeX+1, cursor_pos.y + blue_stripe_width+2), imgui.ColorConvertFloat4ToU32(blue_color), rounding, 1 + 2)
    end

    -- Рисуем заголовок
    local text_size = imgui.CalcTextSize(title)
    imgui.PushFont(Font[20])
    local text_pos_y = cursor_pos.y + (sizeY * 0.5) - (text_size.y * 0.5)
    draw_list:AddText(imgui.ImVec2(cursor_pos.x + 20, text_pos_y), imgui.ColorConvertFloat4ToU32(ImVec4(0, 0, 0, 1)), title)
    imgui.PopFont()
end


Lua:
imgui.PushFont(Font[20])
-- code
imgui.PopFont()


Lua:
local Font = {}

imgui.OnInitialize(function()
    imgui.vAcsTheme()
    local defGlyph = imgui.GetIO().Fonts.ConfigData.Data[0].GlyphRanges
    local font_config = imgui.ImFontConfig()
    font_config.SizePixels = 14.0
    font_config.GlyphExtraSpacing.x = 0.1
    for Size = 10, 45 do
        Font[Size] = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/lib/trebucbd.ttf', Size, font_config, defGlyph)
    end
end) -- шрифт укажите свой
 
Последнее редактирование:

UBP

Известный
320
157
Как создать горячие клавиши imgui и сделать так чтобы они работали?
 

Бульдозер

Участник
11
0
данунахуй