commit e019b31f29eea89924b95eb77df54027ebf0bc4c Author: Tim Kainz Date: Sun Mar 22 00:04:59 2026 +0100 added initial window with grid layout and css styling diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2568970 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +main: main.cpp + g++ main.cpp -o build/main `pkg-config --cflags --libs gtkmm-4.0` \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b05afaa --- /dev/null +++ b/main.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + + +class MyWindow : public Gtk::Window +{ + public: + MyWindow(){ + loadCss(); + m_button = Gtk::Button("test"); + m_button.signal_clicked().connect(sigc::mem_fun(*this,&MyWindow::onButtonClicked)); + + m_label = Gtk::Label("Hello!"); + m_label.get_style_context()->add_provider(css_provider,GTK_STYLE_PROVIDER_PRIORITY_USER+1); + m_label.add_css_class("label"); + + m_picture = Gtk::Picture("/usr/share/doc/gtkmm-4.0/reference/html/image1.png"); + m_picture.set_size_request(200,200); + + m_layout_grid = Gtk::Grid(); + m_layout_grid.get_style_context()->add_provider(css_provider,GTK_STYLE_PROVIDER_PRIORITY_USER+1); + m_layout_grid.attach(m_button, 0, 0); + m_layout_grid.attach(m_label, 1, 0); + m_layout_grid.attach(m_picture, 0, 1); + m_layout_grid.add_css_class("grid"); + + set_child(m_layout_grid); + set_size_request(800,600); + } + void onButtonClicked(){ + std::cout<<"hello world"; + std::flush(std::cout); + } + void loadCss(){ + css_provider = Gtk::CssProvider::create(); + css_provider->load_from_path("main.css"); + } + Gtk::Picture m_picture; + Gtk::Button m_button; + Gtk::Label m_label; + Gtk::Grid m_layout_grid; + Glib::RefPtr css_provider; +}; + +int main(int argc, char **argv) +{ + auto app = Gtk::Application::create("org.gtkmm.example"); + return app->make_window_and_run(argc, argv); +} diff --git a/main.css b/main.css new file mode 100644 index 0000000..f61b8ab --- /dev/null +++ b/main.css @@ -0,0 +1,8 @@ +.label{ + font-weight: 700; + font-size: 20px; + border: 2px solid red; +} +.grid{ + background-color: yellow; +} \ No newline at end of file