Skip to content

Commit

Permalink
* dynamicGUI adaptations
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Walter committed Oct 3, 2023
1 parent 3902761 commit e91abb5
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 164 deletions.
21 changes: 11 additions & 10 deletions Application/src/tracker/Alterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,28 @@ inline static sprite::Map _video_info = [](){
}();

Alterface::Alterface(dyn::Context&& context, std::function<void(const std::string&)>&& settings_update)
: context(std::move(context)),
: dynGUI{
.path = "alter_layout.json",
.graph = nullptr,
.context = std::move(context)
},
settings(std::move(settings_update))
{
}

Alterface::~Alterface() {
context = {};
state = {};

objects.clear();
dynGUI.clear();
}

void Alterface::draw(IMGUIBase& base, DrawStructure& g) {
dyn::update_layout("alter_layout.json", context, state, objects);
if(not dynGUI) {
dynGUI.graph = &g;
dynGUI.base = (Base*)&base;
}

g.section("buttons", [&](auto&, Section* section) {
section->set_scale(g.scale().reciprocal());
for(auto &obj : objects) {
dyn::update_objects(g, obj, context, state);
g.wrap_object(*obj);
}
dynGUI.update(nullptr);
});

settings.draw(base, g);
Expand Down
4 changes: 1 addition & 3 deletions Application/src/tracker/Alterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace gui {

struct Alterface {
Image::Ptr next;
dyn::Context context;
dyn::State state;
std::vector<Layout::Ptr> objects;
dyn::DynamicGUI dynGUI;
SettingsDropdown settings;

Alterface() = delete;
Expand Down
14 changes: 7 additions & 7 deletions Application/src/tracker/VideoOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ VideoOpener::LabeledDropDown::LabeledDropDown(const std::string& name)
items.push_back(Dropdown::TextItem(name, index++));
}
_dropdown->set_items(items);
_dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
_dropdown->select_item(Dropdown::RawIndex{narrow_cast<long>(_ref.get().enum_index()())});
_dropdown->textfield()->set_text(_ref.get().valueString());

_dropdown->on_select([this](auto index, auto) {
if(index < 0)
if(not index.valid())
return;

try {
_ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index));
_ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index.value));
} catch(...) {}

_dropdown->set_opened(false);
});
}

void VideoOpener::LabeledDropDown::update() {
_dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
_dropdown->select_item(Dropdown::RawIndex{narrow_cast<long>(_ref.get().enum_index()())});
}

VideoOpener::VideoOpener()
Expand Down Expand Up @@ -979,7 +979,7 @@ void VideoOpener::select_file(const file::Path &p) {
}

if(name == "output_prefix") {
((Dropdown*)children.back().get())->on_select([dropdown = ((Dropdown*)children.back().get()), this](long_t, const Dropdown::TextItem & item)
((Dropdown*)children.back().get())->on_select([dropdown = ((Dropdown*)children.back().get()), this](auto, const Dropdown::TextItem & item)
{
_output_prefix = item.search_name();
dropdown->set_opened(false);
Expand All @@ -1001,13 +1001,13 @@ void VideoOpener::select_file(const file::Path &p) {
});

if(_output_prefix.empty())
((Dropdown*)children.back().get())->select_item(-1);
((Dropdown*)children.back().get())->select_item(Dropdown::RawIndex());
else {
auto items = ((Dropdown*)children.back().get())->items();
auto N = items.size();
for(size_t i=0; i<N; ++i) {
if(items.at(i).search_name() == _output_prefix) {
((Dropdown*)children.back().get())->select_item(narrow_cast<long>(i));
((Dropdown*)children.back().get())->select_item(Dropdown::RawIndex{narrow_cast<long>(i)});
break;
}
}
Expand Down
14 changes: 7 additions & 7 deletions Application/src/tracker/VideoOpenerScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ VideoOpener::LabeledDropDown::LabeledDropDown(const std::string& name)
items.push_back(Dropdown::TextItem(name, index++));
}
_dropdown->set_items(items);
_dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
_dropdown->select_item(Dropdown::RawIndex{narrow_cast<long>(_ref.get().enum_index()())});
_dropdown->textfield()->set_text(_ref.get().valueString());

_dropdown->on_select([this](auto index, auto) {
if(index < 0)
if(not index.valid())
return;

try {
_ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index));
_ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index.value));
} catch(...) {}

_dropdown->set_opened(false);
});
}

void VideoOpener::LabeledDropDown::update() {
_dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
_dropdown->select_item(Dropdown::RawIndex{narrow_cast<long>(_ref.get().enum_index()())});
}

VideoOpener::VideoOpener()
Expand Down Expand Up @@ -979,7 +979,7 @@ void VideoOpener::select_file(const file::Path &p) {
}

if(name == "output_prefix") {
((Dropdown*)children.back().get())->on_select([dropdown = ((Dropdown*)children.back().get()), this](long_t, const Dropdown::TextItem & item)
((Dropdown*)children.back().get())->on_select([dropdown = ((Dropdown*)children.back().get()), this](auto, const Dropdown::TextItem & item)
{
_output_prefix = item.search_name();
dropdown->set_opened(false);
Expand All @@ -1001,13 +1001,13 @@ void VideoOpener::select_file(const file::Path &p) {
});

if(_output_prefix.empty())
((Dropdown*)children.back().get())->select_item(-1);
((Dropdown*)children.back().get())->select_item(Dropdown::RawIndex{});
else {
auto items = ((Dropdown*)children.back().get())->items();
auto N = items.size();
for(size_t i=0; i<N; ++i) {
if(items.at(i).search_name() == _output_prefix) {
((Dropdown*)children.back().get())->select_item(narrow_cast<long>(i));
((Dropdown*)children.back().get())->select_item(Dropdown::RawIndex{narrow_cast<long>(i)});
break;
}
}
Expand Down
6 changes: 2 additions & 4 deletions Application/src/tracker/gui/ConvertScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ _on_deactivate(on_deactivate)
_video_info.set_do_print(false);
fish.set_do_print(false);

menu.context.variables.emplace("fishes", new Variable([this](std::string) -> std::vector<std::shared_ptr<VarBase_t>>&{
menu.dynGUI.context.variables.emplace("fishes", new Variable([this](std::string) -> std::vector<std::shared_ptr<VarBase_t>>&{
return _gui_objects;
}));
}
Expand Down Expand Up @@ -204,9 +204,7 @@ void ConvertScene::deactivate() {
_segmenter = nullptr;
_object_blobs.clear();
_current_data = {};

menu.state = dyn::State{};
menu.objects.clear();
menu.dynGUI.clear();

if(_on_deactivate)
_on_deactivate(*this);
Expand Down
6 changes: 3 additions & 3 deletions Application/src/tracker/gui/DrawBlobView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void draw_blob_view(const DisplayParameters& parm)
GUI::set_redraw();
}
});
list->on_select([parm](long_t, auto& item) {
list->on_select([parm](auto, auto& item) {
pv::bid clicked_blob_id { (uint32_t)int64_t(item.custom()) };
if(item.ID() == 0) /* SPLIT */ {
auto copy = FAST_SETTING(manual_splits);
Expand Down Expand Up @@ -640,7 +640,7 @@ void draw_blob_view(const DisplayParameters& parm)
}

void clicked_background(DrawStructure& base, GUICache& cache, const Vec2& pos, bool v, std::string key, Dropdown& settings_dropdown, Textfield& value_input) {
const std::string chosen = settings_dropdown.selected_id() > -1 ? settings_dropdown.items().at(settings_dropdown.selected_id()).name() : "";
const std::string chosen = settings_dropdown.has_selection() ? settings_dropdown.selected_item().name() : "";
if (key.empty())
key = chosen;

Expand Down Expand Up @@ -923,7 +923,7 @@ void draw_boundary_selection(DrawStructure& base, Base* window, GUICache& cache,
"track_include",
"recognition_shapes"
});
dropdown->on_select([&](long_t, const Dropdown::TextItem & item){
dropdown->on_select([&](auto, const Dropdown::TextItem & item){
clicked_background(base, cache, Vec2(), true, item.name(), settings_dropdown, value_input);
});
dropdown->textfield()->set_placeholder("append to...");
Expand Down
8 changes: 4 additions & 4 deletions Application/src/tracker/gui/DrawPreviewImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ LabeledDropDown::LabeledDropDown(const std::string& name)
items.push_back(Dropdown::TextItem(name, index++));
}
_dropdown->set_items(items);
_dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
_dropdown->select_item(Dropdown::RawIndex{narrow_cast<long>(_ref.get().enum_index()())});
_dropdown->textfield()->set_text(_ref.get().valueString());

_dropdown->on_select([this](auto index, auto) {
if(index < 0)
if(not index.valid())
return;

try {
_ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index));
_ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index.value));
} catch(...) {}

_dropdown->set_opened(false);
});
}

void LabeledDropDown::update() {
_dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
_dropdown->select_item(Dropdown::RawIndex{narrow_cast<long>(_ref.get().enum_index()())});
}

}
Expand Down
4 changes: 2 additions & 2 deletions Application/src/tracker/gui/LoadingScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class LoadingScene : public Scene {

_textfield = std::make_shared<Dropdown>(Bounds(0, 0, _list->width(), 30));
//_textfield = std::make_shared
_textfield->on_select([this](long_t, const Dropdown::TextItem& item) {
_textfield->on_select([this](auto, const Dropdown::TextItem& item) {
file::Path path;

if (((std::string)item).empty()) {
Expand Down Expand Up @@ -320,4 +320,4 @@ class LoadingScene : public Scene {
void change_folder(const file::Path&);
};

}
}
12 changes: 6 additions & 6 deletions Application/src/tracker/gui/SettingsDropdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ struct SettingsDropdown {
_settings_dropdown.set_origin(Vec2(0, 1));
_value_input.set_origin(Vec2(0, 1));

_settings_dropdown.on_select([&](long_t index, const std::string& name) {
this->selected_setting(index, name, _value_input);
_settings_dropdown.on_select([&](auto index, const std::string& name) {
this->selected_setting(index.value, name, _value_input);
});
_value_input.on_enter([this, on_enter = std::move(on_enter)](){
try {
auto key = _settings_dropdown.items().at(_settings_dropdown.selected_id()).name();
auto key = _settings_dropdown.selected_item().name();
if(GlobalSettings::access_level(key) == AccessLevelType::PUBLIC) {
GlobalSettings::get(key).get().set_value_from_string(_value_input.text());
if(GlobalSettings::get(key).is_type<Color>())
this->selected_setting(_settings_dropdown.selected_id(), key, _value_input);
this->selected_setting(_settings_dropdown.selected_item().ID(), key, _value_input);
if((std::string)key == "auto_apply" || (std::string)key == "auto_train")
{
SETTING(auto_train_on_startup) = false;
Expand All @@ -41,11 +41,11 @@ struct SettingsDropdown {
FormatError("User cannot write setting ", key," (",GlobalSettings::access_level(key).name(),").");
} catch(const std::logic_error&) {
#ifndef NDEBUG
FormatExcept("Cannot set ",_settings_dropdown.items().at(_settings_dropdown.selected_id())," to value ",_value_input.text()," (invalid).");
FormatExcept("Cannot set ",_settings_dropdown.selected_item()," to value ",_value_input.text()," (invalid).");
#endif
} catch(const UtilsException&) {
#ifndef NDEBUG
FormatExcept("Cannot set ",_settings_dropdown.items().at(_settings_dropdown.selected_id())," to value ",_value_input.text()," (invalid).");
FormatExcept("Cannot set ",_settings_dropdown.selected_item()," to value ",_value_input.text()," (invalid).");
#endif
}
});
Expand Down
Loading

0 comments on commit e91abb5

Please sign in to comment.