I may be using the control incorrectly.
The workflow is such that when a checkbox is clicked then I would like other checkboxes to also be updated.
i.e. Click checkbox A and have checkbox B reflect the same checked state as A.
Example Code:
#pragma once
#include <elements.hpp>
#include <memory_resource>
namespace experimental::elements
{
namespace colors_rgba
{
constexpr auto alpha = 200;
constexpr auto default_dark = cycfi::elements::rgba(32, 32, 32, alpha);
constexpr auto slate_gray = cycfi::elements::rgba(112, 128, 144, alpha);
constexpr auto antique_white = cycfi::elements::rgba(250, 235, 215, alpha);
constexpr auto doger_blue = cycfi::elements::rgba(16, 78, 139, alpha);
}
namespace colors_rgb
{
constexpr auto default_dark = cycfi::elements::rgb(32, 32, 32);
constexpr auto slate_gray = cycfi::elements::rgb(112, 128, 144);
constexpr auto antique_white = cycfi::elements::rgb(250, 235, 215);
constexpr auto doger_blue = cycfi::elements::rgb(16, 78, 139);
}
using check_box_t = cycfi::elements::basic_toggle_button<cycfi::elements::proxy<cycfi::elements::check_box_element, cycfi::elements::basic_button>>;
namespace grpc::controller
{
// TODO: Load from config file.
//
auto constexpr default_path = "";
// Main window background color
// Is it possible to effect forground colors_rgba?
//
auto constexpr bkd_color = elements::colors_rgba::slate_gray;
class test_options_dialog final
{
const cycfi::elements::box_element background = cycfi::elements::box(bkd_color);
elements::check_box_t check_box1 = cycfi::elements::check_box("gRPC Simulations Server");
elements::check_box_t check_box2 = cycfi::elements::check_box("gRPC GPS Simulator");
elements::check_box_t check_box3 = cycfi::elements::check_box("gRPC UAV Simulator");
// This works, but the repainting of check_box1, 2, and 3 does not.
// Therefore the user does not receive the desired feedback.
//
elements::check_box_t check_box_select_all = cycfi::elements::check_box("Select All");
std::size_t uav_instances_to_create_ = 5;
auto make_selection_menu()
{
return cycfi::elements::selection_menu(
[&](std::string_view& select)
{
const char* count = select.data();
uav_instances_to_create_ = std::atol(count);
},
{
"5",
"10",
"15",
"20",
}
).first; // We return only the first, the menu. the second is a shared pointer to the label.
}
void run_selected_options() const
{
using namespace cycfi::elements;
const auto simulations_data_bus = std::string(default_path).append("simulations_data_bus.exe");
const auto gps_device_emulator = std::string(default_path).append("gps_device_emulator.exe");
const auto uav_entity_simulator = std::string(default_path).append("uav_emulator.exe");
std::string args = "-ignore";
if (check_box1.value())
{
//system::process::start_process(simulations_data_bus.c_str(), args);
}
if (check_box2.value())
{
//system::process::start_process(gps_device_emulator.c_str(), args);
}
if (check_box3.value())
{
auto* uav_fmt = " -uav:\"UAV ";
const auto end = uav_instances_to_create_;
for (auto n = 0; n < end; ++n)
{
auto arg = uav_fmt + std::to_string(n).append("\"");
//system::process::start_process(uav_entity_simulator.c_str(), arg);
}
}
}
auto options_button_layout(cycfi::elements::view& window_view)
{
using namespace cycfi::elements;
auto run_options_button = button("Run Selected Options");
run_options_button.on_click =
[&](bool) mutable
{
run_selected_options();
};
return
margin({ 20, 0, 20, 20 },
vtile(
top_margin(20, run_options_button),
top_margin(10,
htile(
margin({ 0, 0, 10, 0 },
label("UAV Count:")
.text_align(canvas::right)),
hmin_size(30, make_selection_menu()))
),
top_margin(10, check_box_select_all)
)
);
}
void assign_checkbox_event_handlers(cycfi::elements::view& window_view)
{
check_box_select_all.on_click =
[&](bool) mutable
{
check_box_select_all.value(!check_box_select_all.value());
// ' window_view.refresh(check_box1);' code is not working...
//
const auto update = check_box_select_all.value();
check_box1.on_click(update);
check_box2.on_click(update);
check_box3.on_click(update);
return true;
};
check_box1.on_click =
[&](bool) mutable
{
check_box1.value(!check_box1.value());
window_view.refresh(check_box1);
};
check_box2.on_click =
[&](bool) mutable
{
check_box2.value(!check_box2.value());
window_view.refresh(check_box2);
};
check_box3.on_click =
[&](bool) mutable
{
check_box3.value(!check_box3.value());
window_view.refresh(check_box3);
};
}
auto create_view_models(cycfi::elements::view& window_view)
{
using namespace cycfi::elements;
check_box1.value(false);
check_box2.value(false);
check_box3.value(false);
assign_checkbox_event_handlers(window_view);
auto check_boxes =
group("Components",
margin({ 10, 10, 20, 20 },
top_margin(25,
vtile(
top_margin(10, align_left(check_box1)),
top_margin(10, align_left(check_box2)),
top_margin(10, align_left(check_box3))
)
)
)
);
return
vtile(
htile(
options_button_layout(window_view),
vtile(
margin({ 20, 20, 20, 20 }, check_boxes)
)
)
);
}
public:
auto show(const int argc = 0, char* argv[] = nullptr)
{
using namespace cycfi::elements;
app app_instance(argc, argv, "gRPC - Simulations (Munitions) Data Bus", "");
window window_model(app_instance.name());
window_model.on_close = [&app_instance]() { app_instance.stop(); };
view window_view(window_model);
window_view.content(create_view_models(window_view), background);
app_instance.run();
}
};
inline int show_dialog(const int argc, char* argv[])
{
test_options_dialog dialog;
dialog.show(argc, argv);
return 0;
}
}
} // using namespace experimental::elements;
//#include "grpc-startup-controller.hh"
using namespace experimental::elements::grpc;
/**
- \brief
- \param argc
- \param argv
- \return
/
int main(const int argc, char argv[])
{
return controller::show_dialog(argc, argv);
}
Again, this is awesome work you are doing. Thanks so so much!
I may be using the control incorrectly.
The workflow is such that when a checkbox is clicked then I would like other checkboxes to also be updated.
i.e. Click checkbox A and have checkbox B reflect the same checked state as A.
Example Code:
#pragma once
#include <elements.hpp>
#include <memory_resource>
namespace experimental::elements
{
namespace colors_rgba
{
constexpr auto alpha = 200;
constexpr auto default_dark = cycfi::elements::rgba(32, 32, 32, alpha);
constexpr auto slate_gray = cycfi::elements::rgba(112, 128, 144, alpha);
constexpr auto antique_white = cycfi::elements::rgba(250, 235, 215, alpha);
constexpr auto doger_blue = cycfi::elements::rgba(16, 78, 139, alpha);
}
namespace colors_rgb
{
constexpr auto default_dark = cycfi::elements::rgb(32, 32, 32);
constexpr auto slate_gray = cycfi::elements::rgb(112, 128, 144);
constexpr auto antique_white = cycfi::elements::rgb(250, 235, 215);
constexpr auto doger_blue = cycfi::elements::rgb(16, 78, 139);
}
using check_box_t = cycfi::elements::basic_toggle_button<cycfi::elements::proxy<cycfi::elements::check_box_element, cycfi::elements::basic_button>>;
namespace grpc::controller
{
// TODO: Load from config file.
//
auto constexpr default_path = "";
}
} // using namespace experimental::elements;
//#include "grpc-startup-controller.hh"
using namespace experimental::elements::grpc;
/**
/
int main(const int argc, char argv[])
{
return controller::show_dialog(argc, argv);
}
Again, this is awesome work you are doing. Thanks so so much!