TranslationSpinRow(View *view, Gtk::TreeView *rfo_tree, const char *box_name) : m_inhibit_update(false), m_view(view) { view->m_builder->get_widget (box_name, m_box); for (uint i = 0; i < 3; i++) { m_box->add (*new Gtk::Label (axis_names[i])); m_xyz[i] = new Gtk::SpinButton(); m_xyz[i]->set_numeric(); m_xyz[i]->set_digits (1); m_xyz[i]->set_increments (0.5, 10); m_xyz[i]->set_range(-500.0, +500.0); m_box->add (*m_xyz[i]); m_xyz[i]->signal_value_changed().connect (sigc::bind(sigc::mem_fun(*this, &TranslationSpinRow::spin_value_changed), (int)i)); /* Add statusbar message */ stringstream oss; oss << "Move object in " << axis_names[i] << "-direction (mm)"; m_view->add_statusbar_msg(m_xyz[i], oss.str().c_str()); } selection_changed(); m_box->show_all(); rfo_tree->get_selection()->signal_changed().connect (sigc::mem_fun(*this, &TranslationSpinRow::selection_changed)); }
int main(int argc, char *argv[]) { // make window Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "tutorial2"); Gtk::Window window; window.set_default_size(400,200); window.set_title("Tutorial 2"); // This creates a vertical box container with 0 padding Gtk::Box *vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); window.add(*vbox); // creates menu bar Gtk::MenuBar *menubar = Gtk::manage(new Gtk::MenuBar()); vbox->pack_start(*menubar, Gtk::PACK_SHRINK, 0); // create menu items Gtk::MenuItem *menuitem_file = Gtk::manage(new Gtk::MenuItem("_File", true)); menubar->append(*menuitem_file); Gtk::Menu *filemenu = Gtk::manage(new Gtk::Menu()); menuitem_file->set_submenu(*filemenu); Gtk::MenuItem *menuitem_quit = Gtk::manage(new Gtk::MenuItem("_Quit", true)); filemenu->append(*menuitem_quit); // create grid container with border width 10 // and add it to the new cell of the vertical box Gtk::Grid *grid = Gtk::manage(new Gtk::Grid); grid->set_border_width(10); vbox->add(*grid); // create button Gtk::Button *b1 = Gtk::manage(new Gtk::Button("Button 1")); b1->set_hexpand(true); // take up all unused space horizontally b1->set_vexpand(true); // take up all unused space vertically // possition 0(x), 0(y), span 1 cell wide and 2 cells down grid->attach(*b1, 0, 0, 1, 2); Gtk::Button *b2 = Gtk::manage(new Gtk::Button("Button 2")); grid->attach(*b2, 1, 0, 1, 1); Gtk::Button *b3 = Gtk::manage(new Gtk::Button("Button 3")); grid->attach(*b3, 1, 1, 1, 1); vbox->show_all(); return app->run(window); }
myWindow::myWindow() { set_default_size(400, 200); set_title("Tutorial 3"); Gtk::Box *vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); add(*vbox); Gtk::MenuBar *menubar = Gtk::manage(new Gtk::MenuBar()); vbox->pack_start(*menubar, Gtk::PACK_SHRINK, 0); Gtk::MenuItem *menuitem_file = Gtk::manage(new Gtk::MenuItem("_File", true)); menubar->append(*menuitem_file); Gtk::Menu *filemenu = Gtk::manage(new Gtk::Menu()); menuitem_file->set_submenu(*filemenu); Gtk::MenuItem *menuitem_quit = Gtk::manage(new Gtk::MenuItem("_Quit", true)); menuitem_quit->signal_activate().connect(sigc::mem_fun(*this, &myWindow::on_quit_click)); filemenu->append(*menuitem_quit); Gtk::Grid *grid = Gtk::manage(new Gtk::Grid); grid->set_border_width(10); vbox->add(*grid); Gtk::Button *b1 = Gtk::manage(new Gtk::Button("Big Button 1")); b1->set_hexpand(true); b1->set_vexpand(true); b1->signal_clicked().connect(sigc::mem_fun(*this, &myWindow::on_big_button1_click)); grid->attach(*b1, 0, 0, 1, 2); Gtk::Button *b2 = Gtk::manage(new Gtk::Button("Button 2")); b2->signal_clicked().connect(sigc::mem_fun(*this, &myWindow::on_button2_click)); grid->attach(*b2, 1, 0, 1, 1); Gtk::Button *b3 = Gtk::manage(new Gtk::Button("Button 3")); b3->signal_clicked().connect(sigc::mem_fun(*this, &myWindow::on_button3_click)); grid->attach(*b3, 1, 1, 1, 1); vbox->show_all(); }
void GstPropertiesModule::append_property(const std::shared_ptr<GValueBase>& value_base, const std::string &prop_name) { auto e = std::dynamic_pointer_cast<ElementModel>(controller->get_selected_object()); if (!e) return; auto klass = controller->get_klass(e->get_type_name()); if (!klass) return; auto prop = klass.get().get_property(prop_name); if (!prop) return; Gtk::Box *hbox = new Gtk::Box (Gtk::ORIENTATION_HORIZONTAL, 0); hbox->set_data("property-name", g_strdup (prop_name.c_str()), g_free); Gtk::Label *lbl = Gtk::manage(new Gtk::Label(prop_name)); lbl->set_tooltip_text(prop->get_blurb()); Gtk::Button *btn = Gtk::manage(new Gtk::Button("Refresh")); btn->signal_clicked().connect([this, prop_name] {request_selected_element_property(prop_name);}); hbox->pack_start(*lbl, false, false); auto value_widget = value_base->get_widget(); value_base->set_sensitive(prop.get().get_flags() & G_PARAM_WRITABLE); hbox->pack_start(*value_widget, true, true); hbox->pack_start(*btn, false, false); properties_box->pack_start(*hbox); hbox->show_all(); }
bool addWidgets(Gtk::Box* iBox) { if (mBox != NULL) return false; mBox = Gtk::manage(new Gtk::VBox()); Gtk::Box* box = Gtk::manage(new Gtk::HBox()); mToggleButton = Gtk::manage(new Gtk::ToggleButton(" ")); Gdk::Color color; color.set_rgb_p(mAttributes.mColor[0], mAttributes.mColor[1], mAttributes.mColor[2]); mToggleButton->modify_bg(Gtk::STATE_ACTIVE, color); color.set_rgb_p((mAttributes.mColor[0]+1)/2, (mAttributes.mColor[1]+1)/2, (mAttributes.mColor[2]+1)/2); mToggleButton->modify_bg(Gtk::STATE_PRELIGHT, color); color.set_rgb_p(0.8, 0.8, 0.8); mToggleButton->modify_bg(Gtk::STATE_NORMAL, color); mToggleButton->signal_toggled().connect (sigc::mem_fun(*this, &Helper::onToggleButton)); mToggleButton->set_active(true); box->pack_start(*(mToggleButton), false, false); Gtk::Label* label = Gtk::manage(new Gtk::Label(mAttributes.mLabel)); box->pack_start(*label, false, false); if (mViewId != 1) { Gtk::Button* cancelButton = Gtk::manage(new Gtk::Button("X")); box->pack_start(*cancelButton, false, false); cancelButton->signal_clicked().connect (sigc::mem_fun(*this, &Helper::onRemoveButton)); } Gtk::Button* button = Gtk::manage(new Gtk::Button("save")); button->signal_clicked().connect (sigc::mem_fun(*this, &Helper::onSaveButton)); box->pack_start(*button, false, false); mBox->pack_start(*box, false, false); box = Gtk::manage(new Gtk::HBox()); std::vector<int> ids; std::vector<std::string> labels; ids = { MeshRenderer::ColorModeFlat, MeshRenderer::ColorModeHeight, MeshRenderer::ColorModeRange, MeshRenderer::ColorModeNormal, MeshRenderer::ColorModeCamera }; labels = { "Flat", "Height", "Range", "Normal", "Camera" }; Gtk::ComboBox* combo = gtkmm::RendererBase::createCombo(mAttributes.mColorMode, labels, ids); combo->signal_changed().connect([this]{this->mRenderer->requestDraw();}); box->pack_start(*combo, false, false); ids = { MeshRenderer::MeshModePoints, MeshRenderer::MeshModeWireframe, MeshRenderer::MeshModeFilled }; labels = { "Points", "Wireframe", "Filled" }; combo = gtkmm::RendererBase::createCombo(mAttributes.mMeshMode, labels, ids); combo->signal_changed().connect([this]{this->mRenderer->requestDraw();}); box->pack_start(*combo, false, false); Gtk::HScale* slider = gtkmm::RendererBase::createSlider(mAttributes.mPointSize, 0.1, 10, 0.1); slider->signal_value_changed().connect([this]{this->mRenderer->requestDraw();}); box->pack_start(*slider, true, true); mBox->pack_start(*box, false, false); box = Gtk::manage(new Gtk::HBox()); label = Gtk::manage(new Gtk::Label("Z Rng")); box->pack_start(*label,false,false); slider = gtkmm::RendererBase::createSlider(mAttributes.mMinZ, -1, 2, 0.01); slider->signal_value_changed().connect([this]{this->mRenderer->requestDraw();}); box->pack_start(*slider, true, true); slider = gtkmm::RendererBase::createSlider(mAttributes.mMaxZ, -1, 2, 0.01); slider->signal_value_changed().connect([this]{this->mRenderer->requestDraw();}); box->pack_start(*slider, true, true); mBox->pack_start(*box, false, false); mBox->pack_start(*Gtk::manage(new Gtk::HSeparator())); mBox->show_all(); iBox->pack_start(*mBox, false, false); return true; }
//------------------------------------------------------------------------------ bool mforms::gtk::ToolBarImpl::create_tool_item(mforms::ToolBarItem *item, ToolBarItemType type) { Gtk::Widget *w = 0; switch (type) { case mforms::TextActionItem: case mforms::ActionItem: case mforms::SwitcherItem: { Gtk::Button *btn = Gtk::manage(new Gtk::Button()); btn->set_focus_on_click(false); btn->set_border_width(0); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), btn, item)); if (type == mforms::SwitcherItem) btn->set_always_show_image(true); w = btn; break; } case mforms::SegmentedToggleItem: case mforms::ToggleItem: { Gtk::ToggleButton *btn = Gtk::manage(new Gtk::ToggleButton()); btn->set_focus_on_click(false); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_toggled().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), btn, item)); btn->set_inconsistent(false); w = btn; break; } case mforms::SeparatorItem: { Gtk::Separator *sep = new Gtk::Separator(Gtk::ORIENTATION_VERTICAL); w = sep; break; } case mforms::SearchFieldItem: { #if GTK_VERSION_GE(2, 16) Gtk::Entry *entry = Gtk::manage(new Gtk::Entry()); w = entry; entry->set_icon_from_stock(Gtk::Stock::FIND); #else Gtk::Box *hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0)); w = hbox; Gtk::Image *image = Gtk::manage(new Gtk::Image(Gtk::Stock::FIND, Gtk::ICON_SIZE_MENU)); Gtk::Entry *entry = Gtk::manage(new Gtk::Entry()); hbox->pack_start(*image, false, true); hbox->pack_start(*entry, true, true); hbox->set_data("entry", entry); hbox->show_all(); #endif entry->signal_activate().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), entry, item)); break; } case mforms::TextEntryItem: { Gtk::Box *hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0)); w = hbox; Gtk::Entry *entry = Gtk::manage(new Gtk::Entry()); hbox->pack_start(*entry, true, true); hbox->set_data("entry", entry); hbox->show_all(); entry->signal_activate().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), entry, item)); break; } case mforms::FlatSelectorItem: case mforms::SelectorItem: { Gtk::ComboBoxText *ct = Gtk::manage(new Gtk::ComboBoxText()); ct->signal_changed().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), ct, item)); w = ct; break; } case mforms::ColorSelectorItem: { if (!color_combo_columns) { color_combo_columns = new ColorComboColumns(); } Gtk::ComboBox *ct = Gtk::manage(new Gtk::ComboBox()); ct->pack_start(color_combo_columns->image); ct->signal_changed().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), ct, item)); w = ct; break; } case mforms::ExpanderItem: case mforms::LabelItem: { Gtk::Label *label = Gtk::manage(new Gtk::Label("", 0.0, 0.5)); w = label; break; } case mforms::ImageBoxItem: { Gtk::Image *image = Gtk::manage(new Gtk::Image()); w = image; break; } case mforms::TitleItem: { Gtk::Label *label = Gtk::manage(new Gtk::Label("", 0.0, 0.5)); w = label; auto provider = Gtk::CssProvider::create(); provider->load_from_data("* { color: #333; font-weight: bold; }"); w->get_style_context()->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_USER); break; } } if (w) { w->show(); } else logError("create_tool_item, widget is 0 for passed type %i\n", type); item->set_data(w); return w != 0; }