mirror of https://github.com/daleclack/My_GtkUi
Add MyTitleBar class
This commit is contained in:
parent
e43ee62685
commit
aa221886b1
|
@ -25,14 +25,14 @@ link_directories (${GTK_LIBRARY_DIRS})
|
|||
|
||||
set(SOURCES src/core/main.cpp src/core/MainWin.cpp src/core/MyStack.cpp
|
||||
src/core/MyItem.cpp src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp
|
||||
src/ui/AppView.cpp src/file_app/FileColumnView.cpp src/file_app/FileGridView.cpp
|
||||
src/file_app/FileWindow.cpp src/game_app/GameApp.cpp src/calc_app/calc.cpp
|
||||
src/calc_app/CalcApp.cpp src/run_app/RunApp.cpp src/draw_app/DrawApp.cpp
|
||||
src/game24_app/Game24.cpp src/game24_app/Game24App.cpp src/text_app/TextEditor.cpp
|
||||
src/text_app/MyInfoBar.cpp src/image_app/ImageApp.cpp src/image_app/MyImage.cpp
|
||||
src/mine_app/MineSweeper.cpp src/mine_app/MineCell.cpp src/mine_app/InputBox.cpp
|
||||
src/mine_app/ScoresItem.cpp src/mine_app/ScoresWin.cpp src/media_app/LyricsParser.cpp
|
||||
src/media_app/MyMediaPlayer.cpp src/media_app/MediaItem.cpp)
|
||||
src/ui/AppView.cpp src/ui/MyTitleBar.cpp src/file_app/FileColumnView.cpp
|
||||
src/file_app/FileGridView.cpp src/file_app/FileWindow.cpp src/game_app/GameApp.cpp
|
||||
src/calc_app/calc.cpp src/calc_app/CalcApp.cpp src/run_app/RunApp.cpp
|
||||
src/draw_app/DrawApp.cpp src/game24_app/Game24.cpp src/game24_app/Game24App.cpp
|
||||
src/text_app/TextEditor.cpp src/text_app/MyInfoBar.cpp src/image_app/ImageApp.cpp
|
||||
src/image_app/MyImage.cpp src/mine_app/MineSweeper.cpp src/mine_app/MineCell.cpp
|
||||
src/mine_app/InputBox.cpp src/mine_app/ScoresItem.cpp src/mine_app/ScoresWin.cpp
|
||||
src/media_app/LyricsParser.cpp src/media_app/MyMediaPlayer.cpp src/media_app/MediaItem.cpp)
|
||||
|
||||
#Compile resources with GCR_CMake
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/* A slim headerbar style for widgets */
|
||||
.mytitlebar {
|
||||
min-height: 10px;
|
||||
margin: 0px;
|
||||
padding-top: 1px;
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
|
||||
.mytitlebar label{
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.mytitlebar box{
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.ctrl_btn {
|
||||
min-height: 8px;
|
||||
min-width: 14px;
|
||||
margin: 0px;
|
||||
font-weight: 900;
|
||||
border-radius: 100%;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
padding-left: 1px;
|
||||
padding-right: 1px;
|
||||
}
|
||||
|
||||
.ctrl_btn:hover{
|
||||
color:black;
|
||||
background-color: alpha(gray, 0.3);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
#include "MyTitleBar.h"
|
||||
|
||||
struct _MyTitleBar
|
||||
{
|
||||
GObject parent_instance;
|
||||
GtkWidget *ctrl_window;
|
||||
GtkWidget *header;
|
||||
GtkWidget *btn_close, *btn_mini;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(MyTitleBar, my_titlebar, G_TYPE_OBJECT)
|
||||
|
||||
static void ctrl_win_hide(MyTitleBar *self)
|
||||
{
|
||||
gtk_widget_set_visible(self->ctrl_window, FALSE);
|
||||
}
|
||||
|
||||
static void ctrl_win_close(MyTitleBar *self)
|
||||
{
|
||||
gtk_window_close(GTK_WINDOW(self->ctrl_window));
|
||||
}
|
||||
|
||||
void my_titlebar_set_window(MyTitleBar *self, GtkWidget *window)
|
||||
{
|
||||
gtk_window_set_titlebar(GTK_WINDOW(window), self->header);
|
||||
self->ctrl_window = window;
|
||||
}
|
||||
|
||||
static void my_titlebar_init(MyTitleBar *self)
|
||||
{
|
||||
// Create widgets
|
||||
self->header = gtk_header_bar_new();
|
||||
gtk_widget_set_css_classes(self->header, NULL);
|
||||
gtk_widget_add_css_class(self->header, "mytitlebar");
|
||||
|
||||
// Initalize headerbar
|
||||
gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(self->header), FALSE);
|
||||
|
||||
// Add a close button
|
||||
// self->btn_close = gtk_button_new_with_label("\u00d7");
|
||||
self->btn_close = gtk_button_new_from_icon_name("window-close-symbolic");
|
||||
gtk_widget_set_css_classes(self->btn_close, NULL);
|
||||
gtk_widget_add_css_class(self->btn_close, "ctrl_btn");
|
||||
gtk_widget_add_css_class(self->btn_close, "close");
|
||||
gtk_header_bar_pack_start(GTK_HEADER_BAR(self->header), self->btn_close);
|
||||
|
||||
// Add a minimize button
|
||||
self->btn_mini = gtk_button_new_from_icon_name("window-minimize-symbolic");
|
||||
gtk_widget_set_css_classes(self->btn_mini, NULL);
|
||||
gtk_widget_add_css_class(self->btn_mini, "ctrl_btn");
|
||||
gtk_header_bar_pack_start(GTK_HEADER_BAR(self->header), self->btn_mini);
|
||||
|
||||
// Add style for headerbar
|
||||
GtkCssProvider *provider = gtk_css_provider_new();
|
||||
gtk_css_provider_load_from_resource(provider, "/org/gtk/daleclack/title_style.css");
|
||||
gtk_style_context_add_provider_for_display(gtk_widget_get_display(GTK_WIDGET(self->header)),
|
||||
GTK_STYLE_PROVIDER(provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
g_signal_connect_swapped(self->btn_close, "clicked", G_CALLBACK(ctrl_win_close), self);
|
||||
g_signal_connect_swapped(self->btn_mini, "clicked", G_CALLBACK(ctrl_win_hide), self);
|
||||
}
|
||||
|
||||
static void my_titlebar_class_init(MyTitleBarClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
MyTitleBar *my_titlebar_new()
|
||||
{
|
||||
return My_TitleBar(g_object_new(my_titlebar_get_type(), NULL));
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_DECLARE_FINAL_TYPE(MyTitleBar, my_titlebar, My, TitleBar, GObject)
|
||||
|
||||
void my_titlebar_set_window(MyTitleBar *title_bar, GtkWidget *window);
|
||||
|
||||
MyTitleBar *my_titlebar_new();
|
Loading…
Reference in New Issue