From 076a79deef7caaa84b9578b25a83eab2141d2586 Mon Sep 17 00:00:00 2001 From: daleclack Date: Sun, 5 Dec 2021 18:39:33 +0800 Subject: [PATCH] Update gtk118 & add gtk119 --- Gtk4/gtk118_imageviewer/res/MyImage.ui | 1 - Gtk4/gtk118_imageviewer/src/MyImage.cpp | 35 +- .../gtk119_imageviewer2/.vscode/settings.json | 3 + Gtkmm3/gtk119_imageviewer2/CMakeLists.txt | 62 ++ Gtkmm3/gtk119_imageviewer2/src/MyWin.cc | 5 + Gtkmm3/gtk119_imageviewer2/src/MyWin.hh | 17 + Gtkmm3/gtk119_imageviewer2/src/main.cc | 9 + cpp/algorithms/problem10.cpp | 18 + cpp/algorithms/problem11.cpp | 33 + cpp/algorithms/problem12.cpp | 19 + cpp/algorithms/problem13.cpp | 34 + cpp/algorithms/problem7.cpp | 17 + cpp/algorithms/problem8.cpp | 23 + cpp/algorithms/problem9.cpp | 20 + gtk4-rs/gtk-rs-menus/.vscode/launch.json | 47 ++ gtk4-rs/gtk-rs-menus/Cargo.lock | 722 ++++++++++++++++++ gtk4-rs/gtk-rs-menus/Cargo.toml | 9 + gtk4-rs/gtk-rs-menus/res/menubar.xml | 13 + gtk4-rs/gtk-rs-menus/src/main.rs | 45 ++ rust_test/src/main.rs | 2 + rust_test/src/test2.rs | 2 + rust_test/src/test3.rs | 12 +- 22 files changed, 1120 insertions(+), 28 deletions(-) create mode 100644 Gtkmm3/gtk119_imageviewer2/.vscode/settings.json create mode 100644 Gtkmm3/gtk119_imageviewer2/CMakeLists.txt create mode 100644 Gtkmm3/gtk119_imageviewer2/src/MyWin.cc create mode 100644 Gtkmm3/gtk119_imageviewer2/src/MyWin.hh create mode 100644 Gtkmm3/gtk119_imageviewer2/src/main.cc create mode 100644 cpp/algorithms/problem10.cpp create mode 100644 cpp/algorithms/problem11.cpp create mode 100644 cpp/algorithms/problem12.cpp create mode 100644 cpp/algorithms/problem13.cpp create mode 100644 cpp/algorithms/problem7.cpp create mode 100644 cpp/algorithms/problem8.cpp create mode 100644 cpp/algorithms/problem9.cpp create mode 100644 gtk4-rs/gtk-rs-menus/.vscode/launch.json create mode 100644 gtk4-rs/gtk-rs-menus/Cargo.lock create mode 100644 gtk4-rs/gtk-rs-menus/Cargo.toml create mode 100644 gtk4-rs/gtk-rs-menus/res/menubar.xml create mode 100644 gtk4-rs/gtk-rs-menus/src/main.rs diff --git a/Gtk4/gtk118_imageviewer/res/MyImage.ui b/Gtk4/gtk118_imageviewer/res/MyImage.ui index 9efd0aa..a81430f 100644 --- a/Gtk4/gtk118_imageviewer/res/MyImage.ui +++ b/Gtk4/gtk118_imageviewer/res/MyImage.ui @@ -32,7 +32,6 @@ 1 - diff --git a/Gtk4/gtk118_imageviewer/src/MyImage.cpp b/Gtk4/gtk118_imageviewer/src/MyImage.cpp index 8a3d431..859bb91 100644 --- a/Gtk4/gtk118_imageviewer/src/MyImage.cpp +++ b/Gtk4/gtk118_imageviewer/src/MyImage.cpp @@ -50,33 +50,25 @@ static void drag_start(GtkGestureDrag * self,double x,double y,MyImage * image){ static void drag_update(GtkGestureDrag * self,double x,double y,MyImage * image){ //Move Image - if(image->move_count == 5){ int hadj_value = gtk_adjustment_get_value(image->hadjustment); int vadj_value = gtk_adjustment_get_value(image->vadjustment); - if(hadj_value - x >= 0 && - x <= image->hmax_value){ + if(hadj_value -x < 0){ + gtk_adjustment_set_value(image->hadjustment,0); + }else if(hadj_value - x > image->hmax_value){ + gtk_adjustment_set_value(image->hadjustment,image->hmax_value); + } + else{ gtk_adjustment_set_value(image->hadjustment,-x/2.0); } - if(vadj_value - y >= 0 && - y <= image->vmax_value){ + + if(vadj_value - x < 0){ + gtk_adjustment_set_value(image->vadjustment,0); + }else if(vadj_value - x > image->vmax_value){ + gtk_adjustment_set_value(image->vadjustment,image->vmax_value); + }else{ gtk_adjustment_set_value(image->vadjustment,-y/2.0); } - image->move_count = 0; - }else{ - image->move_count++; - } - -} - -static void drag_end(GtkGestureDrag * self,double x,double y,MyImage * image){ - //g_print("%f %f\n",x+image->start_x,y+image->start_y); - //sleep(1); - int hadj_value = gtk_adjustment_get_value(image->hadjustment); - int vadj_value = gtk_adjustment_get_value(image->vadjustment); - if(hadj_value - x >= 0 && - x <= image->hmax_value){ - gtk_adjustment_set_value(image->hadjustment,-x); - } - if(vadj_value - y >= 0 && - y <= image->vmax_value){ - gtk_adjustment_set_value(image->vadjustment,-y); - } + image->move_count = 0; } static void my_image_dispose(GObject * object){ @@ -255,7 +247,6 @@ static void my_image_class_init(MyImageClass * self_class){ gtk_widget_class_bind_template_callback(self_class,pressed_cb); gtk_widget_class_bind_template_callback(self_class,drag_start); gtk_widget_class_bind_template_callback(self_class,drag_update); - gtk_widget_class_bind_template_callback(self_class,drag_end); } void my_image_bind_adjustments(MyImage * self, diff --git a/Gtkmm3/gtk119_imageviewer2/.vscode/settings.json b/Gtkmm3/gtk119_imageviewer2/.vscode/settings.json new file mode 100644 index 0000000..b4d8c35 --- /dev/null +++ b/Gtkmm3/gtk119_imageviewer2/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" +} \ No newline at end of file diff --git a/Gtkmm3/gtk119_imageviewer2/CMakeLists.txt b/Gtkmm3/gtk119_imageviewer2/CMakeLists.txt new file mode 100644 index 0000000..f99f4ef --- /dev/null +++ b/Gtkmm3/gtk119_imageviewer2/CMakeLists.txt @@ -0,0 +1,62 @@ +set(CMAKE_CXX_STANDARD 17) +cmake_minimum_required(VERSION 3.0.0) +project(gtk117 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 +# gnome-fs-directory.png +# gnome-fs-regular.png +# icons/24x24/actions/view-grid-symbolic.png +# icons/24x24/actions/view-list-symbolic.png +# icons/48x48/actions/dialog-error.png) + +# compile_gresources(RESOURCE_FILE +# XML_OUT +# TYPE EMBED_C +# RESOURCES ${RESOURCE_LIST} +# PREFIX "/org/gtk/daleclack" +# SOURCE_DIR ${PROJECT_SOURCE_DIR}/../default_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) +else() + add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc) + +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) diff --git a/Gtkmm3/gtk119_imageviewer2/src/MyWin.cc b/Gtkmm3/gtk119_imageviewer2/src/MyWin.cc new file mode 100644 index 0000000..bc8d908 --- /dev/null +++ b/Gtkmm3/gtk119_imageviewer2/src/MyWin.cc @@ -0,0 +1,5 @@ +#include "MyWin.hh" + +MyWin::MyWin(){ + +} \ No newline at end of file diff --git a/Gtkmm3/gtk119_imageviewer2/src/MyWin.hh b/Gtkmm3/gtk119_imageviewer2/src/MyWin.hh new file mode 100644 index 0000000..0208325 --- /dev/null +++ b/Gtkmm3/gtk119_imageviewer2/src/MyWin.hh @@ -0,0 +1,17 @@ +#pragma once + +#include + +class MyWin : public Gtk::Window{ + public: + MyWin(); + private: + //Child widgets + Gtk::ScrolledWindow sw; + Gtk::Image image; + Gtk::Box main_box; + + //Gesture control + + //Signal Handlers +}; diff --git a/Gtkmm3/gtk119_imageviewer2/src/main.cc b/Gtkmm3/gtk119_imageviewer2/src/main.cc new file mode 100644 index 0000000..7e5f2b4 --- /dev/null +++ b/Gtkmm3/gtk119_imageviewer2/src/main.cc @@ -0,0 +1,9 @@ +#include "MyWin.hh" + +int main(int argc,char ** argv){ + auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack"); + + MyWin window; + + return app->run(window); +} \ No newline at end of file diff --git a/cpp/algorithms/problem10.cpp b/cpp/algorithms/problem10.cpp new file mode 100644 index 0000000..930bf99 --- /dev/null +++ b/cpp/algorithms/problem10.cpp @@ -0,0 +1,18 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2009 + +#include +#include + +int main(){ + int m; + double n; + while(scanf("%lf%d",&n,&m)!=EOF){ + double sum = 0; + for(int i=0;i + +int main(){ + int m,n; + bool flag; + while(scanf("%d%d",&m,&n)!=EOF){ + flag = false; + if(m>n){ + int t = m; + m = n; + n = t; + } + for(int i=m;i<=n;i++){ + int x,y,z; + x = i/100; + y = i%100/10; + z = i%10; + if(x*x*x + y*y*y + z*z*z == i){ + if(flag){ printf(" "); } + printf("%d",i); + flag = true; + } + } + if(!flag){ + printf("no\n"); + }else{ + printf("\n"); + } + } + return 0; +} diff --git a/cpp/algorithms/problem12.cpp b/cpp/algorithms/problem12.cpp new file mode 100644 index 0000000..72e0d81 --- /dev/null +++ b/cpp/algorithms/problem12.cpp @@ -0,0 +1,19 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2011 + +#include +#include + +int main(){ + int m,n; + double sum; + scanf("%d",&m); + for(int i=0;i +#include + +int isPrime(int number){ + int i; + for(i=2;i<=sqrt(number);i++){ + if(number%i==0) return 0; + } + return 1; +} + +int main(){ + int x,y,i,flag=1; + while(scanf("%d%d",&x,&y)){ + flag=1; + if(x==0 && y==0){break;} + if(x>y){ + int t=x; + x=y; + y=t; + } + for(i=x;i<=y;i++){ + if(!isPrime(i*i+i+41)){ + flag=0; + break; + } + } + if(flag){ printf("OK\n"); } + else{ printf("Sorry\n"); } + } + return 0; +} diff --git a/cpp/algorithms/problem7.cpp b/cpp/algorithms/problem7.cpp new file mode 100644 index 0000000..7433197 --- /dev/null +++ b/cpp/algorithms/problem7.cpp @@ -0,0 +1,17 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2006 + +#include + +int main(){ + int i,n,x,sum=1; + while(scanf("%d",&n)!=EOF){ + sum = 1; + for(i=0;i + +int main(){ + int m=0,n=0,x,y; + while(scanf("%d%d",&m,&n)!=EOF){ + x=0,y=0; + if(m > n){ + int t = m; + m = n; + n = t; + } + for(int i=m;i<=n;i++){ + if(i%2==0){ + x += i*i; + }else{ + y += i*i*i; + } + } + printf("%d %d\n",x,y); + } +} diff --git a/cpp/algorithms/problem9.cpp b/cpp/algorithms/problem9.cpp new file mode 100644 index 0000000..ed5058a --- /dev/null +++ b/cpp/algorithms/problem9.cpp @@ -0,0 +1,20 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2008 + +#include + +int main(){ + int x,y,z,n; + while(scanf("%d",&n)){ + double temp = 0.0; + x=0;y=0;z=0; + if(n==0) break; + for(int i=0 ; i0){ z++; } + if(temp==0){ y++; } + } + printf("%d %d %d\n",x,y,z); + } + return 0; +} diff --git a/gtk4-rs/gtk-rs-menus/.vscode/launch.json b/gtk4-rs/gtk-rs-menus/.vscode/launch.json new file mode 100644 index 0000000..cb726c1 --- /dev/null +++ b/gtk4-rs/gtk-rs-menus/.vscode/launch.json @@ -0,0 +1,47 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'gtk-rs-menus'", + "cargo": { + "args": [ + "build", + "--bin=gtk-rs-menus", + "--package=gtk-rs-menus", + "--release" + ], + "filter": { + "name": "gtk-rs-menus", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'gtk-rs-menus'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=gtk-rs-menus", + "--package=gtk-rs-menus", + "--release" + ], + "filter": { + "name": "gtk-rs-menus", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/gtk4-rs/gtk-rs-menus/Cargo.lock b/gtk4-rs/gtk-rs-menus/Cargo.lock new file mode 100644 index 0000000..aa09737 --- /dev/null +++ b/gtk4-rs/gtk-rs-menus/Cargo.lock @@ -0,0 +1,722 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cairo-rs" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b5725979db0c586d98abad2193cdb612dd40ef95cd26bd99851bf93b3cb482" +dependencies = [ + "bitflags", + "cairo-sys-rs", + "glib", + "libc", + "thiserror", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b448b876970834fda82ba3aeaccadbd760206b75388fc5c1b02f1e343b697570" +dependencies = [ + "glib-sys", + "libc", + "system-deps 3.2.0", +] + +[[package]] +name = "cfg-expr" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b412e83326147c2bb881f8b40edfbf9905b9b8abaebd0e47ca190ba62fda8f0e" +dependencies = [ + "smallvec", +] + +[[package]] +name = "cfg-expr" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edae0b9625d1fce32f7d64b71784d9b1bf8469ec1a9c417e44aaf16a9cbd7571" +dependencies = [ + "smallvec", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "field-offset" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e1c54951450cbd39f3dbcf1005ac413b49487dabf18a720ad2383eccfeffb92" +dependencies = [ + "memoffset", + "rustc_version", +] + +[[package]] +name = "futures-channel" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445" + +[[package]] +name = "futures-executor" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11" + +[[package]] +name = "futures-task" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12" + +[[package]] +name = "futures-util" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534192cb8f01daeb8fab2c8d4baa8f9aae5b7a39130525779f5c2608e235b10f" +dependencies = [ + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f097c0704201fbc8f69c1762dc58c6947c8bb188b8ed0bc7e65259f1894fe590" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps 3.2.0", +] + +[[package]] +name = "gdk4" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f97a162c17214d1bf981af3f683156a0b1667dd1927057c4f0a68513251ecf0f" +dependencies = [ + "bitflags", + "cairo-rs", + "gdk-pixbuf", + "gdk4-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk4-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9498f4e06969fb96a4e4234dfe1d308a3ac6b120b3c6d93e3ec5c77fe88bc6d5" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "libc", + "pango-sys", + "system-deps 5.0.0", +] + +[[package]] +name = "gio" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711c3632b3ebd095578a9c091418d10fed492da9443f58ebc8f45efbeb215cb0" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-io", + "gio-sys", + "glib", + "libc", + "once_cell", + "thiserror", +] + +[[package]] +name = "gio-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0a41df66e57fcc287c4bcf74fc26b884f31901ea9792ec75607289b456f48fa" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps 3.2.0", + "winapi", +] + +[[package]] +name = "glib" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c515f1e62bf151ef6635f528d05b02c11506de986e43b34a5c920ef0b3796a4" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "once_cell", + "smallvec", +] + +[[package]] +name = "glib-macros" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518" +dependencies = [ + "anyhow", + "heck", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "glib-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c1d60554a212445e2a858e42a0e48cece1bd57b311a19a9468f70376cf554ae" +dependencies = [ + "libc", + "system-deps 3.2.0", +] + +[[package]] +name = "gobject-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa92cae29759dae34ab5921d73fff5ad54b3d794ab842c117e36cafc7994c3f5" +dependencies = [ + "glib-sys", + "libc", + "system-deps 3.2.0", +] + +[[package]] +name = "graphene-rs" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3380f132530ef9eb9e0a2bac180e30390aa5e49892d20294f822a974117a563" +dependencies = [ + "glib", + "graphene-sys", + "libc", +] + +[[package]] +name = "graphene-sys" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a9ac7450b3aa80792513a3c029920a2ede419de13fb5169a4e51b07a5685332" +dependencies = [ + "glib-sys", + "libc", + "pkg-config", + "system-deps 3.2.0", +] + +[[package]] +name = "gsk4" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff59ca46c4fc5087fd7a0c3770a71ea4b6e94f8c24c12e2c2e8538f9f6fd764" +dependencies = [ + "bitflags", + "cairo-rs", + "gdk4", + "glib", + "graphene-rs", + "gsk4-sys", + "libc", + "pango", +] + +[[package]] +name = "gsk4-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13aa53ce70234da02f9954339d988d5ab853d746a8f47a4ae17735ff873545b5" +dependencies = [ + "cairo-sys-rs", + "gdk4-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "libc", + "pango-sys", + "system-deps 5.0.0", +] + +[[package]] +name = "gtk-rs-menus" +version = "0.1.0" +dependencies = [ + "gtk4", +] + +[[package]] +name = "gtk4" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58a04f421d1485ba4739e723199f5828bca05ab4e622ed39a96a342b6b1a6a3d" +dependencies = [ + "bitflags", + "cairo-rs", + "field-offset", + "futures-channel", + "gdk-pixbuf", + "gdk4", + "gio", + "glib", + "graphene-rs", + "gsk4", + "gtk4-macros", + "gtk4-sys", + "libc", + "once_cell", + "pango", +] + +[[package]] +name = "gtk4-macros" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5068d4354af02454f44687adc613100aa98ae11e273cdcac84f89dc08be2b4a1" +dependencies = [ + "anyhow", + "heck", + "itertools", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "gtk4-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e20a64c8f0ddcff8902ff04c130747f2fb7834a43530f75d03d6c71335733b49" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk4-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "gsk4-sys", + "libc", + "pango-sys", + "system-deps 5.0.0", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "itertools" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +dependencies = [ + "either", +] + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "pango" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546fd59801e5ca735af82839007edd226fe7d3bb06433ec48072be4439c28581" +dependencies = [ + "bitflags", + "glib", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2367099ca5e761546ba1d501955079f097caa186bb53ce0f718dca99ac1942fe" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps 3.2.0", +] + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" + +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "smallvec" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" + +[[package]] +name = "strum" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" + +[[package]] +name = "strum_macros" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "system-deps" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6" +dependencies = [ + "anyhow", + "cfg-expr 0.8.1", + "heck", + "itertools", + "pkg-config", + "strum", + "strum_macros", + "thiserror", + "toml", + "version-compare", +] + +[[package]] +name = "system-deps" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18db855554db7bd0e73e06cf7ba3df39f97812cb11d3f75e71c39bf45171797e" +dependencies = [ + "cfg-expr 0.9.0", + "heck", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "version-compare" +version = "0.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/gtk4-rs/gtk-rs-menus/Cargo.toml b/gtk4-rs/gtk-rs-menus/Cargo.toml new file mode 100644 index 0000000..9485518 --- /dev/null +++ b/gtk4-rs/gtk-rs-menus/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "gtk-rs-menus" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +gtk = { version = "0.3.1", package = "gtk4", features = ["v4_4"] } \ No newline at end of file diff --git a/gtk4-rs/gtk-rs-menus/res/menubar.xml b/gtk4-rs/gtk-rs-menus/res/menubar.xml new file mode 100644 index 0000000..dc03d6c --- /dev/null +++ b/gtk4-rs/gtk-rs-menus/res/menubar.xml @@ -0,0 +1,13 @@ + + + +
+ + File + + Exit + + +
+
+
diff --git a/gtk4-rs/gtk-rs-menus/src/main.rs b/gtk4-rs/gtk-rs-menus/src/main.rs new file mode 100644 index 0000000..db016ca --- /dev/null +++ b/gtk4-rs/gtk-rs-menus/src/main.rs @@ -0,0 +1,45 @@ +use gtk::prelude::*; +use gtk::{self, + gio::{self} +}; + +fn main() { + //Create a application + let app = gtk::Application::builder() + .application_id("org.gtk.daleclack") + .build(); + + app.connect_activate(build_ui); + + app.run(); +} + +fn build_ui(app:>k::Application){ + //Create a window + let window = gtk::Window::builder() + .application(app) + .title("Gtk-rs menu test") + .icon_name("org.gtk.daleclack") + .build(); + + window.set_default_size(800,600); + + //Create menu + let builder = gtk::Builder::from_file("./res/menubar.xml"); + let menu:gio::MenuModel = builder.object("menubar").unwrap(); + + //Create menubar + let menubar = gtk::PopoverMenuBar::builder() + .menu_model(&menu) + .build(); + + menubar.set_halign(gtk::Align::Start); + menubar.set_valign(gtk::Align::Start); + + let vbox = gtk::Box::new(gtk::Orientation::Horizontal,5); + + vbox.append(&menubar); + window.set_child(Some(&vbox)); + + window.present(); +} diff --git a/rust_test/src/main.rs b/rust_test/src/main.rs index a2a0092..d0b47f8 100644 --- a/rust_test/src/main.rs +++ b/rust_test/src/main.rs @@ -1,3 +1,5 @@ +#[allow(dead_code)] + mod test; mod test2; mod test3; diff --git a/rust_test/src/test2.rs b/rust_test/src/test2.rs index f45a5b4..c87230f 100644 --- a/rust_test/src/test2.rs +++ b/rust_test/src/test2.rs @@ -1,3 +1,5 @@ +#[allow(dead_code)] + fn main(){ let pair = ('a',17); println!("{} {}",pair.0,pair.1); diff --git a/rust_test/src/test3.rs b/rust_test/src/test3.rs index dbf2b34..394c219 100644 --- a/rust_test/src/test3.rs +++ b/rust_test/src/test3.rs @@ -1,10 +1,12 @@ //Get Current directory(May cause error when handling directory name with chinese) +#[allow(dead_code)] fn main(){ - let mut args = std::env::args(); - let path = args.nth(0).unwrap(); - let length = path.len(); - println!("{}",path); - let path1 = &path[0..length-5]; + let path = std::env::args().nth(0).unwrap(); //The arg[0] is the path of binary + + let length = path.len(); //Get length to handle the String + + let path1 = &path[0..length-5]; //Remove the binary name + println!("{}",path1); } \ No newline at end of file