added initial window with grid layout and css styling

This commit is contained in:
2026-03-22 00:04:59 +01:00
commit e019b31f29
4 changed files with 62 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

2
Makefile Normal file
View File

@@ -0,0 +1,2 @@
main: main.cpp
g++ main.cpp -o build/main `pkg-config --cflags --libs gtkmm-4.0`

51
main.cpp Normal file
View File

@@ -0,0 +1,51 @@
#include <iostream>
#include <gtkmm/button.h>
#include <gtkmm.h>
#include <gtkmm/application.h>
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<Gtk::CssProvider> css_provider;
};
int main(int argc, char **argv)
{
auto app = Gtk::Application::create("org.gtkmm.example");
return app->make_window_and_run<MyWindow>(argc, argv);
}

8
main.css Normal file
View File

@@ -0,0 +1,8 @@
.label{
font-weight: 700;
font-size: 20px;
border: 2px solid red;
}
.grid{
background-color: yellow;
}