2020-12-20 11:22:22 +08:00
|
|
|
#include "gtkwin.h"
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
//Initalize GtkButton
|
|
|
|
void GtkBtn::init(const gchar *str,int width,int height){
|
|
|
|
button=gtk_button_new_with_label(str);
|
|
|
|
gtk_widget_set_size_request(button,width,height);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Link "clicked" signal
|
|
|
|
void GtkBtn::signal_clicked(pfun func,gpointer data){
|
|
|
|
g_signal_connect(button,"clicked",G_CALLBACK(func),data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//put widget int layout
|
|
|
|
void Winlayout::put(GtkWidget *child,int x,int y){
|
|
|
|
gtk_layout_put(GTK_LAYOUT(layout),child,x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Initalize Gtklayout
|
|
|
|
void Winlayout::init(){
|
|
|
|
GtkBtn button1;
|
|
|
|
button1.init("Test",100,50);
|
|
|
|
button1.signal_clicked(print,NULL);
|
|
|
|
put(button1.button,150,100);
|
|
|
|
}
|
|
|
|
|
2020-12-20 20:50:10 +08:00
|
|
|
void WinHeader::init(){
|
|
|
|
gtk_header_bar_set_show_close_button(_header,TRUE);
|
|
|
|
gtk_header_bar_set_decoration_layout(_header,"close,minimize,maximize:menu");
|
|
|
|
}
|
|
|
|
|
2020-12-20 11:22:22 +08:00
|
|
|
//Add widget to window
|
|
|
|
void GtkWin::add(GtkWidget *widget){
|
|
|
|
gtk_container_add(GTK_CONTAINER(window),widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GtkWin::win_init(GtkApplication *app,int width,int height){
|
|
|
|
//Create a window and set window proprites
|
|
|
|
window=gtk_application_window_new(app);
|
|
|
|
_window=GTK_WINDOW(window);
|
|
|
|
gtk_window_set_default_size(_window,width,height);
|
|
|
|
gtk_window_set_position(_window,GTK_WIN_POS_CENTER);
|
2020-12-20 20:50:10 +08:00
|
|
|
//Set window titlebar
|
|
|
|
WinHeader header1;
|
|
|
|
header1.init();
|
|
|
|
set_titlebar(header1.header);
|
2020-12-20 11:22:22 +08:00
|
|
|
//Put a layout
|
|
|
|
Winlayout layout1;
|
|
|
|
layout1.init();
|
|
|
|
add(layout1.layout);
|
|
|
|
}
|
|
|
|
|
2020-12-20 20:50:10 +08:00
|
|
|
void GtkWin::set_titlebar(GtkWidget *title){
|
|
|
|
gtk_window_set_titlebar(_window,title);
|
|
|
|
}
|
|
|
|
|
2020-12-20 11:22:22 +08:00
|
|
|
//Show everything
|
|
|
|
void GtkWin::show_all(){
|
|
|
|
gtk_widget_show_all(window);
|
|
|
|
}
|