Skip to content

Support request: Help gtk-kt with GIR #8

Closed

Description

@leinardi

Hello, I know that this is a weird request, so feel free to just say no, but I was wondering if you will be open to help the gtk-kt project ^^
The gtk-kt project is focused on Kotlin native, and not JNA so isn't exactly a direct competitor of your project.
Currently there is only one maintainer that started writing the bindings manually but now he's working on a GIR generator for the Kotlin native code. But it isn't an easy task to do without previous knowledge of GIR so I was wondering if you could help us.
If you are wondering who am I, I'm just an Android developer that would love to be able to write GTK application in Koltin native. I started contributing to the gtk-kt project, very recently and, since I do not have a lot of C interop knowledge, my contributions are mostly on Gradle and pure Kotlin code level. And maybe a little of PR ^^.

Activity

  1. bailuk commented on Feb 9, 2023

    @bailuk
    Owner

    Hi,
    GTK bindings for Kotlin native sounds interesting to me. However I have no experience with Kotlin native so far.

    What is the desired output of that "GIR generator"? Will it be Kotlin code? And if so how will it link to the C-Library? Will it call an autogenerated "cinterop" API?

  2. Doomsdayrs commented on Feb 9, 2023

    @Doomsdayrs

    Hi, GTK bindings for Kotlin native sounds interesting to me. However I have no experience with Kotlin native so far.

    What is the desired output of that "GIR generator"? Will it be Kotlin code? And if so how will it link to the C-Library? Will it call an autogenerated "cinterop" API?

    It will can an auto generated cinterop API. The Kotlin multi platform stack generates these plugins via definition files that point to relevant headers and other C related information.

    The main goal on my side is to get Kotlin/Native generation up and running. But I also want to eventually create Java bindings as well under the tree.

  3. leinardi commented on Feb 9, 2023

    @leinardi
    Author

    Hi @bailuk thank you for coming back to us!

    This is an example of a generated kotlin native class:

    package org.gtk
    
    import glib.gint
    import gtk.GtkBox
    import gtk.gtk_box_append
    import gtk.gtk_box_get_baseline_position
    import gtk.gtk_box_get_homogeneous
    import gtk.gtk_box_get_spacing
    import gtk.gtk_box_insert_child_after
    import gtk.gtk_box_prepend
    import gtk.gtk_box_remove
    import gtk.gtk_box_reorder_child_after
    import gtk.gtk_box_set_baseline_position
    import gtk.gtk_box_set_homogeneous
    import gtk.gtk_box_set_spacing
    import kotlin.Boolean
    import kotlin.Int
    import kotlin.Unit
    import kotlinx.cinterop.CPointer
    import kotlinx.cinterop.reinterpret
    import org.gtk.Accessible
    import org.gtk.BaselinePosition
    import org.gtk.Buildable
    import org.gtk.ConstraintTarget
    import org.gtk.Orientable
    import org.gtk.Widget
    import org.gtk.glib.bool
    import org.gtk.glib.gtk
    
    /**
     * The `GtkBox` widget arranges child widgets into a single row or column.
     *
     * ![An example GtkBox](box.png)
     *
     * Whether it is a row or column depends on the value of its
     * [property@Gtk.Orientable:orientation] property. Within the other
     * dimension, all children are allocated the same size. Of course, the
     * [property@Gtk.Widget:halign] and [property@Gtk.Widget:valign] properties
     * can be used on the children to influence their allocation.
     *
     * Use repeated calls to [method@Gtk.Box.append] to pack widgets into a
     * `GtkBox` from start to end. Use [method@Gtk.Box.remove] to remove widgets
     * from the `GtkBox`. [method@Gtk.Box.insert_child_after] can be used to add
     * a child at a particular position.
     *
     * Use [method@Gtk.Box.set_homogeneous] to specify whether or not all children
     * of the `GtkBox` are forced to get the same amount of space.
     *
     * Use [method@Gtk.Box.set_spacing] to determine how much space will be minimally
     * placed between all children in the `GtkBox`. Note that spacing is added
     * *between* the children.
     *
     * Use [method@Gtk.Box.reorder_child_after] to move a child to a different
     * place in the box.
     *
     * # CSS nodes
     *
     * `GtkBox` uses a single CSS node with name box.
     *
     * # Accessibility
     *
     * `GtkBox` uses the %GTK_ACCESSIBLE_ROLE_GROUP role.
     */
    public open class Box(
    	public val boxPointer: CPointer<GtkBox>,
    ) : Widget(boxPointer.reinterpret()), Accessible, Buildable, ConstraintTarget, Orientable {
    	public override val AccessiblePointer: CPointer<GtkAccessible> = boxPointer.reinterpret()
    
    	public override val BuildablePointer: CPointer<GtkBuildable> = boxPointer.reinterpret()
    
    	public override val ConstraintTargetPointer: CPointer<GtkConstraintTarget> =
    			boxPointer.reinterpret()
    
    	public override val OrientablePointer: CPointer<GtkOrientable> = boxPointer.reinterpret()
    
    	/**
    	 * The position of the baseline aligned widgets if extra space is available.
    	 */
    	public var baselinePosition: BaselinePosition
    		/**
    		 * Gets the value set by gtk_box_set_baseline_position().
    		 */
    		get() {
    			val cReturn = gtk_box_get_baseline_position(boxPointer)
    			return cReturn!!.let { gtk -> 
    					BaselinePosition.valueOf(gtk)
    					}
    		}
    		/**
    		 * Sets the baseline position of a box.
    		 *
    		 * This affects only horizontal boxes with at least one baseline
    		 * aligned child. If there is more vertical space available than
    		 * requested, and the baseline is not allocated by the parent then
    		 * @position is used to allocate the baseline with respect to the
    		 * extra space available.
    		 */
    		set(position) {
    			gtk_box_set_baseline_position(boxPointer, position.value)
    		}
    
    	/**
    	 * Whether the children should all be the same size.
    	 */
    	public var homogeneous: Boolean
    		/**
    		 * Returns whether the box is homogeneous (all children are the
    		 * same size).
    		 */
    		get() {
    			val cReturn = gtk_box_get_homogeneous(boxPointer)
    			return cReturn!!.bool
    		}
    		/**
    		 * Sets whether or not all children of @box are given equal space
    		 * in the box.
    		 */
    		set(homogeneous) {
    			gtk_box_set_homogeneous(boxPointer, homogeneous.gtk)
    		}
    
    	/**
    	 * The amount of space between children.
    	 */
    	public var spacing: Int
    		/**
    		 * Gets the value set by gtk_box_set_spacing().
    		 */
    		get() {
    			val cReturn = gtk_box_get_spacing(boxPointer)
    			return cReturn!!
    		}
    		/**
    		 * Sets the number of pixels to place between children of @box.
    		 */
    		set(spacing) {
    			gtk_box_set_spacing(boxPointer, spacing)
    		}
    
    	/**
    	 * Adds @child as the last child to @box.
    	 */
    	public fun append(child: Widget): Unit {
    		gtk_box_append(boxPointer, child.pointer.reinterpret())
    	}
    
    	/**
    	 * Inserts @child in the position after @sibling in the list
    	 * of @box children.
    	 *
    	 * If @sibling is %NULL, insert @child at the first position.
    	 */
    	public fun insertChildAfter(child: Widget, sibling: Widget): Unit {
    		gtk_box_insert_child_after(boxPointer, child.pointer.reinterpret(), sibling.pointer.reinterpret())
    	}
    
    	/**
    	 * Adds @child as the first child to @box.
    	 */
    	public fun prepend(child: Widget): Unit {
    		gtk_box_prepend(boxPointer, child.pointer.reinterpret())
    	}
    
    	/**
    	 * Removes a child widget from @box.
    	 *
    	 * The child must have been added before with
    	 * [method@Gtk.Box.append], [method@Gtk.Box.prepend], or
    	 * [method@Gtk.Box.insert_child_after].
    	 */
    	public fun remove(child: Widget): Unit {
    		gtk_box_remove(boxPointer, child.pointer.reinterpret())
    	}
    
    	/**
    	 * Moves @child to the position after @sibling in the list
    	 * of @box children.
    	 *
    	 * If @sibling is %NULL, move @child to the first position.
    	 */
    	public fun reorderChildAfter(child: Widget, sibling: Widget): Unit {
    		gtk_box_reorder_child_after(boxPointer, child.pointer.reinterpret(),
    				sibling.pointer.reinterpret())
    	}
    
    	public companion object {
    		public fun CPointer<GtkBox>?.wrap(): Box? = this?.wrap()
    
    		public fun CPointer<GtkBox>.wrap(): Box = Box(this)
    	}
    }

    If you want to try the generator yourself you can checkout this project: https://gitlab.com/gtk-kt/gir-kt
    Simply run ./gradlew run, the generated code will be available in build/gir-kt.
    Currently the generated code isn't complete and doesn't work yet, we are still trying to squash some bugs, that's why your help would be great since you have already a lot of experience with GIR generation!

    If you want to jump in for a chat with us, we are available on the official Matrix instance for the project: https://matrix.to/#/#gtk-kt:matrix.org
    But if you prefer to chat somewhere else, let me know!

  4. Repository owner locked and limited conversation to collaborators on Mar 21, 2023
  5. converted this issue into a discussion #14 on Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions