Skip to content

Commit

Permalink
add style_rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
tope99 committed Nov 16, 2023
1 parent bcafc78 commit f91e8af
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 28 deletions.
16 changes: 11 additions & 5 deletions doc/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ void Test::Draw()
/// @style Dark
/// @unit dp
/// @begin TopWindow
const float dp = ((ImRad::IOUserData*)ImGui::GetIO().UserData)->dpiScale;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 7*dp, 10*dp });
auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;
const float dp = ioUserData->dpiScale;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 7*dp, 10*dp });
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::SetNextWindowPos(ioUserData->displayRectMinOffset);
ImGui::SetNextWindowSize({ ImGui::GetIO().DisplaySize.x - ioUserData->displayRectMinOffset.x - ioUserData->displayRectMaxOffset.x,
ImGui::GetIO().DisplaySize.y - ioUserData->displayRectMinOffset.y - ioUserData->displayRectMaxOffset.y }); //{ 420*dp, 640*dp }
ImGui::SetNextWindowSize({ ImGui::GetMainViewport()->Size.x - ioUserData->displayRectMinOffset.x - ioUserData->displayRectMaxOffset.x,
ImGui::GetMainViewport()->Size.y - ioUserData->displayRectMinOffset.y - ioUserData->displayRectMaxOffset.y }); //{ 320*dp, 500*dp }
bool tmpOpen;
if (ImGui::Begin("###Test", &tmpOpen, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings))
if (ImGui::Begin("###Test", &tmpOpen, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings))
{
/// @separator

Expand All @@ -32,6 +32,8 @@ void Test::Draw()
/// @begin Input
ImGui::SetNextItemWidth(-1);
ImGui::InputText("##value1", &value1, ImGuiInputTextFlags_None);
if (ImGui::IsItemActive())
ioUserData->imeType = ImRad::ImeText;
/// @end Input

/// @begin Text
Expand All @@ -50,7 +52,10 @@ void Test::Draw()
/// @end Text

/// @begin Input
ImGui::SetNextItemAllowOverlap();
ImGui::InputTextMultiline("##value5", &value5, { -1, -110*dp }, ImGuiInputTextFlags_Multiline);
if (ImGui::IsItemActive())
ioUserData->imeType = ImRad::ImeText;
/// @end Input

/// @begin CheckBox
Expand All @@ -70,6 +75,7 @@ void Test::Draw()
}
ImGui::PopStyleVar();
ImGui::PopStyleVar();
ImGui::PopStyleVar();
/// @end TopWindow
}

1 change: 1 addition & 0 deletions doc/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Test
int value3 = -1;
std::string value5;
bool value7 = false;
std::string value8;
/// @end interface

private:
Expand Down
93 changes: 70 additions & 23 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ TopWindow::TopWindow(UIContext& ctx)
placement.add$(Top);
placement.add$(Bottom);
placement.add$(Center);

style_border = ctx.style.WindowBorderSize;
style_rounding = ctx.style.WindowRounding;
}

void TopWindow::Draw(UIContext& ctx)
Expand Down Expand Up @@ -455,7 +458,9 @@ void TopWindow::Draw(UIContext& ctx)
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style_spacing.eval_px(ctx));
if (style_border*1.f != ctx.style.WindowBorderSize)
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, style_border);

if (style_rounding.eval_px(ctx) != ctx.style.WindowRounding)
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, style_rounding);

ImGui::SetNextWindowPos(ctx.wpos); // , ImGuiCond_Always, { 0.5, 0.5 });

if (kind == MainWindow && placement == Maximize)
Expand Down Expand Up @@ -558,6 +563,8 @@ void TopWindow::Draw(UIContext& ctx)

ImGui::End();

if (style_rounding.eval_px(ctx) != ctx.style.WindowRounding)
ImGui::PopStyleVar();
if (style_border*1.f != ctx.style.WindowBorderSize)
ImGui::PopStyleVar();
if (style_spacing.has_value())
Expand Down Expand Up @@ -614,20 +621,27 @@ void TopWindow::Export(std::ostream& os, UIContext& ctx)
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, "
<< style_spacing.to_arg(ctx.unit) << ");\n";
}
if (style_border*1.f != ctx.style.WindowBorderSize)
if (style_rounding.eval_px(ctx) != ctx.style.WindowRounding)
{
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, "
<< style_rounding.to_arg(ctx.unit) << ");\n";
}
if (style_border*1.f != ctx.style.WindowBorderSize &&
kind != Activity)
{
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, "
<< (style_border*1.0f) << ");\n";
}

if (kind != MainWindow && placement == None &&
(flags & ImGuiWindowFlags_AlwaysAutoResize) == 0)
if (kind != MainWindow && kind != Activity &&
(flags & ImGuiWindowFlags_AlwaysAutoResize) == 0 &&
placement == None)
{
os << ctx.ind << "ImGui::SetNextWindowSize({ "
<< size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }, "
<< "ImGuiCond_FirstUseEver);\n";
}

if (kind == MainWindow)
{
os << ctx.ind << "glfwSetWindowTitle(window, " << title.to_arg() << ");\n";
Expand Down Expand Up @@ -789,6 +803,8 @@ void TopWindow::Export(std::ostream& os, UIContext& ctx)

if (style_border*1.f != ctx.style.WindowBorderSize)
os << ctx.ind << "ImGui::PopStyleVar();\n";
if (style_rounding.eval_px(ctx) != ctx.style.WindowRounding)
os << ctx.ind << "ImGui::PopStyleVar();\n";
if (style_spacing.has_value())
os << ctx.ind << "ImGui::PopStyleVar();\n";
if (style_padding.has_value())
Expand Down Expand Up @@ -861,6 +877,8 @@ void TopWindow::Import(cpp::stmt_iterator& sit, UIContext& ctx)
style_padding.set_from_arg(sit->params[1]);
else if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_ItemSpacing")
style_spacing.set_from_arg(sit->params[1]);
else if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_WindowRounding")
style_rounding.set_from_arg(sit->params[1]);
else if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_WindowBorderSize")
style_border = std::stod(sit->params[1]) != 0;
}
Expand Down Expand Up @@ -1031,8 +1049,9 @@ TopWindow::Properties()
{
return {
{ "top.kind", nullptr },
{ "top.@style.border", &style_border },
{ "top.@style.padding", &style_padding },
{ "top.@style.rounding", &style_rounding },
{ "top.@style.border", &style_border },
{ "top.@style.spacing", &style_spacing },
{ "top.@style.font", &style_font },
{ "top.flags", nullptr },
Expand Down Expand Up @@ -1064,29 +1083,37 @@ bool TopWindow::PropertyUI(int i, UIContext& ctx)
}
case 1:
{
ImGui::Text("border");
ImGui::Text("padding");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = ImGui::Checkbox("##style_border", style_border.access());
changed = ImGui::InputFloat2("##style_padding", (float*)style_padding.access());
break;
}
case 2:
{
ImGui::Text("padding");
ImGui::Text("rounding");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = ImGui::InputFloat2("##style_padding", (float*)style_padding.access());
changed = ImGui::InputFloat("##style_rounding", style_rounding.access());
break;
}
case 3:
{
ImGui::Text("border");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = ImGui::Checkbox("##style_border", style_border.access());
break;
}
case 4:
{
ImGui::Text("spacing");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = ImGui::InputFloat2("##style_spacing", (float*)style_spacing.access());
break;
}
case 4:
case 5:
ImGui::Text("font");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -1102,7 +1129,7 @@ bool TopWindow::PropertyUI(int i, UIContext& ctx)
ImGui::EndCombo();
}
break;
case 5:
case 6:
TreeNodeProp("flags", true, [&] {
ImGui::TableNextColumn();
ImGui::Spacing();
Expand All @@ -1115,31 +1142,31 @@ bool TopWindow::PropertyUI(int i, UIContext& ctx)
children.erase(children.begin());
});
break;
case 6:
case 7:
ImGui::Text("title");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##title", &title, ctx);
ImGui::SameLine(0, 0);
BindingButton("title", &title, ctx);
break;
case 7:
case 8:
ImGui::Text("size_x");
ImGui::TableNextColumn();
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || (kind == MainWindow && placement == Maximize));
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##size_x", &size_x, {}, ctx);
ImGui::EndDisabled();
break;
case 8:
case 9:
ImGui::Text("size_y");
ImGui::TableNextColumn();
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || (kind == MainWindow && placement == Maximize));
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##size_y", &size_y, {}, ctx);
ImGui::EndDisabled();
break;
case 9:
case 10:
ImGui::Text("placement");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand Down Expand Up @@ -2391,6 +2418,7 @@ Selectable::Selectable(UIContext& ctx)
flags.prefix("ImGuiSelectableFlags_");
flags.add$(ImGuiSelectableFlags_DontClosePopups);
flags.add$(ImGuiSelectableFlags_SpanAllColumns);
flags.add$(ImGuiSelectableFlags_NoPadWithHalfSpacing);
flags.add$(ImGuiSelectableFlags_Disabled);

horizAlignment.add("AlignLeft", ImRad::AlignLeft);
Expand Down Expand Up @@ -2726,6 +2754,7 @@ Button::Button(UIContext& ctx)
arrowDir.add$(ImGuiDir_Up);
arrowDir.add$(ImGuiDir_Down);

style_rounding = ctx.style.FrameRounding;
InitDimensions(ctx);
}

Expand Down Expand Up @@ -5564,6 +5593,7 @@ Child::Child(UIContext& ctx)
flags.add$(ImGuiChildFlags_AutoResizeY);
flags.add$(ImGuiChildFlags_FrameStyle);

style_rounding = ctx.style.ChildRounding;
InitDimensions(ctx);
}

Expand Down Expand Up @@ -5619,6 +5649,8 @@ void Child::DoDraw(UIContext& ctx)
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style_padding);
if (style_spacing.has_value())
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style_spacing);
if (style_rounding.eval_px(ctx) != ctx.style.ChildRounding)
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, style_rounding);
if (!style_bg.empty())
ImGui::PushStyleColor(ImGuiCol_ChildBg, style_bg.eval(ctx));

Expand All @@ -5641,6 +5673,8 @@ void Child::DoDraw(UIContext& ctx)

if (!style_bg.empty())
ImGui::PopStyleColor();
if (style_rounding.eval_px(ctx) != ctx.style.ChildRounding)
ImGui::PopStyleVar();
if (style_padding.has_value())
ImGui::PopStyleVar();
if (style_spacing.has_value())
Expand All @@ -5661,6 +5695,8 @@ void Child::DoExport(std::ostream& os, UIContext& ctx)
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, " << style_padding.to_arg(ctx.unit) << ");\n";
if (style_spacing.has_value())
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, " << style_spacing.to_arg(ctx.unit) << ");\n";
if (style_rounding.eval_px(ctx) != ctx.style.ChildRounding)
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, " << style_rounding.to_arg(ctx.unit) << ");\n";
if (!style_bg.empty())
os << ctx.ind << "ImGui::PushStyleColor(ImGuiCol_ChildBg, " << style_bg.to_arg() << ");\n";

Expand Down Expand Up @@ -5745,6 +5781,8 @@ void Child::DoExport(std::ostream& os, UIContext& ctx)
os << ctx.ind << "ImGui::PopClipRect();\n";
if (!style_bg.empty())
os << ctx.ind << "ImGui::PopStyleColor();\n";
if (style_rounding.eval_px(ctx) != ctx.style.ChildRounding)
os << ctx.ind << "ImGui::PopStyleVar();\n";
if (style_padding.has_value())
os << ctx.ind << "ImGui::PopStyleVar();\n";
if (style_spacing.has_value())
Expand All @@ -5764,6 +5802,8 @@ void Child::DoImport(const cpp::stmt_iterator& sit, UIContext& ctx)
style_padding.set_from_arg(sit->params[1]);
else if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_ItemSpacing")
style_spacing.set_from_arg(sit->params[1]);
else if (sit->params.size() == 2 && sit->params[0] == "ImGuiStyleVar_ChildRounding")
style_rounding.set_from_arg(sit->params[1]);
}
else if (sit->kind == cpp::Other && !sit->line.compare(0, 9, "ImVec2 sz"))
{
Expand Down Expand Up @@ -5809,6 +5849,7 @@ Child::Properties()
{ "@style.color", &style_bg },
{ "@style.padding", &style_padding },
{ "@style.spacing", &style_spacing },
{ "@style.rounding", &style_rounding },
{ "@style.outer_padding", &style_outer_padding },
{ "child.flags", &flags },
{ "child.column_count", &columnCount },
Expand Down Expand Up @@ -5846,42 +5887,48 @@ bool Child::PropertyUI(int i, UIContext& ctx)
changed = ImGui::InputFloat2("##spacing", (float*)style_spacing.access());
break;
case 3:
ImGui::Text("rounding");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = ImGui::InputFloat("##rounding", (float*)style_rounding.access());
break;
case 4:
ImGui::Text("outerPadding");
ImGui::TableNextColumn();
changed = ImGui::Checkbox("##outerPadding", style_outer_padding.access());
break;
case 4:
case 5:
TreeNodeProp("flags", true, [&] {
ImGui::TableNextColumn();
ImGui::Spacing();
changed = CheckBoxFlags(&flags) || changed;
});
break;
case 5:
case 6:
ImGui::Text("columnCount");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##columnCount", &columnCount, 1, ctx);
ImGui::SameLine(0, 0);
BindingButton("columnCount", &columnCount, ctx);
break;
case 6:
case 7:
ImGui::Text("columnBorder");
ImGui::TableNextColumn();
changed = ImGui::Checkbox("##columnBorder", columnBorder.access());
break;
case 7:
case 8:
changed = DataLoopProp("itemCount", &itemCount, ctx);
break;
case 8:
case 9:
ImGui::Text("size_x");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##size_x", &size_x, {}, ctx);
ImGui::SameLine(0, 0);
BindingButton("size_x", &size_x, ctx);
break;
case 9:
case 10:
ImGui::Text("size_y");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -5890,7 +5937,7 @@ bool Child::PropertyUI(int i, UIContext& ctx)
BindingButton("size_y", &size_y, ctx);
break;
default:
return Widget::PropertyUI(i - 10, ctx);
return Widget::PropertyUI(i - 11, ctx);
}
return changed;
}
Expand Down
2 changes: 2 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ struct Child : Widget
direct_val<dimension2> style_padding;
direct_val<dimension2> style_spacing;
direct_val<bool> style_outer_padding = true;
direct_val<dimension> style_rounding = 0;
bindable<color32> style_bg;

Child(UIContext& ctx);
Expand Down Expand Up @@ -639,6 +640,7 @@ struct TopWindow : UINode
direct_val<dimension2> style_padding;
direct_val<dimension2> style_spacing;
direct_val<bool> style_border = 1;
direct_val<dimension> style_rounding = 0;
direct_val<Placement> placement = None;

TopWindow(UIContext& ctx);
Expand Down

0 comments on commit f91e8af

Please sign in to comment.