Skip to content

Commit

Permalink
fix (mvDrawRect): Replaced four separate corner colors with a single …
Browse files Browse the repository at this point in the history
…parm that properly maps colors to corners #1996 (#2239)
  • Loading branch information
v-ein committed Dec 19, 2023
1 parent 4938318 commit 8b8d448
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dearpygui/dearpygui.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/mvAppItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3419,6 +3419,7 @@ DearPyGui::GetEntityParser(mvAppItemType type)
args.push_back({ mvPyDataType::Bool, "multicolor", mvArgType::KEYWORD_ARG, "False" });
args.push_back({ mvPyDataType::Float, "rounding", mvArgType::KEYWORD_ARG, "0.0", "Number of pixels of the radius that will round the corners of the rectangle. Note: doesn't work with multicolor" });
args.push_back({ mvPyDataType::Float, "thickness", mvArgType::KEYWORD_ARG, "1.0" });
args.push_back({ mvPyDataType::ListListInt, "corner_colors", mvArgType::KEYWORD_ARG, "[(255, 255, 255, 255), (255, 255, 255, 255), (255, 255, 255, 255), (255, 255, 255, 255)]", "Corner colors in a list, starting with upper-left and going clockwise: (upper-left, upper-right, bottom-right, bottom-left). 'multicolor' must be set to 'True'." });

setup.about = "Adds a rectangle.";
setup.category = { "Drawlist", "Widgets" };
Expand Down
35 changes: 35 additions & 0 deletions src/mvDrawings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,41 @@ void mvDrawRect::handleSpecificKeywordArgs(PyObject* dict)
if (PyObject* item = PyDict_GetItemString(dict, "rounding")) _rounding = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "thickness")) _thickness = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "multicolor")) _multicolor = ToBool(item);
if (PyObject* item = PyDict_GetItemString(dict, "corner_colors"))
{
if (item != Py_None)
{
if (PyTuple_Check(item))
{
if (PyTuple_Size(item) != 4)
mvThrowPythonError(mvErrorCode::mvNone, "The corner_colors parm on draw_rectangle must contain 4 colors.");
else
{
// Note: the variables are named incorrectly, e.g. _color_bottom_right
// actually controls upper-left corner. That's how old Python parms
// were named so we're keeping the names for a while until we drop the
// old parms altogether (if this ever happens).
// For now, we're just filling them in appropriate order.
_color_bottom_right = ToColor(PyTuple_GetItem(item, 0));
_color_bottom_left = ToColor(PyTuple_GetItem(item, 1));
_color_upper_left = ToColor(PyTuple_GetItem(item, 2));
_color_upper_right = ToColor(PyTuple_GetItem(item, 3));
}
}
else if (PyList_Check(item))
{
if (PyList_Size(item) != 4)
mvThrowPythonError(mvErrorCode::mvNone, "The corner_colors parm on draw_rectangle must contain 4 colors.");
else
{
_color_bottom_right = ToColor(PyList_GetItem(item, 0));
_color_bottom_left = ToColor(PyList_GetItem(item, 1));
_color_upper_left = ToColor(PyList_GetItem(item, 2));
_color_upper_right = ToColor(PyList_GetItem(item, 3));
}
}
}
}

if (_multicolor)
_rounding = 0.0f;
Expand Down

0 comments on commit 8b8d448

Please sign in to comment.