This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GtkButton1.lua
67 lines (54 loc) · 1.64 KB
/
GtkButton1.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local lgi = require("lgi")
local Gtk = lgi.require("Gtk", "3.0")
local Gio = lgi.require("Gio", "2.0")
local GLib = lgi.require("GLib", "2.0")
local App = Gtk.Application({
application_id = "com.github.Miqueas.Lua-GTK3-Examples.GtkButton1"
})
function App:on_startup()
Gtk.ApplicationWindow({
application = self,
default_width = 400,
default_height = 400
})
end
function App:on_activate()
self.active_window:set_titlebar(Gtk.HeaderBar({
visible = true,
show_close_button = true,
title = "GtkButton",
subtitle = "Example 1"
}))
--[[ GtkButton:
Just a button lol
]]
local Button = Gtk.Button({
visible = true,
label = "Click me!",
valign = Gtk.Align.CENTER,
halign = Gtk.Align.CENTER
})
local Notification_ID = 0
--for k, v in pairs(GLib:_resolve(true)._struct) do print(k, v) end
-- The "clicked" signal is emited when the user clicks
-- the button
function Button:on_clicked()
-- Notifications are not yet supported on Windows
if GLib.get_os_info("ID") == "windows" then
print(("Clicked %d times!"):format(Notification_ID))
else
local Notification = Gio.Notification()
Notification:set_title("GtkButton example 1")
Notification:set_body("You cliked the button!")
-- 'self' can't be used here, because 'self' here
-- reffers to the GtkButton that's clicked
App:send_notification(Notification_ID, Notification)
end
-- Incrementing this value makes the app spawn various
-- notifications
Notification_ID = Notification_ID + 1
end
self.active_window:add(Button)
self.active_window:present()
end
return App:run(arg)