Add Kotlin and Scala examples. #2

Merged
poach3r merged 5 commits from main into main 2024-12-20 23:04:14 +01:00
poach3r commented 2024-12-10 15:47:59 +01:00 (Migrated from github.com)

I've created both a HelloWorld example for Scala and a Calculator example for Kotlin. Due to the nature of Scala, it is impossible to write java-gi programs that follow proper Scala practices, as such I struggled to rewrite any examples except for HelloWorld. I may be able to write a wrapper library similar to the one for Swing in the future which would greatly improve Scala support.

I've created both a HelloWorld example for Scala and a Calculator example for Kotlin. Due to the nature of Scala, it is impossible to write java-gi programs that follow proper Scala practices, as such I struggled to rewrite any examples except for HelloWorld. I may be able to write a wrapper library similar to [the one for Swing](https://index.scala-lang.org/scala/scala-swing) in the future which would greatly improve Scala support.
jwharm commented 2024-12-11 22:33:08 +01:00 (Migrated from github.com)

Thanks for the PR! Can you please change the calculator example so that it will replace the current Java version? I don't think it's really useful to have two calculator examples.

I'd really like a Scala example app that is a bit larger. Why is it impossible to write java-gi programs that follow Scala best practices? Is the Gtk API not suitable or is it something specific in java-gi?

Thanks for the PR! Can you please change the calculator example so that it will replace the current Java version? I don't think it's really useful to have two calculator examples. I'd really like a Scala example app that is a bit larger. Why is it impossible to write java-gi programs that follow Scala best practices? Is the Gtk API not suitable or is it something specific in java-gi?
poach3r commented 2024-12-12 01:05:47 +01:00 (Migrated from github.com)

I'll change the PR once I have access to my laptop. As for the second question, it is just due to the nature of GTK. Ideally, Scala programs should be immutable, non-nullable, and functional, however GTK was intended for mutable, nullable, and object-oriented programming languages. This conflict of interest makes it necessary to use Scala like it was Java or Vala which isn't how the language was intended to be used.

I'll change the PR once I have access to my laptop. As for the second question, it is just due to the nature of GTK. Ideally, Scala programs should be immutable, non-nullable, and functional, however GTK was intended for mutable, nullable, and object-oriented programming languages. This conflict of interest makes it necessary to use Scala like it was Java or Vala which isn't how the language was intended to be used.
jwharm (Migrated from github.com) requested changes 2024-12-13 22:40:47 +01:00
jwharm (Migrated from github.com) left a comment

Thanks! I like the image viewer example a lot. It's small, and easy to understand.

I have a few review comments, nothing spectacular.

One question remains: Do you mind if I change the references to "org.poach3r" into "io.jwharm.javagi.examples" for consistency with the other examples, and credit you in the examples' README file instead?

Thanks! I like the image viewer example a lot. It's small, and easy to understand. I have a few review comments, nothing spectacular. One question remains: Do you mind if I change the references to "org.poach3r" into "io.jwharm.javagi.examples" for consistency with the other examples, and credit you in the examples' README file instead?
@ -0,0 +1,28 @@
plugins {
jwharm (Migrated from github.com) commented 2024-12-13 22:00:32 +01:00

Missing a closing "

Missing a closing `"`
@ -0,0 +1,28 @@
plugins {
kotlin("jvm") version "2.0.21"
}
jwharm (Migrated from github.com) commented 2024-12-13 22:15:37 +01:00

Please add the application plugin & set the main class, so gradle run will work, and suppress the warning about unsafe access:

tasks.named<JavaExec>("run") {
    jvmArgs("--enable-native-access=ALL-UNNAMED")
}

application {
    mainClass.set("org.poach3r.MainKt")
}
Please add the `application` plugin & set the main class, so `gradle run` will work, and suppress the warning about unsafe access: ``` tasks.named<JavaExec>("run") { jvmArgs("--enable-native-access=ALL-UNNAMED") } application { mainClass.set("org.poach3r.MainKt") } ```
@ -0,0 +1,185 @@
package io.jwharm.javagi.examples
jwharm (Migrated from github.com) commented 2024-12-13 22:16:45 +01:00

Change this to Gtk.styleContextAddProviderForDisplay to prevent a deprecation warning about the StyleContext class.

Change this to `Gtk.styleContextAddProviderForDisplay` to prevent a deprecation warning about the `StyleContext` class.
@ -0,0 +5,4 @@
lazy val root = (project in file("."))
.settings(
name := "HelloWorldScala"
)
jwharm (Migrated from github.com) commented 2024-12-13 22:25:04 +01:00

Please suppress the "unsafe native access" warning:

    fork := true,
    javaOptions += "--enable-native-access=ALL-UNNAMED"
Please suppress the "unsafe native access" warning: ``` fork := true, javaOptions += "--enable-native-access=ALL-UNNAMED" ```
@ -0,0 +7,4 @@
name := "HelloWorldScala"
)
libraryDependencies += "io.github.jwharm.javagi" % "gtk" % "0.11.0"
jwharm (Migrated from github.com) commented 2024-12-13 22:25:19 +01:00

0.11.1

0.11.1
@ -0,0 +1,14 @@
ThisBuild / version := "0.1.0-SNAPSHOT"
jwharm (Migrated from github.com) commented 2024-12-13 22:26:13 +01:00

Please suppress the "unsafe native access" warning:

    fork := true,
    javaOptions += "--enable-native-access=ALL-UNNAMED"

Please suppress the "unsafe native access" warning: ``` fork := true, javaOptions += "--enable-native-access=ALL-UNNAMED" ```
@ -0,0 +1,44 @@
import io.github.jwharm.javagi.base.GErrorException
jwharm (Migrated from github.com) commented 2024-12-13 22:33:58 +01:00

I think it's okay. Can you remove the comment?

I think it's okay. Can you remove the comment?
poach3r commented 2024-12-19 12:39:27 +01:00 (Migrated from github.com)

I'm unsure if Github notified you of this, however I updated my branch with your requests.

I'm unsure if Github notified you of this, however I updated my branch with your requests.
jwharm commented 2024-12-20 23:08:22 +01:00 (Migrated from github.com)

Thanks!

Thanks!
Sign in to join this conversation.
No description provided.