commit 81bb95cf25a15e80c0057abe388ad1c87650545f Author: Zoe Moore Date: Fri Dec 16 15:19:11 2022 -0800 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..163eb75 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.cr] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab45be8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/docs/ +/lib/ +/bin/ +/.shards/ +*.dwarf +/data/ui/compiled diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0fa8c40 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zoe Moore + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f9825e --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# gtktest + +Crystal GTK test application + +## Build + +You gotta have blueprint installed + +``` +pacman -S blueprint-compiler crystal shards libadwaita +``` + +Then you can test run with + +``` +crystal run src/gtktest.cr +``` + diff --git a/data/gtktest.gresource.xml b/data/gtktest.gresource.xml new file mode 100644 index 0000000..8712acb --- /dev/null +++ b/data/gtktest.gresource.xml @@ -0,0 +1,6 @@ + + + + ui/compiled/main.ui + + diff --git a/data/ui/main.blp b/data/ui/main.blp new file mode 100644 index 0000000..937642f --- /dev/null +++ b/data/ui/main.blp @@ -0,0 +1,14 @@ +using Gtk 4.0; +using Adw 1; + +Adw.ApplicationWindow mainWindow { + title: "Hello world"; + default-width: 300; + default-height: 400; + + Gtk.Box { + orientation: vertical; + + Adw.HeaderBar {} + } +} \ No newline at end of file diff --git a/shard.lock b/shard.lock new file mode 100644 index 0000000..0f39dc6 --- /dev/null +++ b/shard.lock @@ -0,0 +1,18 @@ +version: 2.0 +shards: + gi-crystal: + git: https://github.com/hugopl/gi-crystal.git + version: 0.14.0 + + gtk4: + git: https://github.com/hugopl/gtk4.cr.git + version: 0.12.0 + + libadwaita: + git: https://github.com/geopjr/libadwaita.cr.git + version: 1.0.0+git.commit.72f2e42c7dafbf7a427fb24db5dce4e66199d680 + + version_from_shard: + git: https://github.com/hugopl/version_from_shard.git + version: 1.2.5 + diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..7e78e78 --- /dev/null +++ b/shard.yml @@ -0,0 +1,19 @@ +name: gtktest +version: 0.1.0 + +authors: + - Zoe Moore + +targets: + gtktest: + main: src/gtktest.cr + +dependencies: + gtk4: + github: hugopl/gtk4.cr + libadwaita: + github: GeopJr/libadwaita.cr + +crystal: 1.6.2 + +license: MIT diff --git a/spec/gtktest_spec.cr b/spec/gtktest_spec.cr new file mode 100644 index 0000000..add3116 --- /dev/null +++ b/spec/gtktest_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Gtktest do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100644 index 0000000..84e7eae --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/gtktest" diff --git a/src/gtktest.cr b/src/gtktest.cr new file mode 100644 index 0000000..c15880a --- /dev/null +++ b/src/gtktest.cr @@ -0,0 +1,10 @@ +require "libadwaita" + +require "./modules/prerequisites.cr" +require "./modules/views/main.cr" + +module GtkTest + B_UI = Gtk::Builder.new_from_resource("/gtktest/ui/compiled/main.ui") + + APP = Adw::Application.new("dev.gtktest", Gio::ApplicationFlags::None) +end diff --git a/src/modules/prerequisites.cr b/src/modules/prerequisites.cr new file mode 100644 index 0000000..f9686e3 --- /dev/null +++ b/src/modules/prerequisites.cr @@ -0,0 +1,9 @@ +module GtkTest + extend self + + VERSION = {{read_file("./shard.yml").split("version: ")[1].split("\n")[0]}} + {% + `blueprint-compiler batch-compile ./data/ui/compiled ./data/ui/ ./data/ui/*.blp` + %} + Gio.register_resource("data/gtktest.gresource.xml", "data") +end diff --git a/src/modules/views/main.cr b/src/modules/views/main.cr new file mode 100644 index 0000000..df58fee --- /dev/null +++ b/src/modules/views/main.cr @@ -0,0 +1,18 @@ +module GtkTest + @@main_window_id = 0_u32 + + def activate(app : Adw::Application) + main_window = APP.window_by_id(@@main_window_id) + return main_window.present if main_window + + window = Adw::ApplicationWindow.cast(B_UI["mainWindow"]) + window.application = app + + @@main_window_id = window.id + + window.present + end + + APP.activate_signal.connect(->activate(Adw::Application)) + exit(APP.run(ARGV)) +end \ No newline at end of file