From 1f0bcbc1940ccea0ac8331cca4c7907aecad7a95 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 23 Nov 2023 17:19:49 +0200 Subject: [PATCH] Added option to configure dropdown position --- client/gui/InterfaceObjectConfigurable.cpp | 4 +++- client/widgets/ComboBox.cpp | 10 +++++----- client/widgets/ComboBox.h | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index 9d172d2a3..589b45fe4 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -560,9 +560,11 @@ std::shared_ptr InterfaceObjectConfigurable::buildComboBox(const JsonN { logGlobal->debug("Building widget ComboBox"); auto position = readPosition(config["position"]); + auto dropDownPosition = readPosition(config["dropDownPosition"]); auto image = AnimationPath::fromJson(config["image"]); auto help = readHintText(config["help"]); - auto result = std::make_shared(position, image, help, config["dropDown"]); + auto result = std::make_shared(position, image, help, config["dropDown"], dropDownPosition); + if(!config["items"].isNull()) { for(const auto & item : config["items"].Vector()) diff --git a/client/widgets/ComboBox.cpp b/client/widgets/ComboBox.cpp index eca9fd458..9d98db32e 100644 --- a/client/widgets/ComboBox.cpp +++ b/client/widgets/ComboBox.cpp @@ -67,7 +67,7 @@ void ComboBox::DropDown::Item::clickReleased(const Point & cursorPosition) dropDown.clickReleased(cursorPosition); } -ComboBox::DropDown::DropDown(const JsonNode & config, ComboBox & _comboBox): +ComboBox::DropDown::DropDown(const JsonNode & config, ComboBox & _comboBox, Point dropDownPosition): InterfaceObjectConfigurable(LCLICK | HOVER), comboBox(_comboBox) { @@ -78,7 +78,7 @@ ComboBox::DropDown::DropDown(const JsonNode & config, ComboBox & _comboBox): addCallback("sliderMove", std::bind(&ComboBox::DropDown::sliderMove, this, std::placeholders::_1)); - pos = comboBox.pos; + pos = comboBox.pos + dropDownPosition; build(config); @@ -156,12 +156,12 @@ void ComboBox::DropDown::setItem(const void * item) GH.windows().popWindows(1); } -ComboBox::ComboBox(Point position, const AnimationPath & defName, const std::pair & help, const JsonNode & dropDownDescriptor, EShortcut key, bool playerColoredButton): +ComboBox::ComboBox(Point position, const AnimationPath & defName, const std::pair & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key, bool playerColoredButton): CButton(position, defName, help, 0, key, playerColoredButton) { - addCallback([&, dropDownDescriptor]() + addCallback([this, dropDownDescriptor, dropDownPosition]() { - GH.windows().createAndPushWindow(dropDownDescriptor, *this); + GH.windows().createAndPushWindow(dropDownDescriptor, *this, dropDownPosition); }); } diff --git a/client/widgets/ComboBox.h b/client/widgets/ComboBox.h index dafd496bf..561ad96f9 100644 --- a/client/widgets/ComboBox.h +++ b/client/widgets/ComboBox.h @@ -32,7 +32,7 @@ class ComboBox : public CButton friend struct Item; public: - DropDown(const JsonNode &, ComboBox &); + DropDown(const JsonNode &, ComboBox &, Point dropDownPosition); bool receiveEvent(const Point & position, int eventType) const override; void clickPressed(const Point & cursorPosition) override; @@ -54,7 +54,7 @@ class ComboBox : public CButton void setItem(const void *); public: - ComboBox(Point position, const AnimationPath & defName, const std::pair & help, const JsonNode & dropDownDescriptor, EShortcut key = {}, bool playerColoredButton = false); + ComboBox(Point position, const AnimationPath & defName, const std::pair & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key = {}, bool playerColoredButton = false); //define this callback to fill input vector with data for the combo box std::function &)> onConstructItems;