This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.kt
53 lines (45 loc) · 1.52 KB
/
Main.kt
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
import bindings.gtk.*
import native.gtk.GtkAlign.GTK_ALIGN_CENTER
import native.gtk.GtkOrientation.GTK_ORIENTATION_HORIZONTAL
fun main() {
val app = Application("io.quantus.gtkkn.sevenguis.temperature-converter")
app.onActivate {
val window = ApplicationWindow(app).apply {
title = "7GUIs Temperature Converter"
}
val celciusField = Entry()
val fahrenheitField = Entry()
var isEditing = false
celciusField.onChanged {
if (isEditing) return@onChanged
celciusField.text.toIntOrNull()?.let { c ->
isEditing = true
fahrenheitField.text = (c * (9 / 5.toDouble()) + 32).toInt().toString()
isEditing = false
}
}
fahrenheitField.onChanged {
if (isEditing) return@onChanged
fahrenheitField.text.toIntOrNull()?.let { f ->
isEditing = true
celciusField.text = ((f - 32) * (5 / 9.toDouble())).toInt().toString()
isEditing = false
}
}
window.child = Box(GTK_ORIENTATION_HORIZONTAL, 10).apply {
homogeneous = true
valign = GTK_ALIGN_CENTER
marginTop = 10
marginBottom = 10
marginStart = 10
marginEnd = 10
append(celciusField)
append(Label("Celcius ="))
append(fahrenheitField)
append(Label("Fahrenheit"))
}
window.show()
}
app.run()
app.unref()
}