Adjusted design of list on scripts and all numbers now use sliders

This commit is contained in:
Kah Wei 2022-11-12 03:53:30 +08:00
parent d6764b4551
commit 6dbda12f30
3 changed files with 39 additions and 60 deletions

View File

@ -75,7 +75,7 @@ namespace SHADE
bool SHEditorUI::BeginMenu(const std::string& label) bool SHEditorUI::BeginMenu(const std::string& label)
{ {
return ImGui::BeginMenu(label.data()); return ImGui::BeginMenu(label.data());
} }
bool SHEditorUI::BeginMenu(const std::string& label, const char* icon) bool SHEditorUI::BeginMenu(const std::string& label, const char* icon)
@ -143,7 +143,7 @@ namespace SHADE
bool SHEditorUI::Selectable(const std::string& label) bool SHEditorUI::Selectable(const std::string& label)
{ {
return ImGui::Selectable(label.data()); return ImGui::Selectable(label.data());
} }
bool SHEditorUI::Selectable(const std::string& label, const char* icon) bool SHEditorUI::Selectable(const std::string& label, const char* icon)
@ -165,8 +165,10 @@ namespace SHADE
if (isHovered) if (isHovered)
*isHovered = ImGui::IsItemHovered(); *isHovered = ImGui::IsItemHovered();
ImGui::SameLine(); ImGui::SameLine();
return ImGui::InputInt("##", &value, return ImGui::DragInt("##", &value, 0.001f,
1, 10, std::numeric_limits<int>::min(),
std::numeric_limits<int>::max(),
"%d",
ImGuiInputTextFlags_EnterReturnsTrue); ImGuiInputTextFlags_EnterReturnsTrue);
} }
bool SHEditorUI::InputUnsignedInt(const std::string& label, unsigned int& value, bool* isHovered) bool SHEditorUI::InputUnsignedInt(const std::string& label, unsigned int& value, bool* isHovered)
@ -190,31 +192,22 @@ namespace SHADE
if (isHovered) if (isHovered)
*isHovered = ImGui::IsItemHovered(); *isHovered = ImGui::IsItemHovered();
ImGui::SameLine(); ImGui::SameLine();
return ImGui::InputFloat("##", &value, return ImGui::DragFloat("##", &value, 0.001f,
0.1f, 1.0f, "%.3f", std::numeric_limits<float>::lowest(),
std::numeric_limits<float>::max(),
"%.3f",
ImGuiInputTextFlags_EnterReturnsTrue); ImGuiInputTextFlags_EnterReturnsTrue);
} }
bool SHEditorUI::InputDouble(const std::string& label, double& value, bool* isHovered) bool SHEditorUI::InputDouble(const std::string& label, double& value, bool* isHovered)
{ {
ImGui::Text(label.c_str()); float val = value;
if (isHovered) const bool CHANGED = InputFloat(label, val, isHovered);
*isHovered = ImGui::IsItemHovered(); if (CHANGED)
ImGui::SameLine(); {
return ImGui::InputDouble("##", &value, value = static_cast<double>(val);
0.1, 1.0, "%.3f", }
ImGuiInputTextFlags_EnterReturnsTrue); return CHANGED;
} }
bool SHEditorUI::InputAngle(const std::string& label, double& value, bool* isHovered)
{
ImGui::Text(label.c_str());
if (isHovered)
*isHovered = ImGui::IsItemHovered();
ImGui::SameLine();
return ImGui::InputDouble("##", &value,
1.0, 45.0, "%.3f",
ImGuiInputTextFlags_EnterReturnsTrue);
}
bool SHEditorUI::InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered /*= nullptr*/) bool SHEditorUI::InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered /*= nullptr*/)
{ {
ImGui::Text(label.c_str()); ImGui::Text(label.c_str());

View File

@ -219,17 +219,6 @@ namespace SHADE
/// <returns>True if the value was changed.</returns> /// <returns>True if the value was changed.</returns>
static bool InputDouble(const std::string& label, double& value, bool* isHovered = nullptr); static bool InputDouble(const std::string& label, double& value, bool* isHovered = nullptr);
/// <summary> /// <summary>
/// Creates a decimal field widget for double input with increments of higher
/// steps meant for angle variables.
/// <br/>
/// Wraps up ImGui::InputDouble().
/// </summary>
/// <param name="label">Label used to identify this widget.</param>
/// <param name="value">Reference to the variable to store the result.</param>
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
/// <returns>True if the value was changed.</returns>
static bool InputAngle(const std::string& label, double& value, bool* isHovered = nullptr);
/// <summary>
/// Creates an int slider field widget for double input. /// Creates an int slider field widget for double input.
/// <br/> /// <br/>
/// Wraps up ImGui::SliderInt(). /// Wraps up ImGui::SliderInt().

View File

@ -178,39 +178,36 @@ namespace SHADE
RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field); RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field);
System::Collections::IList^ iList = safe_cast<System::Collections::IList^>(field->GetValue(object)); System::Collections::IList^ iList = safe_cast<System::Collections::IList^>(field->GetValue(object));
SHEditorUI::Text(Convert::ToNative(field->Name)); if (SHEditorUI::CollapsingHeader(Convert::ToNative(field->Name)))
SHEditorUI::SameLine();
if (SHEditorUI::Button("+"))
{ {
System::Object^ obj = System::Activator::CreateInstance(listType); if (SHEditorUI::Button("Add Item"))
iList->Add(obj);
registerUndoListAddAction(listType, iList, iList->Count - 1, obj);
}
SHEditorUI::Indent();
for (int i = 0; i < iList->Count; ++i)
{
SHEditorUI::PushID(i);
System::Object^ obj = iList[i];
System::Object^ oldObj = iList[i];
if (renderFieldEditor(std::to_string(i), obj, rangeAttrib))
{ {
iList[i] = obj; System::Object^ obj = System::Activator::CreateInstance(listType);
registerUndoListChangeAction(listType, iList, i, obj, oldObj); iList->Add(obj);
registerUndoListAddAction(listType, iList, iList->Count - 1, obj);
} }
SHEditorUI::SameLine(); for (int i = 0; i < iList->Count; ++i)
if (SHEditorUI::Button("-"))
{ {
SHEditorUI::PushID(i);
System::Object^ obj = iList[i]; System::Object^ obj = iList[i];
iList->RemoveAt(i); System::Object^ oldObj = iList[i];
registerUndoListRemoveAction(listType, iList, i, obj); if (renderFieldEditor(std::to_string(i), obj, rangeAttrib))
{
iList[i] = obj;
registerUndoListChangeAction(listType, iList, i, obj, oldObj);
}
SHEditorUI::SameLine();
if (SHEditorUI::Button("-"))
{
System::Object^ obj = iList[i];
iList->RemoveAt(i);
registerUndoListRemoveAction(listType, iList, i, obj);
SHEditorUI::PopID();
break;
}
SHEditorUI::PopID(); SHEditorUI::PopID();
break;
} }
SHEditorUI::PopID();
} }
SHEditorUI::Unindent();
} }
else else
{ {