Skip to content

Commit

Permalink
more styles for Slider, ColorEdit, ProgressBar
Browse files Browse the repository at this point in the history
  • Loading branch information
tpecholt committed Aug 25, 2024
1 parent 02c5fed commit c7e0819
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 20 deletions.
159 changes: 140 additions & 19 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5946,6 +5946,11 @@ Slider::Properties()
{
auto props = Widget::Properties();
props.insert(props.begin(), {
{ "@style.text", &style_text },
{ "@style.frameBg", &style_frameBg },
{ "@style.border", &style_border },
{ "@style.borderSize", &style_frameBorderSize },
{ "@style.font", &style_font },
{ "label", &label, true },
{ "slider.type", &type },
{ "slider.field_name", &fieldName },
Expand Down Expand Up @@ -5975,12 +5980,50 @@ bool Slider::PropertyUI(int i, UIContext& ctx)
switch (i)
{
case 0:
ImGui::Text("text");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##text", &style_text, ImGuiCol_Text, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("text", &style_text, ctx);
break;
case 1:
ImGui::Text("frameBg");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##frameBg", &style_frameBg, ImGuiCol_FrameBg, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("frameBg", &style_frameBg, ctx);
break;
case 2:
ImGui::Text("border");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##border", &style_border, ImGuiCol_Border, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("border", &style_border, ctx);
break;
case 3:
ImGui::Text("borderSize");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##borderSize", &style_frameBorderSize, ctx);
break;
case 4:
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:
ImGui::Text("label");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##label", &label, ctx);
break;
case 1:
case 6:
ImGui::Text("type");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -5997,14 +6040,14 @@ bool Slider::PropertyUI(int i, UIContext& ctx)
ImGui::EndCombo();
}
break;
case 2:
case 7:
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, FIELD_NAME_CLR);
ImGui::Text("fieldName");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputFieldRef("##fieldName", &fieldName, type, false, ctx);
break;
case 3:
case 8:
ImGui::Text("min");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -6017,7 +6060,7 @@ bool Slider::PropertyUI(int i, UIContext& ctx)
changed = ImGui::InputFloat("##min", min.access());
}
break;
case 4:
case 9:
ImGui::Text("max");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -6030,13 +6073,13 @@ bool Slider::PropertyUI(int i, UIContext& ctx)
changed = ImGui::InputFloat("##max", max.access());
}
break;
case 5:
case 10:
ImGui::Text("format");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = ImGui::InputText("##format", format.access());
break;
case 6:
case 11:
ImGui::Text("size_x");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -6045,7 +6088,7 @@ bool Slider::PropertyUI(int i, UIContext& ctx)
changed |= BindingButton("size_x", &size_x, ctx);
break;
default:
return Widget::PropertyUI(i - 7, ctx);
return Widget::PropertyUI(i - 12, ctx);
}
return changed;
}
Expand Down Expand Up @@ -6161,8 +6204,12 @@ ProgressBar::Properties()
{
auto props = Widget::Properties();
props.insert(props.begin(), {
{ "@style.text", &style_text },
{ "@style.frameBg", &style_frameBg },
{ "@style.color", &style_color },
{ "@style.border", &style_border },
{ "@style.borderSize", &style_frameBorderSize },
{ "@style.font", &style_font },
{ "progress.field_name", &fieldName },
{ "progress.indicator", &indicator },
{ "size_x", &size_x },
Expand All @@ -6177,25 +6224,63 @@ bool ProgressBar::PropertyUI(int i, UIContext& ctx)
switch (i)
{
case 0:
ImGui::Text("text");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##text", &style_text, ImGuiCol_Text, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("text", &style_text, ctx);
break;
case 1:
ImGui::Text("frameBg");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##frameBg", &style_frameBg, ImGuiCol_FrameBg, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("frameBg", &style_frameBg, ctx);
break;
case 2:
ImGui::Text("color");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##color", &style_color, ImGuiCol_PlotHistogram, ctx);
break;
case 1:
case 3:
ImGui::Text("border");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##border", &style_border, ImGuiCol_Border, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("border", &style_border, ctx);
break;
case 4:
ImGui::Text("borderSize");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##borderSize", &style_frameBorderSize, ctx);
break;
case 2:
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 6:
ImGui::Text("borderSize");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##borderSize", &style_frameBorderSize, ctx);
break;
case 7:
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, FIELD_NAME_CLR);
ImGui::Text("fieldName");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputFieldRef("##fieldName", &fieldName, "float", false, ctx);
break;
case 3:
case 8:
{
ImGui::Text("indicator");
ImGui::TableNextColumn();
Expand All @@ -6205,15 +6290,15 @@ bool ProgressBar::PropertyUI(int i, UIContext& ctx)
indicator = ind;
break;
}
case 4:
case 9:
ImGui::Text("size_x");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##size_x", &size_x, {}, InputBindable_StretchButton, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("size_x", &size_x, ctx);
break;
case 5:
case 10:
ImGui::Text("size_y");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -6222,7 +6307,7 @@ bool ProgressBar::PropertyUI(int i, UIContext& ctx)
changed |= BindingButton("size_y", &size_y, ctx);
break;
default:
return Widget::PropertyUI(i - 6, ctx);
return Widget::PropertyUI(i - 11, ctx);
}
return changed;
}
Expand Down Expand Up @@ -6350,7 +6435,11 @@ ColorEdit::Properties()
{
auto props = Widget::Properties();
props.insert(props.begin(), {
{ "@style.text", &style_text },
{ "@style.frameBg", &style_frameBg },
{ "@style.border", &style_border },
{ "@style.borderSize", &style_frameBorderSize },
{ "@style.font", &style_font },
{ "color.flags", &flags },
{ "label", &label, true },
{ "color.type", &type },
Expand All @@ -6371,25 +6460,57 @@ bool ColorEdit::PropertyUI(int i, UIContext& ctx)
switch (i)
{
case 0:
ImGui::Text("text");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##text", &style_text, ImGuiCol_Text, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("text", &style_text, ctx);
break;
case 1:
ImGui::Text("frameBg");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##frameBg", &style_frameBg, ImGuiCol_FrameBg, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("frameBg", &style_frameBg, ctx);
break;
case 2:
ImGui::Text("border");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputBindable("##border", &style_border, ImGuiCol_Border, ctx);
ImGui::SameLine(0, 0);
changed |= BindingButton("border", &style_border, ctx);
break;
case 3:
ImGui::Text("borderSize");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##borderSize", &style_frameBorderSize, ctx);
break;
case 1:
case 4:
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:
TreeNodeProp("flags", "...", [&] {
ImGui::TableNextColumn();
ImGui::Spacing();
changed = CheckBoxFlags(&flags);
});
break;
case 2:
case 6:
ImGui::Text("label");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##label", &label, ctx);
break;
case 3:
case 7:
ImGui::Text("type");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -6406,14 +6527,14 @@ bool ColorEdit::PropertyUI(int i, UIContext& ctx)
ImGui::EndCombo();
}
break;
case 4:
case 8:
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, FIELD_NAME_CLR);
ImGui::Text("fieldName");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputFieldRef("##fieldName", &fieldName, type, false, ctx);
break;
case 5:
case 9:
ImGui::Text("size_x");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
Expand All @@ -6422,7 +6543,7 @@ bool ColorEdit::PropertyUI(int i, UIContext& ctx)
changed |= BindingButton("size_x", &size_x, ctx);
break;
default:
return Widget::PropertyUI(i - 6, ctx);
return Widget::PropertyUI(i - 10, ctx);
}
return changed;
}
Expand Down
2 changes: 1 addition & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ struct Splitter : Widget
void DoExport(std::ostream& os, UIContext& ctx);
void DoImport(const cpp::stmt_iterator& sit, UIContext& ctx);
//void CalcSizeEx(ImVec2 p1, UIContext& ctx);
const char* GetIcon() const { return ICON_FA_ARROWS_LEFT_RIGHT_TO_LINE; }
const char* GetIcon() const { return ICON_FA_TABLE_COLUMNS; }
};

struct TopWindow : UINode
Expand Down

0 comments on commit c7e0819

Please sign in to comment.