Skip to content

[Help] How to use headerbar? How Gtk classes are translated into swift? #12

@lf-araujo

Description

@lf-araujo

Dear Tomas,

Thank you for this bindings! This is super useful.

I have a little experience in Vala, but on trying to use some elements from gtk I get errors. Specifically I am trying to use headerbars. How do this class translates into Swift? What am I doing wrong in the code below?

import SwiftGtk

let app = Application(applicationId: "com.example.application")

app.run { window in
    window.defaultSize = Size(width: 400, height: 400)
    window.resizable = true
    let headerbar = Headerbar()
    headerbar.set_title("My test")


    let button = Button(label: "Press Me")
    button.clicked = { _ in
        let newWindow = Window(windowType: .topLevel)
        newWindow.title = "Just a window"
        newWindow.defaultSize = Size(width: 200, height: 200)
        let labelPressed = Label(text: "Oh, you pressed the button.")
        newWindow.add(labelPressed)

        newWindow.showAll()
    }
    window.set_titlebar(headerbar)
    window.add(button)
}

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