Commit 07cc82b3 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: add popup context menu for generator

parent 7f9b6e47
......@@ -1917,6 +1917,18 @@ show_dynamics_inputs(generator& dyn)
{
ImGui::InputDouble("value", &dyn.default_value);
ImGui::InputDouble("offset", &dyn.default_offset);
if (ImGui::Button("Select.."))
ImGui::OpenPopup("Select source");
ImGui::SameLine();
if (dyn.default_value_source_id == external_source_id{ 0 }) {
ImGui::TextUnformatted("<None>");
} else {
ImGui::Text("%" PRIu64, static_cast<u64>(dyn.default_value_source_id));
}
external_source src;
app.srcs.show_menu(src);
}
static void
......
......@@ -311,6 +311,7 @@ struct sources
irt::source::text_file* new_text_file() noexcept;
void show(bool* is_show);
void show_menu(external_source& src);
};
struct editor
......
......@@ -79,7 +79,7 @@ static constexpr const char* items[] = {
};
template<typename RandomGenerator, typename Distribution>
inline void
static void
generate(std::ostream& os,
RandomGenerator& gen,
Distribution dist,
......@@ -336,7 +336,7 @@ struct distribution_manager
}
};
void
static void
show_random()
{
static distribution_manager dm;
......@@ -762,4 +762,68 @@ sources::show(bool* is_show)
ImGui::End();
}
void
sources::show_menu(external_source& src)
{
small_string<16> tmp;
std::pair<const int, source::constant>* constant_ptr = nullptr;
std::pair<const int, source::binary_file>* binary_file_ptr = nullptr;
std::pair<const int, source::text_file>* text_file_ptr = nullptr;
if (ImGui::BeginPopup("Select source")) {
if (!csts.empty() && ImGui::BeginMenu("Constant")) {
for (auto& elem : csts) {
fmt::format_to_n(tmp.begin(), tmp.capacity(), "{}", elem.first);
if (ImGui::MenuItem(tmp.c_str())) {
constant_ptr = &elem;
break;
}
}
ImGui::EndMenu();
}
if (!bins.empty() && ImGui::BeginMenu("Binary files")) {
for (auto& elem : bins) {
fmt::format_to_n(tmp.begin(), tmp.capacity(), "{}", elem.first);
if (ImGui::MenuItem(tmp.c_str())) {
binary_file_ptr = &elem;
break;
}
}
ImGui::EndMenu();
}
if (!texts.empty() && ImGui::BeginMenu("Text files")) {
for (auto& elem : texts) {
fmt::format_to_n(tmp.begin(), tmp.capacity(), "{}", elem.first);
if (ImGui::MenuItem(tmp.c_str())) {
text_file_ptr = &elem;
break;
}
}
ImGui::EndMenu();
}
if (constant_ptr != nullptr) {
constant_ptr->second.init(src);
src.id = constant_ptr->first;
constant_ptr = nullptr;
}
if (binary_file_ptr != nullptr) {
binary_file_ptr->second.init(src);
src.id = binary_file_ptr->first;
binary_file_ptr = nullptr;
}
if (text_file_ptr != nullptr) {
text_file_ptr->second.init(src);
src.id = text_file_ptr->first;
text_file_ptr = nullptr;
}
ImGui::EndPopup();
}
}
} // namespace irt
\ No newline at end of file
......@@ -17,6 +17,16 @@ struct constant
{
double value;
bool init(external_source& src)
{
src.type = 0;
src.id = 0;
src.data = &value;
src.index = 0;
return true;
}
bool operator()(external_source& src)
{
src.index = 0;
......@@ -36,6 +46,9 @@ struct binary_file
bool init(external_source& src)
{
src.type = 1;
src.id = 0;
if (!ifs) {
ifs.open(file_path);
......@@ -45,6 +58,8 @@ struct binary_file
if (!read(src))
return false;
return true;
}
bool operator()(external_source& src)
......@@ -89,6 +104,9 @@ struct text_file
bool init(external_source& src)
{
src.type = 2;
src.id = 0;
if (!ifs) {
ifs.open(file_path);
......@@ -98,6 +116,8 @@ struct text_file
if (!read(src))
return false;
return true;
}
bool operator()(external_source& src)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment