From: Mikko Rasa Date: Mon, 21 Aug 2023 14:35:13 +0000 (+0300) Subject: Add an example of dialogs in the widget demo program X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=72de2dce79c76da9931e6bc80e59743526cc18fe;p=libs%2Fgltk.git Add an example of dialogs in the widget demo program --- diff --git a/basic.skin b/basic.skin index 73f60c4..5f9f0b1 100644 --- a/basic.skin +++ b/basic.skin @@ -404,6 +404,16 @@ style "panel" part "children"; }; +style "dialog" +{ + part + { + graphic NORMAL "grey_beveled"; + }; + + part "children"; +}; + style "root" { part "children"; diff --git a/examples/widgetdemo/dialogdemo.cpp b/examples/widgetdemo/dialogdemo.cpp new file mode 100644 index 0000000..63fb68e --- /dev/null +++ b/examples/widgetdemo/dialogdemo.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include "dialogdemo.h" + +using namespace std; +using namespace Msp; + +class PromptDialog: public GLtk::Dialog +{ +public: + sigc::signal signal_text_response; + +private: + GLtk::Entry ent_text; + +public: + PromptDialog(); + +protected: + void on_response(int) override; +}; + + +DialogDemo::DialogDemo() +{ + get_or_create_layout(); + + GLtk::Button *btn_prompt = new GLtk::Button("Enter some text"); + add(*btn_prompt); + btn_prompt->signal_clicked.connect(sigc::mem_fun(this, &DialogDemo::button_clicked)); + + add(lbl_text); + layout->add_constraint(lbl_text, GLtk::Layout::BELOW, *btn_prompt); + layout->set_expand(lbl_text, true, false); +} + +void DialogDemo::button_clicked() +{ + GLtk::Root *root = find_ancestor(); + PromptDialog *dialog = GLtk::AutoDialog::create(); + root->add(*dialog); + root->get_or_create_layout().set_gravity(*dialog, 0, 0); + dialog->signal_text_response.connect(sigc::mem_fun(this, &DialogDemo::got_response)); +} + +void DialogDemo::got_response(const string &text) +{ + lbl_text.set_text(text); +} + + +PromptDialog::PromptDialog() +{ + get_or_create_layout(); + + ent_text.set_edit_size(50, 1); + add(ent_text); + layout->set_expand(ent_text, true, false); + + GLtk::Button *btn_ok = new GLtk::Button("OK"); + add_button(*btn_ok, 1); + layout->add_constraint(*btn_ok, GLtk::Layout::FAR_BELOW, ent_text); + layout->set_gravity(*btn_ok, 1, -1); +} + +void PromptDialog::on_response(int) +{ + signal_text_response.emit(ent_text.get_text()); +} diff --git a/examples/widgetdemo/dialogdemo.h b/examples/widgetdemo/dialogdemo.h new file mode 100644 index 0000000..4e5f770 --- /dev/null +++ b/examples/widgetdemo/dialogdemo.h @@ -0,0 +1,20 @@ +#ifndef DIALOGDEMO_H_ +#define DIALOGDEMO_H_ + +#include +#include + +class DialogDemo: public Msp::GLtk::Panel +{ +private: + Msp::GLtk::Label lbl_text; + +public: + DialogDemo(); + +private: + void button_clicked(); + void got_response(const std::string &); +}; + +#endif diff --git a/examples/widgetdemo/widgetdemo.cpp b/examples/widgetdemo/widgetdemo.cpp index 52545a2..b1482e7 100644 --- a/examples/widgetdemo/widgetdemo.cpp +++ b/examples/widgetdemo/widgetdemo.cpp @@ -1,6 +1,7 @@ #include #include #include "buttondemo.h" +#include "dialogdemo.h" #include "dropdowndemo.h" #include "entrydemo.h" #include "toggledemo.h" @@ -25,6 +26,7 @@ WidgetDemo::WidgetDemo(int, char **): root_layout.set_expand(selector, false, true); add_demo("Button", new ButtonDemo); + add_demo("Dialog", new DialogDemo); add_demo("Dropdown", new DropdownDemo); add_demo("Entry", new EntryDemo); add_demo("Toggle", new ToggleDemo);