There are two widgets in maemomm for text entry, both of which are inherited from gtkmm equivalents, but with extra Hildon-specific additions.
Hildon::Entry
is a single-line text entry field. It is derived from Gtk::Entry
, providing additional features specific to the Hildon framework. For example, when constructing a Hildon::Entry
you can specify a size such as finger or thumb height.
Hildon::TextView
is a multi-line text entry box. It is derived from Gtk::TextView
, providing additional features specific to the Hildon framework. For example, placeholder text can be set which is only shown when the widget is not focused and is empty, but which is otherwise ignored.
The Hildon::Entry
class shows a single-line text entry field, enabling the user to enter freeform text. You can set the placeholder text that is shown when the widget is not focused and is empty. Hildon::Entry
is derived from Gtk::Entry
.
This example shows a simple window that contains an entry, a button, and a label. The entry has placeholder text set, which disappears when text is entered into the widget. When the button is clicked, or the entry is activated, the current text in the entry is sent to standard output.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H #define _MAEMOMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> #include <hildonmm/button.h> #include <hildonmm/entry.h> #include <gtkmm/box.h> #include <gtkmm/buttonbox.h> #include <gtkmm/table.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); private: // Signal handlers: void on_button_clicked(); void on_entry_activated(); // Child widgets: Gtk::VBox vbox_; Gtk::HButtonBox buttonbox_; Hildon::Button button_; Hildon::Entry entry_; }; #endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h" #include <iostream> ExampleWindow::ExampleWindow() : vbox_(false, 8), // TODO: Gtk::Hildon::SIZE_DEFAULT ? button_(Gtk::Hildon::SIZE_FULLSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT, Hildon::BUTTON_ARRANGEMENT_VERTICAL, "Click Me", "to print text in entry"), entry_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT) { set_title("Hildon::Entry Example"); entry_.set_placeholder("This is placeholder text"); buttonbox_.pack_start(button_); vbox_.pack_start(buttonbox_, Gtk::PACK_SHRINK); vbox_.pack_start(entry_, Gtk::PACK_SHRINK); add(vbox_); button_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button_clicked)); entry_.signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_entry_activated)); show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_button_clicked() { std::cout << "Button clicked. Current entry text=\"" << entry_.get_text() << "\"." << std::endl; } void ExampleWindow::on_entry_activated() { std::cout << "Entry activated. Current text=\"" << entry_.get_text() << "\"." << std::endl; }
File: main.cc
#include <hildonmm.h> #include "examplewindow.h" int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); Hildon::init(); ExampleWindow window; kit.run(window); //Shows the window and returns when it is closed. return 0; }
The Hildon::TextView
class is the multi-line equivalent of the Hildon::Entry
class. As with Hildon::Entry
, Hildon:TextView
is derived from its gtkmm equivalent, in this case Gtk::TextView
. The placeholder text functionality that exists in Hildon::Entry
, where text can be shown by the widget when it is empty and the widget is not focused, is also present in Hildon::TextView
.
![]() |
Note |
---|---|
Although |
This example shows a simple window that contains a text view, a button, and a label. The text view has placeholder text set, which disappears when text is entered into the widget. Clicking the button, or activating the text view, sends the current text in the view to standard output.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H #define _MAEMOMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> #include <hildonmm/button.h> #include <hildonmm/text-view.h> #include <gtkmm/table.h> #include <gtkmm/label.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); private: // Signal handlers: void on_button_clicked(); // Child widgets: Gtk::VBox vbox_; Hildon::Button button_; Hildon::TextView textview_; }; #endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h" #include <iostream> ExampleWindow::ExampleWindow() : button_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT, Hildon::BUTTON_ARRANGEMENT_VERTICAL, "Click Me", "to print text in textview") { set_title("Hildon::TextView Example"); vbox_.pack_start(button_, Gtk::PACK_SHRINK); vbox_.pack_start(textview_); textview_.set_placeholder("This is placeholder text"); add(vbox_); button_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button_clicked)); show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_button_clicked() { std::cout << "Button clicked. Current textview text=\"" << textview_.get_buffer()->get_text() << "\"." << std::endl; }
File: main.cc
#include <hildonmm.h> #include "examplewindow.h" int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); Hildon::init(); ExampleWindow window; kit.run(window); // Shows the window and returns when it is closed. return 0; }