diff --git a/examples/widgets_example.hpp b/examples/widgets_example.hpp index 3ecbb33..1dd4bb8 100644 --- a/examples/widgets_example.hpp +++ b/examples/widgets_example.hpp @@ -101,6 +101,14 @@ namespace WidgetsExample progress->setCaption("Loading"); progress->setWidth(100); + std::vector button_names{"0", "25", "50", "75", "100", "-1", "+1"}; + messageBox = std::make_unique("Change progression", + "Set progression value", + button_names); + messageBox->setMovable(true); + messageBox->setFrameSize(1); + messageBox->addActionListener(this); + guisanLogoImage.reset(gcn::Image::load("guisan-logo.png")); guisanLogoIcon = std::make_unique(guisanLogoImage.get()); window->add(guisanLogoIcon.get()); @@ -138,6 +146,7 @@ namespace WidgetsExample top->add(nestedScrollArea.get(), 440, 350); top->add(progress.get(), 580, 200); + top->add(messageBox.get(), 480, 220); } ~MainContainer() = default; @@ -159,6 +168,20 @@ namespace WidgetsExample label->adjustSize(); } } + else if (actionEvent.getSource() == messageBox.get()) + { + switch (messageBox->getClickedButton()) + { + default: + case 0: progress->setValue(0); break; + case 1: progress->setValue(25); break; + case 2: progress->setValue(50); break; + case 3: progress->setValue(75); break; + case 4: progress->setValue(100); break; + case 5: progress->setValue(progress->getValue() - 1); break; + case 6: progress->setValue(progress->getValue() + 1); break; + } + } } private: @@ -186,6 +209,7 @@ namespace WidgetsExample std::unique_ptr slider; // A slider std::unique_ptr image; // An image for the icon std::unique_ptr window; + std::unique_ptr messageBox; std::unique_ptr progress; std::unique_ptr guisanLogoImage; std::unique_ptr guisanLogoIcon; diff --git a/include/guisan/widgets/messagebox.hpp b/include/guisan/widgets/messagebox.hpp index 0271a0c..26cff60 100644 --- a/include/guisan/widgets/messagebox.hpp +++ b/include/guisan/widgets/messagebox.hpp @@ -57,15 +57,14 @@ #ifndef GCN_MESSAGEBOX_HPP #define GCN_MESSAGEBOX_HPP -#include - -#include "guisan/graphics.hpp" -#include "guisan/mouselistener.hpp" #include "guisan/platform.hpp" -#include "guisan/widgets/window.hpp" #include "guisan/widgets/button.hpp" #include "guisan/widgets/label.hpp" -#include "guisan/widgets/icon.hpp" +#include "guisan/widgets/window.hpp" + +#include +#include +#include namespace gcn { @@ -75,25 +74,38 @@ namespace gcn class GCN_CORE_DECLSPEC MessageBox : public Window { public: - /** * Constructor. - * This version only has a single button labeled "OK". + * This version only has a single button labeled "OK". * * @param caption the MessageBox caption. * @param message the message to display in the MessageBox */ MessageBox(const std::string& caption, const std::string& message); - + /** * Constructor. * * @param caption the MessageBox caption. * @param message the message to display in the MessageBox - * @param buttons strings to display as button captions + * @param button_captions strings to display as button captions * @param size length of the buttons array */ - MessageBox(const std::string& caption, const std::string& message, const std::string *buttons, int size); + MessageBox(const std::string& caption, + const std::string& message, + const std::string* button_captions, + int size); + + /** + * Constructor. + * + * @param caption the MessageBox caption. + * @param message the message to display in the MessageBox + * @param button_captions strings to display as button captions + */ + MessageBox(const std::string& caption, + const std::string& message, + const std::vector& button_captions); /** * Destructor. @@ -107,20 +119,6 @@ namespace gcn */ int getClickedButton() const; - /** - * Sets the MessageBox caption. - * - * @param caption the MessageBox caption. - */ - void setCaption(const std::string& caption); - - /** - * Gets the MessageBox caption. - * - * @return the MessageBox caption. - */ - const std::string& getCaption() const; - /** * Sets the position for the button(s) in the MessageBox. * @@ -136,91 +134,25 @@ namespace gcn Graphics::Alignment getButtonAlignment() const; /** - * Sets the padding of the window which is the distance between the - * window border and the content. - * - * @param padding the padding value. - */ - void setPadding(unsigned int padding); - - /** - * Gets the padding. - * - * @return the padding value. - */ - unsigned int getPadding() const; - - /** - * Sets the title bar height. - * - * @param height the title height value. - */ - void setTitleBarHeight(unsigned int height); - - /** - * Gets the title bar height. - * - * @return the title bar height. - */ - unsigned int getTitleBarHeight(); - - /** - * Check if the window is movable. - * - * @return true or false. - */ - bool isMovable() const; - - /** - * Sets the MessageBox to be opaque. If it's not opaque, the content area - * will not be filled with a color. - * - * @param opaque true or false. - */ - void setOpaque(bool opaque); - - /** - * Checks if the MessageBox is opaque. - * - * @return true or false. - */ - bool isOpaque(); - - /** - * Add this MessageBox to a parent container, centered both horizontally and vertically - * If instead, you want to place it somewhere else, use Container::add(). + * Add this MessageBox to a parent container, + * centered both horizontally and vertically. + * If instead, you want to place it somewhere else, use Container::add(). * * @param container parent container */ void addToContainer(Container* container); - // Inherit from Window - - /** - * Resizes the container to fit the content exactly. - */ - void resizeToContent() override; - - // Inherited from Widget - - Rectangle getChildrenArea() override; - void draw(Graphics* graphics) override; - // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; - void mouseDragged(MouseEvent& mouseEvent) override; void mouseReleased(MouseEvent& mouseEvent) override; protected: - std::string mMessage; - int mNbButtons; Graphics::Alignment mButtonAlignment = Graphics::Alignment::Left; int mClickedButton = -1; - Button **mButtons = nullptr; - Label *mLabel = nullptr; + std::vector> mButtons; + std::unique_ptr