egui API
unknown
lua
2 years ago
16 kB
28
Indexable
-- Easier Gui creation for REFramework
local egui = {}
egui:__index = egui
-- constructor
local function egui:new()
local self = setmatatable({}, egui)
return self
end
-- ENUM
local egui:ImguiDir = {
NONE = -1,
LEFT = 0,
RIGHT = 1,
UP = 2,
DOWN = 3
}
local egui:MouseButton = {
LEFT = 0,
RIGHT = 1,
MIDDLE = 2
}
local egui:ImGuiWindowFlags = {
NONE = 0,
NO_TITLE_BAR = 1,
NO_RESIZE = 2,
NO_MOVE = 4,
NO_SCROLLBAR = 8,
NO_SCROLL_WITH_MOUSE = 16,
NO_COLLAPSE = 32,
ALWAYS_AUTO_RESIZE = 64,
NO_BACKGROUND = 128,
NO_SAVED_SETTINGS = 256,
NO_MOUSE_INPUTS = 512,
MENU_BAR = 1024,
HORIZONTAL_SCROLLBAR = 2048,
NO_FOCUS_ON_APPEARING = 4096,
NO_BRING_TO_FRONT_ON_FOCUS = 8192,
ALWAYS_VERTICAL_SCROLLBAR = 16384,
ALWAYS_HORIZONTAL_SCROLLBAR = 32768,
ALWAYS_USE_WINDOW_PADDING = 65536,
NO_NAV_INPUT = 262144,
NO_NAV_FOCUS = 524288,
UNSAVED_DOCUMENT = 1048576,
NO_NAV = 786432,
NO_DECORATION = 43,
NO_INPUTS = 786944,
NAV_FLATTENED = 8388608,
CHILD_WINDOW = 16777216,
TOOL_TIP = 33554432,
POPUP = 67108864,
MODAL = 134217728,
CHILD_MENU = 268435456
}
----------------------------------------------
-- Functions
----------------------------------------------
local function egui:isDD2()
if reframework:get_game_name() == "DD2" then
return true
end
end
local function egui:GetGameName()
return reframework:get_game_name()
end
local function egui:LoadConfigFile(configFile)
return json.load_file(configFile)
end
local function egui:SaveConfigFile(configFile, contents)
json.dump_file(configFile, content)
end
local function egui:SetNextWidth(width)
imgui.push_next_item_width(width)
end
local function egui:SetWidth(width)
imgui.push_item_width(width)
end
local function egui:PopWidth()
imgui.pop_item_width()
end
local function egui:Indent(width)
imgui.indent(width)
end
local function egui:Unindent(width)
imgui.unindent(width)
end
local function egui:SetTooltip(text, biggerBox)
imgui.begin_tooltip()
if biggerBox then
Text("\n\t"..text.."\t\n")
else
Text(text)
end
imgui.end_tooltip()
end
local function egui:SetTooltipColored(text, color, biggerBox)
imgui.begin_tooltip()
if biggerBox then
TextColored("\n\t"..text.."\t\n", color)
else
TextColored(text, color)
end
imgui.end_tooltip()
end
local function egui:CalcTextSize(text, returnType)
-- Return Type
--0 = standard (both)
--1 = width
--2 = height
if returnType == 0 then
return imgui.calc_text_size()
elseif returnType == 1 then
return imgui.calc_text_size().x
elseif returnType == 2 then
return imgui.calc_text_size().y
end
end
local function egui:GetItemWidth(item)
return item.calc_item_width()
end
local function egui:GetWindowSize(returnType)
-- Return Type
--0 = standard (both)
--1 = width
--2 = height
if returnType == 0 then
return imgui.get_window_size()
elseif returnType == 1 then
return imgui.get_window_size().x
elseif returnType == 2 then
return imgui.get_window_size().y
end
end
local function egui:SameLine()
imgui.same_line()
end
local function egui:NewLine()
imgui.new_line()
end
local function egui:Separator()
imgui.separator()
end
local function egui:TranslateHotkey(keyID)
-- Function to translate the integer values of keycodes to the actual key name
local keycodes = {
[8] = "Backspace",
[9] = "Tab",
[13] = "Enter",
[16] = "Shift",
[17] = "Control",
[18] = "Alt",
[19] = "Pause",
[20] = "Caps Lock",
[27] = "Escape",
[32] = "Space",
[33] = "Page Up",
[34] = "Page Down",
[35] = "End",
[36] = "Home",
[37] = "Left Arrow",
[38] = "Up Arrow",
[39] = "Right Arrow",
[40] = "Down Arrow",
[44] = "Print Screen",
[45] = "Insert",
[46] = "Delete",
[48] = "0",
[49] = "1",
[50] = "2",
[51] = "3",
[52] = "4",
[53] = "5",
[54] = "6",
[55] = "7",
[56] = "8",
[57] = "9",
[65] = "A",
[66] = "B",
[67] = "C",
[68] = "D",
[69] = "E",
[70] = "F",
[71] = "G",
[72] = "H",
[73] = "I",
[74] = "J",
[75] = "K",
[76] = "L",
[77] = "M",
[78] = "N",
[79] = "O",
[80] = "P",
[81] = "Q",
[82] = "R",
[83] = "S",
[84] = "T",
[85] = "U",
[86] = "V",
[87] = "W",
[88] = "X",
[89] = "Y",
[90] = "Z",
[91] = "Left Windows",
[92] = "Right Windows",
[93] = "Select",
[96] = "Numpad 0",
[97] = "Numpad 1",
[98] = "Numpad 2",
[99] = "Numpad 3",
[100] = "Numpad 4",
[101] = "Numpad 5",
[102] = "Numpad 6",
[103] = "Numpad 7",
[104] = "Numpad 8",
[105] = "Numpad 9",
[106] = "Multiply",
[107] = "Add",
[109] = "Subtract",
[110] = "Decimal",
[111] = "Divide",
[112] = "F1",
[113] = "F2",
[114] = "F3",
[115] = "F4",
[116] = "F5",
[117] = "F6",
[118] = "F7",
[119] = "F8",
[120] = "F9",
[121] = "F10",
[122] = "F11",
[123] = "F12",
[144] = "Num Lock"
}
return keycodes[keyID]
end
-- vectors
local function egui:Vec2(x, y)
return Vector2f.new(x, y)
end
local function egui:Vec3(x, y, z)
return Vector3f.new(x, y, z)
end
local function egui:Vec4(x, y, z, w)
return Vector4f.new(x, y, z, w)
end
-----------------------------------------------
-- Widgets
-----------------------------------------------
-- Custom Widgets
local function egui:SectionHeader(text)
Text(text)
end
-- Text
local function egui:Text(text)
imgui.text(text)
end
local function egui:TextColored(text, color)
imgui.text_colored(text, color)
end
-- Buttons
local function egui:Button(text, size, func)
if imgui.button(text) then
func()
end
end
local function egui:SmallButton(text, func)
if imgui.small_button(text) then
func()
end
end
local function egui:InvisButton(id, size, flags, func)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
if imgui.invisible_button(id, size, flags) then
func()
end
end
local function egui:ArrowButton(id, ImguiDir, func)
if imgui.arrow_button(id, ImguiDir) then
func()
end
end
local function egui:Checkbox(varUpdate, prefixLabel ,value, label)
-- Sets checkbox label to empty if prefixLabel is true, othewise sets the label text
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.checkbox(labelToUse, value)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
-- Sliders and Drag
local function egui:DragFloat(varUpdate, prefixLabel, value, label, speed, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.drag_float(label, value, speed, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:DragFloat2(varUpdate, prefixLabel, value, label, speed, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.drag_float2(label, value, speed, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:DragFloat3(varUpdate, prefixLabel, value, label, speed, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.drag_float3(label, value, speed, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:DragFloat4(varUpdate, prefixLabel, value, label, speed, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.drag_float4(label, value, speed, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:DragInt(varUpdate, prefixLabel, value, label, speed, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.drag_int(label, value, speed, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:SliderFloat(varUpdate, prefixLabel, value, label, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.slider_float(label, value, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:SliderInt(varUpdate, prefixLabel, value, label, min, max, displayFormat)
displayFormat = displayFormat or nil
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.slider_int(label, value, min, max, displayFormat)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
-- Inputs
local function egui:InputText(varUpdate, prefixLabel, value, label, text, size, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.input_text(labelToUse, text, size)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:InputTextMultiline(varUpdate, value, label, text, size, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local changed, newValue = imgui.input_text_multiline(label, text, size, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
-- Combo Box
local function egui:ComboBox(varUpdate, prefixLabel, label, selection, values)
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.combo(labelToUse, selection, values)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
-- Color Picker
local function egui:ColorPicker(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_picker(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorPickerARGB(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_picker_argb(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorPicker3 (varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_picker3(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorPicker4(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_picker4(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorEdit(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_edit(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorEditARGB(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_edit_argb(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorEdit3(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_edit3(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
end
local function egui:ColorEdit4(varUpdate, prefixLabel, label, color, flags)
if flags == nil then
flags = ImGuiWindowFlags.NONE
end
local labelToUse = prefixLabel and "" or label
if prefixLabel then
Text(label)
SameLine()
end
local changed, newValue = imgui.color_edit4(labelToUse, color, flags)
if changed and newValue ~= value then
value = newValue
varUpdate = true
end
endEditor is loading...
Leave a Comment