Skip to content

Commit

Permalink
add button padding
Browse files Browse the repository at this point in the history
  • Loading branch information
tpecholt committed Jun 27, 2024
1 parent aad0cb3 commit 146aa6c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,8 @@ void Widget::Draw(UIContext& ctx)
ImGui::PushStyleColor(ImGuiCol_FrameBg, style_frameBg.eval(ctx));
if (!style_frameRounding.empty())
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, style_frameRounding);
if (!style_framePadding.empty())
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, style_framePadding);

ImGui::BeginDisabled((disabled.has_value() && disabled.value()) || (visible.has_value() && !visible.value()));
DoDraw(ctx);
Expand All @@ -1622,6 +1624,8 @@ void Widget::Draw(UIContext& ctx)
ImGui::PopStyleColor();
if (!style_frameRounding.empty())
ImGui::PopStyleVar();
if (!style_framePadding.empty())
ImGui::PopStyleVar();
if (style_font.has_value())
ImGui::PopFont();

Expand Down Expand Up @@ -1944,11 +1948,19 @@ void Widget::Export(std::ostream& os, UIContext& ctx)
{
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, " << style_frameRounding.to_arg(ctx.unit) << ");\n";
}
if (!style_framePadding.empty())
{
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, " << style_framePadding.to_arg(ctx.unit) << ");\n";
}

ctx.parents.push_back(this);
DoExport(os, ctx);
ctx.parents.pop_back();

if (!style_framePadding.empty())
{
os << ctx.ind << "ImGui::PopStyleVar();\n";
}
if (!style_frameRounding.empty())
{
os << ctx.ind << "ImGui::PopStyleVar();\n";
Expand Down Expand Up @@ -2198,6 +2210,8 @@ void Widget::Import(cpp::stmt_iterator& sit, UIContext& ctx)
{
if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_FrameRounding")
style_frameRounding.set_from_arg(sit->params[1]);
else if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_FramePadding")
style_framePadding.set_from_arg(sit->params[1]);
else
DoImport(sit, ctx);
}
Expand Down Expand Up @@ -3547,6 +3561,7 @@ Button::Properties()
{ "@style.text", &style_text },
{ "@style.button", &style_button },
{ "@style.hovered", &style_hovered },
{ "@style.padding", &style_framePadding },
{ "@style.rounding", &style_frameRounding },
{ "@style.font", &style_font },
{ "button.arrowDir", &arrowDir },
Expand Down Expand Up @@ -3591,20 +3606,26 @@ bool Button::PropertyUI(int i, UIContext& ctx)
changed |= BindingButton("hovered", &style_hovered, ctx);
break;
case 3:
ImGui::Text("padding");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##padding", &style_framePadding, ctx);
break;
case 4:
ImGui::Text("rounding");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##rounding", &style_frameRounding, ctx);
break;
case 4:
case 5:
ImGui::Text("font");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##font", &style_font, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("font", &style_font, ctx);
break;
case 5:
case 6:
{
ImGui::Text("arrowDir");
ImGui::TableNextColumn();
Expand All @@ -3621,7 +3642,7 @@ bool Button::PropertyUI(int i, UIContext& ctx)
}
break;
}
case 6:
case 7:
ImGui::BeginDisabled(arrowDir != ImGuiDir_None);
ImGui::Text("label");
ImGui::TableNextColumn();
Expand All @@ -3631,13 +3652,13 @@ bool Button::PropertyUI(int i, UIContext& ctx)
changed |= BindingButton("label", &label, ctx);
ImGui::EndDisabled();
break;
case 7:
case 8:
ImGui::Text("shortcut");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##shortcut", &shortcut, ctx);
break;
case 8:
case 9:
{
ImGui::BeginDisabled(ctx.kind != TopWindow::ModalPopup);
ImGui::Text("modalResult");
Expand All @@ -3659,7 +3680,7 @@ bool Button::PropertyUI(int i, UIContext& ctx)
ImGui::EndDisabled();
break;
}
case 9:
case 10:
ImGui::Text("dropDownMenu");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -3681,14 +3702,14 @@ bool Button::PropertyUI(int i, UIContext& ctx)
ImGui::EndCombo();
}
break;
case 10:
case 11:
ImGui::BeginDisabled(arrowDir != ImGuiDir_None);
ImGui::Text("small");
ImGui::TableNextColumn();
changed = InputDirectVal("##small", &small, ctx);
ImGui::EndDisabled();
break;
case 11:
case 12:
ImGui::BeginDisabled(small || arrowDir != ImGuiDir_None);
ImGui::Text("size_x");
ImGui::TableNextColumn();
Expand All @@ -3698,7 +3719,7 @@ bool Button::PropertyUI(int i, UIContext& ctx)
changed |= BindingButton("size_x", &size_x, ctx);
ImGui::EndDisabled();
break;
case 12:
case 13:
ImGui::BeginDisabled(small || arrowDir != ImGuiDir_None);
ImGui::Text("size_y");
ImGui::TableNextColumn();
Expand All @@ -3709,7 +3730,7 @@ bool Button::PropertyUI(int i, UIContext& ctx)
ImGui::EndDisabled();
break;
default:
return Widget::PropertyUI(i - 13, ctx);
return Widget::PropertyUI(i - 14, ctx);
}
return changed;
}
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct Widget : UINode
bindable<color32> style_text;
bindable<color32> style_frameBg;
direct_val<pzdimension> style_frameRounding;
direct_val<pzdimension2> style_framePadding;
direct_val<std::string> contextMenu = "";
event<> onItemClicked;
event<> onItemDoubleClicked;
Expand Down

0 comments on commit 146aa6c

Please sign in to comment.