Skip to content

Commit

Permalink
Added imgui.color_edit4
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Feb 3, 2025
1 parent 174f923 commit c1c6930
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,33 @@
"summary": "SliderFloat",
"usage": null
},
{
"description": "",
"has_params": true,
"has_returns": false,
"name": "color_edit4",
"params": [
{
"description": "",
"name": "label",
"type": "string"
},
{
"description": "",
"name": "color",
"type": "vec4"
},
{
"description": "",
"name": "flags",
"type": "number"
}
],
"params_string": "label,color,flags",
"returns": [],
"summary": "ColorEdit4",
"usage": null
},
{
"description": "",
"has_params": false,
Expand Down
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,16 @@ RETURNS
* `value` [`number`] -


### color_edit4(label,color,flags)
ColorEdit4


PARAMS
* `label` [`string`] -
* `color` [`vec4`] -
* `flags` [`number`] -


### selectable()
Selectable

Expand Down
5 changes: 5 additions & 0 deletions example/tab2.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local JEDI = { "Luke", "Obi-Wan", "Yoda" }
local SITH = { "Maul", "Vader", "Palpatine" }

local COLOR = vmath.vector4()

return function(self)
local selected = imgui.tree_node("root")
if selected then
Expand Down Expand Up @@ -72,4 +74,7 @@ return function(self)
pprint("second same button")
end
imgui.pop_id()

self.color = self.color or vmath.vector4()
imgui.color_edit4("coloredit4", self.color)
end
14 changes: 14 additions & 0 deletions imgui/api/imgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,20 @@
type: number


- name: color_edit4
type: function
desc: ColorEdit4
parameters:
- name: label
type: string

- name: color
type: vec4

- name: flags
type: number


- name: selectable
type: function
desc: Selectable
Expand Down
57 changes: 57 additions & 0 deletions imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,35 @@ static int imgui_SliderFloat(lua_State* L)
}


/** ColorEdit4
* @name color_edit4
* @string label
* @vec4 color
* @number flags
*/
static int imgui_ColorEdit4(lua_State* L)
{
imgui_NewFrame();
const char* label = luaL_checkstring(L, 1);
dmVMath::Vector4* color = dmScript::CheckVector4(L, 2);
uint32_t flags = 0x0;
if (lua_isnumber(L, 3))
{
flags = luaL_checknumber(L, 3);
}

static ImVec4 c(color->getX(), color->getY(), color->getZ(), color->getW());
ImGui::ColorEdit4(label, (float*)&c, flags);
color->setX(c.x);
color->setY(c.y);
color->setZ(c.z);
color->setW(c.w);
return 0;
}




/** Selectable
* @name selectable
*/
Expand Down Expand Up @@ -3264,6 +3293,8 @@ static const luaL_reg Module_methods[] =
{"push_id", imgui_PushId},
{"pop_id", imgui_PopId},

{"color_edit4", imgui_ColorEdit4},

{"selectable", imgui_Selectable},
{"text", imgui_Text},
{"text_colored", imgui_TextColored},
Expand Down Expand Up @@ -3629,6 +3660,32 @@ static void LuaInit(lua_State* L)
lua_setfieldstringint(L, "INPUTFLAGS_CALLBACKEDIT", ImGuiInputTextFlags_CallbackEdit); // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)
lua_setfieldstringint(L, "INPUTFLAGS_ESCAPECLEARSALL", ImGuiInputTextFlags_EscapeClearsAll); // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)

lua_setfieldstringint(L, "COLOREDITFLAGS_NONE", ImGuiColorEditFlags_None);
lua_setfieldstringint(L, "COLOREDITFLAGS_NOALPHA", ImGuiColorEditFlags_NoAlpha); // // ColorEdit, ColorPicker, ColorButton: ignore Alpha component (will only read 3 components from the input pointer).
lua_setfieldstringint(L, "COLOREDITFLAGS_NOPICKER", ImGuiColorEditFlags_NoPicker); // // ColorEdit: disable picker when clicking on color square.
lua_setfieldstringint(L, "COLOREDITFLAGS_NOOPTIONS", ImGuiColorEditFlags_NoOptions); // // ColorEdit: disable toggling options menu when right-clicking on inputs/small preview.
lua_setfieldstringint(L, "COLOREDITFLAGS_NOSMALLPREVIEW", ImGuiColorEditFlags_NoSmallPreview); // // ColorEdit, ColorPicker: disable color square preview next to the inputs. (e.g. to show only the inputs)
lua_setfieldstringint(L, "COLOREDITFLAGS_NOINPUTS", ImGuiColorEditFlags_NoInputs); // // ColorEdit, ColorPicker: disable inputs sliders/text widgets (e.g. to show only the small preview color square).
lua_setfieldstringint(L, "COLOREDITFLAGS_NOTOOLTIP", ImGuiColorEditFlags_NoTooltip); // // ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview.
lua_setfieldstringint(L, "COLOREDITFLAGS_NOLABEL", ImGuiColorEditFlags_NoLabel); // // ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker).
lua_setfieldstringint(L, "COLOREDITFLAGS_NOSIDEPREVIEW", ImGuiColorEditFlags_NoSidePreview); // // ColorPicker: disable bigger color preview on right side of the picker, use small color square preview instead.
lua_setfieldstringint(L, "COLOREDITFLAGS_NODRAGDROP", ImGuiColorEditFlags_NoDragDrop); // // ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source.
lua_setfieldstringint(L, "COLOREDITFLAGS_NOBORDER", ImGuiColorEditFlags_NoBorder); // // ColorButton: disable border (which is enforced by default)
lua_setfieldstringint(L, "COLOREDITFLAGS_ALPHABAR", ImGuiColorEditFlags_AlphaBar); // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker.
lua_setfieldstringint(L, "COLOREDITFLAGS_ALPHAPREVIEW", ImGuiColorEditFlags_AlphaPreview); // // ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque.
lua_setfieldstringint(L, "COLOREDITFLAGS_ALPHAPREVIEWHALF", ImGuiColorEditFlags_AlphaPreviewHalf); // // ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque.
lua_setfieldstringint(L, "COLOREDITFLAGS_HDR", ImGuiColorEditFlags_HDR); // // (WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well).
lua_setfieldstringint(L, "COLOREDITFLAGS_DISPLAYRGB", ImGuiColorEditFlags_DisplayRGB); // [Display] // ColorEdit: override _display_ type among RGB/HSV/Hex. ColorPicker: select any combination using one or more of RGB/HSV/Hex.
lua_setfieldstringint(L, "COLOREDITFLAGS_DISPLAYHSV", ImGuiColorEditFlags_DisplayHSV); // [Display] // "
lua_setfieldstringint(L, "COLOREDITFLAGS_DISPLAYHEX", ImGuiColorEditFlags_DisplayHex); // [Display] // "
lua_setfieldstringint(L, "COLOREDITFLAGS_UINT8", ImGuiColorEditFlags_Uint8); // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.
lua_setfieldstringint(L, "COLOREDITFLAGS_FLOAT", ImGuiColorEditFlags_Float); // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers.
lua_setfieldstringint(L, "COLOREDITFLAGS_PICKERHUEBAR", ImGuiColorEditFlags_PickerHueBar); // [Picker] // ColorPicker: bar for Hue, rectangle for Sat/Value.
lua_setfieldstringint(L, "COLOREDITFLAGS_PICKERHUEWHEEL", ImGuiColorEditFlags_PickerHueWheel); // [Picker] // ColorPicker: wheel for Hue, triangle for Sat/Value.
lua_setfieldstringint(L, "COLOREDITFLAGS_INPUTRGB", ImGuiColorEditFlags_InputRGB); // [Input] // ColorEdit, ColorPicker: input and output data in RGB format.
lua_setfieldstringint(L, "COLOREDITFLAGS_INPUTHSV", ImGuiColorEditFlags_InputHSV); // [Input] // ColorEdit, ColorPicker: input and output data in HSV format.


lua_setfieldstringint(L, "COND_NONE", ImGuiCond_None); // No condition (always set the variable), same as _Always
lua_setfieldstringint(L, "COND_ALWAYS", ImGuiCond_Always); // No condition (always set the variable)
lua_setfieldstringint(L, "COND_ONCE", ImGuiCond_Once); // Set the variable once per runtime session (only the first call will succeed)
Expand Down

0 comments on commit c1c6930

Please sign in to comment.