Add gtk121

This commit is contained in:
daleclack 2022-01-11 12:36:37 +08:00
parent 769e969eff
commit 8c08709800
7 changed files with 241 additions and 1 deletions

View File

@ -1,6 +1,6 @@
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0) cmake_minimum_required(VERSION 3.0.0)
project(gtk118 VERSION 1.0.0) project(gtk120 VERSION 1.0.0)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros)
include(GlibCompileResourcesSupport) include(GlibCompileResourcesSupport)

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -0,0 +1,58 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(gtk119 VERSION 1.0.0)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros)
include(GlibCompileResourcesSupport)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
include_directories(.)
include_directories(..)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
include_directories (${GTKMM3_INCLUDE_DIRS})
link_directories (${GTKMM3_LIBRARY_DIRS})
#Compile Resource
set(RESOURCE_LIST
stack.ui)
compile_gresources(RESOURCE_FILE
XML_OUT
TYPE EMBED_C
RESOURCES ${RESOURCE_LIST}
PREFIX "/org/gtk/daleclack"
SOURCE_DIR ${PROJECT_SOURCE_DIR}/res)
# Add a custom target to the makefile. Now make builds our resource file.
# It depends on the output RESOURCE_FILE.
add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE})
#For win32 platform,use rc resource and .ico icon
if(WIN32)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(app_WINRC ../icon.rc)
set_property(SOURCE ../icon.rc APPEND PROPERTY
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
)
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} src/main.cc src/MyWin.cc ${RESOURCE_FILE})
else()
add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc ${RESOURCE_FILE})
endif(WIN32)
#Add command to generate .gitignore
add_custom_command(TARGET ${PROJECT_NAME}
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
SET (CMAKE_EXTRA_CXX_FLAGS ${GTKMM3_CFLAGS_OTHER})
target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES} -lpthread)

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="window">
<property name="can-focus">False</property>
<property name="default-width">440</property>
<property name="default-height">250</property>
<child>
<object class="GtkStack" id="main_stack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="transition-type">crossfade</property>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="start_grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="btn_go">
<property name="label" translatable="yes">Go</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="test_grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="btn_back">
<property name="label" translatable="yes">back</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,36 @@
#include "MyWin.hh"
MyWin *MyWin::create()
{
MyWin *win = nullptr;
auto builder1 = Gtk::Builder::create_from_resource("/org/gtk/daleclack/stack.ui");
builder1->get_widget_derived("window", win);
win->set_icon_name("org.gtk.daleclack");
return win;
}
MyWin::MyWin(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &builder)
: Gtk::Window(cobject),
ref_builder(builder)
{
//Get Widgets
ref_builder->get_widget("btn_go",btn_go);
ref_builder->get_widget("btn_back",btn_back);
ref_builder->get_widget("start_grid",start_grid);
ref_builder->get_widget("test_grid",test_grid);
ref_builder->get_widget("main_stack",main_stack);
//Link Signals
btn_go->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btngo_clicked));
btn_back->signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnback_clicked));
}
void MyWin::btngo_clicked(){
main_stack->set_visible_child(*test_grid);
}
void MyWin::btnback_clicked(){
main_stack->set_visible_child(*start_grid);
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <gtkmm.h>
class MyWin : public Gtk::Window
{
public:
static MyWin *create();
MyWin(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &builder);
private:
Glib::RefPtr<Gtk::Builder> ref_builder;
// Child Widgets
Gtk::Button *btn_go, *btn_back;
Gtk::Grid *start_grid, *test_grid;
Gtk::Stack *main_stack;
//Signal Handlers
void btngo_clicked();
void btnback_clicked();
};

View File

@ -0,0 +1,8 @@
#include "MyWin.hh"
int main(int argc,char ** argv){
//Create a application and run
auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack");
auto win = MyWin::create();
return app->run(*win);
}