1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-17 11:56:46 +02:00

Added option to configure dropdown position

This commit is contained in:
Ivan Savenko 2023-11-23 17:19:49 +02:00
parent 0fd966818f
commit 1f0bcbc194
3 changed files with 10 additions and 8 deletions

View File

@ -560,9 +560,11 @@ std::shared_ptr<ComboBox> InterfaceObjectConfigurable::buildComboBox(const JsonN
{ {
logGlobal->debug("Building widget ComboBox"); logGlobal->debug("Building widget ComboBox");
auto position = readPosition(config["position"]); auto position = readPosition(config["position"]);
auto dropDownPosition = readPosition(config["dropDownPosition"]);
auto image = AnimationPath::fromJson(config["image"]); auto image = AnimationPath::fromJson(config["image"]);
auto help = readHintText(config["help"]); auto help = readHintText(config["help"]);
auto result = std::make_shared<ComboBox>(position, image, help, config["dropDown"]); auto result = std::make_shared<ComboBox>(position, image, help, config["dropDown"], dropDownPosition);
if(!config["items"].isNull()) if(!config["items"].isNull())
{ {
for(const auto & item : config["items"].Vector()) for(const auto & item : config["items"].Vector())

View File

@ -67,7 +67,7 @@ void ComboBox::DropDown::Item::clickReleased(const Point & cursorPosition)
dropDown.clickReleased(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), InterfaceObjectConfigurable(LCLICK | HOVER),
comboBox(_comboBox) 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)); addCallback("sliderMove", std::bind(&ComboBox::DropDown::sliderMove, this, std::placeholders::_1));
pos = comboBox.pos; pos = comboBox.pos + dropDownPosition;
build(config); build(config);
@ -156,12 +156,12 @@ void ComboBox::DropDown::setItem(const void * item)
GH.windows().popWindows(1); GH.windows().popWindows(1);
} }
ComboBox::ComboBox(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, const JsonNode & dropDownDescriptor, EShortcut key, bool playerColoredButton): ComboBox::ComboBox(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key, bool playerColoredButton):
CButton(position, defName, help, 0, key, playerColoredButton) CButton(position, defName, help, 0, key, playerColoredButton)
{ {
addCallback([&, dropDownDescriptor]() addCallback([this, dropDownDescriptor, dropDownPosition]()
{ {
GH.windows().createAndPushWindow<ComboBox::DropDown>(dropDownDescriptor, *this); GH.windows().createAndPushWindow<ComboBox::DropDown>(dropDownDescriptor, *this, dropDownPosition);
}); });
} }

View File

@ -32,7 +32,7 @@ class ComboBox : public CButton
friend struct Item; friend struct Item;
public: public:
DropDown(const JsonNode &, ComboBox &); DropDown(const JsonNode &, ComboBox &, Point dropDownPosition);
bool receiveEvent(const Point & position, int eventType) const override; bool receiveEvent(const Point & position, int eventType) const override;
void clickPressed(const Point & cursorPosition) override; void clickPressed(const Point & cursorPosition) override;
@ -54,7 +54,7 @@ class ComboBox : public CButton
void setItem(const void *); void setItem(const void *);
public: public:
ComboBox(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, const JsonNode & dropDownDescriptor, EShortcut key = {}, bool playerColoredButton = false); ComboBox(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key = {}, bool playerColoredButton = false);
//define this callback to fill input vector with data for the combo box //define this callback to fill input vector with data for the combo box
std::function<void(std::vector<const void *> &)> onConstructItems; std::function<void(std::vector<const void *> &)> onConstructItems;