From 30582215002890481b293d8da978aca9a6994eba Mon Sep 17 00:00:00 2001 From: daleclack Date: Wed, 20 Mar 2024 16:23:36 +0800 Subject: [PATCH] Replace control button icon to char --- Gtk4/gtk160_wayland_test/res/style.css | 3 ++- Gtk4/gtk160_wayland_test/src/main.cpp | 25 ++++++++----------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Gtk4/gtk160_wayland_test/res/style.css b/Gtk4/gtk160_wayland_test/res/style.css index 8c2a340..bd13f42 100644 --- a/Gtk4/gtk160_wayland_test/res/style.css +++ b/Gtk4/gtk160_wayland_test/res/style.css @@ -5,7 +5,8 @@ headerbar{ margin:0px; } -button{ +.ctrl_btn{ min-height: 8px; margin: 0px; + font-weight:900; } \ No newline at end of file diff --git a/Gtk4/gtk160_wayland_test/src/main.cpp b/Gtk4/gtk160_wayland_test/src/main.cpp index 256edd7..3dce38e 100644 --- a/Gtk4/gtk160_wayland_test/src/main.cpp +++ b/Gtk4/gtk160_wayland_test/src/main.cpp @@ -1,4 +1,8 @@ #include "MainWin.h" +#include "../json_nlohmann/json.hpp" +#include + +using json = nlohmann::json; static void gtkmain(GtkApplication *app, gpointer user_data) { @@ -15,13 +19,13 @@ static void gtkmain(GtkApplication *app, gpointer user_data) gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(header), FALSE); // Add a close button - btn_close = gtk_button_new(); - + btn_close = gtk_button_new_with_label("\u00d7"); + gtk_widget_add_css_class(btn_close, "ctrl_btn"); gtk_header_bar_pack_start(GTK_HEADER_BAR(header), btn_close); // Add a minimize button - btn_mini = gtk_button_new(); - + btn_mini = gtk_button_new_with_label("-"); + gtk_widget_add_css_class(btn_mini, "ctrl_btn"); gtk_header_bar_pack_start(GTK_HEADER_BAR(header), btn_mini); // Add style for headerbar @@ -35,19 +39,6 @@ static void gtkmain(GtkApplication *app, gpointer user_data) g_signal_connect_swapped(btn_mini, "clicked", G_CALLBACK(gtk_window_minimize), window); // show the window gtk_window_present(GTK_WINDOW(window)); - - // Get Scale factor - GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(window)); - double scale = gdk_surface_get_scale(surface); - g_print("%f\n", scale); - - img_close = gtk_image_new_from_icon_name("win_close"); - gtk_image_set_pixel_size(GTK_IMAGE(img_close), 12 / scale); - gtk_button_set_child(GTK_BUTTON(btn_close), img_close); - - img_mini = gtk_image_new_from_icon_name("win_minimize"); - gtk_image_set_pixel_size(GTK_IMAGE(img_mini), 12 / scale); - gtk_button_set_child(GTK_BUTTON(btn_mini), img_mini); } int main(int argc, char **argv)