Skip to content

Commit

Permalink
feat (mvFont): added ImGui's PixelSnapH to font parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
v-ein authored Aug 30, 2023
1 parent e8bab91 commit 1fe2f6c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
10 changes: 6 additions & 4 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 @@ -4831,6 +4831,7 @@ DearPyGui::GetEntityParser(mvAppItemType type)

args.push_back({ mvPyDataType::String, "file" });
args.push_back({ mvPyDataType::Integer, "size" });
args.push_back({ mvPyDataType::Bool, "pixel_snapH", mvArgType::KEYWORD_ARG, "False", "Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font, or rendering text piece-by-piece (e.g. for coloring)." });
args.push_back({ mvPyDataType::UUID, "parent", mvArgType::KEYWORD_ARG, "internal_dpg.mvReservedUUID_0", "Parent to add this item to. (runtime adding)" });
args.push_back({ mvPyDataType::Bool, "default_font", mvArgType::DEPRECATED_REMOVE_KEYWORD_ARG });

Expand Down
13 changes: 12 additions & 1 deletion src/mvFontItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ void mvFont::customAction(void* data)

ImGuiIO& io = ImGui::GetIO();

ImFontConfig cfg;
cfg.PixelSnapH = _pixel_snap_h;
_fontPtr = io.Fonts->AddFontFromFileTTF(_file.c_str(), _size,
nullptr, _ranges.Data);
&cfg, _ranges.Data);

if (_fontPtr == nullptr)
{
Expand Down Expand Up @@ -178,13 +180,22 @@ void mvFont::handleSpecificRequiredArgs(PyObject* dict)

}

void mvFont::handleSpecificKeywordArgs(PyObject* dict)
{
if (dict == nullptr)
return;

if (PyObject* item = PyDict_GetItemString(dict, "pixel_snapH")) _pixel_snap_h = ToBool(item);
}

void mvFont::getSpecificConfiguration(PyObject* dict)
{
if (dict == nullptr)
return;

PyDict_SetItemString(dict, "file", ToPyString(_file));
PyDict_SetItemString(dict, "size", ToPyFloat(_size));
PyDict_SetItemString(dict, "pixel_snapH", ToPyBool(_pixel_snap_h));
}

void mvFontChars::handleSpecificRequiredArgs(PyObject* dict)
Expand Down
2 changes: 2 additions & 0 deletions src/mvFontItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class mvFont : public mvAppItem
void draw(ImDrawList* drawlist, float x, float y) override;
void customAction(void* data = nullptr) override;
void handleSpecificRequiredArgs(PyObject* dict) override;
void handleSpecificKeywordArgs(PyObject* dict) override;
void getSpecificConfiguration(PyObject* dict) override;
ImFont* getFontPtr() { return _fontPtr; }

Expand All @@ -60,6 +61,7 @@ class mvFont : public mvAppItem
std::string _file;
float _size = 13.0f;
bool _default = false;
bool _pixel_snap_h = false;

// finalized
ImFont* _fontPtr = nullptr;
Expand Down

0 comments on commit 1fe2f6c

Please sign in to comment.