correct menu_bar.ui
This commit is contained in:
parent
a328b57c3c
commit
77b14d2fe3
@ -6,15 +6,15 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace learn_gtkmm4 {
|
||||
HelloWorld::HelloWorld() : m_button("Hello world!") {
|
||||
HelloWorld::HelloWorld(const Glib::RefPtr<Gio::Menu>& menuModel) :
|
||||
m_VBox(Gtk::Orientation::VERTICAL), m_menu_bar(menuModel), m_button("Hello world!") {
|
||||
set_title("Hello world!");
|
||||
set_default_size(720, 1280);
|
||||
add_action("Open");
|
||||
add_action("Quit");
|
||||
set_show_menubar();
|
||||
set_default_size(1280, 720);
|
||||
m_button.set_margin(10);
|
||||
m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked));
|
||||
set_child(m_button);
|
||||
m_VBox.append(m_menu_bar);
|
||||
m_VBox.append(m_button);
|
||||
set_child(m_VBox);
|
||||
}
|
||||
|
||||
void HelloWorld::on_button_clicked() {
|
||||
|
@ -9,18 +9,21 @@
|
||||
#include <gtkmm/glarea.h>
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/applicationwindow.h>
|
||||
#include <gtkmm/popovermenubar.h>
|
||||
#include <gtkmm/popovermenu.h>
|
||||
|
||||
namespace learn_gtkmm4 {
|
||||
|
||||
class HelloWorld : public Gtk::ApplicationWindow {
|
||||
public:
|
||||
HelloWorld();
|
||||
explicit HelloWorld(const Glib::RefPtr<Gio::Menu>& menuModel);
|
||||
~HelloWorld() override = default;
|
||||
|
||||
protected:
|
||||
void on_button_clicked();
|
||||
|
||||
Gtk::Box m_VBox;
|
||||
Gtk::PopoverMenuBar m_menu_bar;
|
||||
Gtk::Button m_button;
|
||||
Gtk::GLArea gl_area;
|
||||
};
|
||||
|
19
main.cpp
19
main.cpp
@ -1,7 +1,24 @@
|
||||
#include "hello_world.hpp"
|
||||
#include <gtkmm/application.h>
|
||||
#include <gtkmm/builder.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
auto app = Gtk::Application::create("org.gtkmm.example");
|
||||
return app->make_window_and_run<learn_gtkmm4::HelloWorld>(argc, argv);
|
||||
|
||||
const auto menu_model = []() -> Glib::RefPtr<Gio::Menu> {
|
||||
try {
|
||||
const auto builder = Gtk::Builder::create_from_file("menu_bar.ui");
|
||||
return std::dynamic_pointer_cast<Gio::Menu>(builder->get_object("menu"));
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
}();
|
||||
if (menu_model == nullptr) {
|
||||
std::cerr << "Menu model object is null. Down-cast failed.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return app->make_window_and_run<learn_gtkmm4::HelloWorld>(argc, argv, menu_model);
|
||||
}
|
||||
|
58
menu_bar.ui
Normal file
58
menu_bar.ui
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gio" version="2.0"/>
|
||||
<menu id="menu">
|
||||
<submenu id="file_submenu">
|
||||
<attribute name="label" translatable="yes" context=""Files" menu used here">Fichiers</attribute>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="action">file.new</attribute>
|
||||
<attribute name="icon">document-new</attribute>
|
||||
<attribute name="label" translatable="yes" context="It means New File in french">Nouveau fichier</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="action">file.open</attribute>
|
||||
<attribute name="icon">document-open</attribute>
|
||||
<attribute name="label" translatable="yes" context="It means Open in french">Ouvrir</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="action">file.save</attribute>
|
||||
<attribute name="icon">document-save</attribute>
|
||||
<attribute name="label" translatable="yes" context="It means Save">Enregistrer</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="action">file.save_as</attribute>
|
||||
<attribute name="icon">document-save-as</attribute>
|
||||
<attribute name="label" translatable="yes" context="It means Save">Enregistrer sous</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="action">file.quit</attribute>
|
||||
<attribute name="icon">application-exit</attribute>
|
||||
<attribute name="label" translatable="yes" context="It means Quit">Quitter</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</submenu>
|
||||
<submenu id="edit_submenu">
|
||||
<attribute name="label" translatable="yes" context="It means Edit">Éditer</attribute>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="action">edit.copy</attribute>
|
||||
<attribute name="icon">edit-copy</attribute>
|
||||
<attribute name="label" translatable="yes">Copier</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="action">edit.cut</attribute>
|
||||
<attribute name="icon">edit-cut</attribute>
|
||||
<attribute name="label" translatable="yes">Couper</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="action">edit.paste</attribute>
|
||||
<attribute name="icon">edit-paste</attribute>
|
||||
<attribute name="label" translatable="yes">Coller</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</submenu>
|
||||
</menu>
|
||||
</interface>
|
Loading…
Reference in New Issue
Block a user