Skip to content

Commit f0dcf6e

Browse files
committed
Implement Scale.kt
1 parent 546d1e1 commit f0dcf6e

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed

nativex/Control.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ Guide
3333
| ScaleButton | 🟩 | 🟩 | 🟩
3434
| VolumeButton | 🟩 | 🟫 | 🟩
3535
| AppChooserButton | 🟩 | 🟩 | 🟩
36-
| Scale | 🟩 | 🟫 | 🟩
37-
| Scrollbar |
36+
| Scale | 🟩 | 🟩 | 🟩
37+
| Scrollbar | 🟩 | 🟫 | 🟩

nativex/glib-object/src/nativeMain/kotlin/nativex/gobject/Signals.kt

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ object Signals {
327327

328328
// GtkAppChooserButton
329329
const val CUSTOM_ITEM_ACTIVATED = "custom-item-activated"
330+
331+
// GtkScale
332+
const val FORMAT_VALUE = "format-value"
330333
}
331334

332335

nativex/src/nativeMain/kotlin/nativex/gtk/widgets/range/Scale.kt

+83-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,49 @@
11
package nativex.gtk.widgets.range
22

3+
import glib.gpointer
4+
import gobject.GCallback
35
import gtk.*
46
import kotlinx.cinterop.*
57
import nativex.glib.bool
68
import nativex.glib.gtk
9+
import nativex.gobject.SignalManager
10+
import nativex.gobject.Signals
11+
import nativex.gobject.signalManager
712
import nativex.gtk.Adjustment
813
import nativex.gtk.Orientable
914
import nativex.gtk.common.enums.Orientation
1015
import nativex.gtk.common.enums.PositionType
16+
import nativex.pango.Layout
17+
import nativex.pango.Layout.Companion.wrap
1118

1219
/**
1320
* kotlinx-gtk
21+
*
1422
* 14 / 03 / 2021
23+
*
24+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html">GtkScale</a>
1525
*/
1626
class Scale(
17-
val scalePointer: CPointer<GtkScale>
27+
val scalePointer: CPointer<GtkScale>
1828
) : Range(scalePointer.reinterpret()), Orientable {
1929

2030
override val orientablePointer: CPointer<GtkOrientable> by lazy { scalePointer.reinterpret() }
2131

32+
/**
33+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-new">
34+
* gtk_scale_new</a>
35+
*/
2236
constructor(
2337
orientation: Orientation,
2438
adjustment: Adjustment? = null
2539
) : this(
2640
gtk_scale_new(orientation.gtk, adjustment?.adjustmentPointer)!!.reinterpret()
2741
)
2842

43+
/**
44+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-new-with-range">
45+
* gtk_scale_new_with_range</a>
46+
*/
2947
constructor(
3048
orientation: Orientation,
3149
min: Double,
@@ -40,18 +58,42 @@ class Scale(
4058
)!!.reinterpret()
4159
)
4260

61+
/**
62+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-get-digits">
63+
* gtk_scale_get_digits</a>
64+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-set-digits">
65+
* gtk_scale_set_digits</a>
66+
*/
4367
var digits: Int
4468
get() = gtk_scale_get_digits(scalePointer)
4569
set(value) = gtk_scale_set_digits(scalePointer, value)
4670

71+
/**
72+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-get-draw-value">
73+
* gtk_scale_get_draw_value</a>
74+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-set-draw-value">
75+
* gtk_scale_set_draw_value</a>
76+
*/
4777
var drawValue: Boolean
4878
get() = gtk_scale_get_draw_value(scalePointer).bool
4979
set(value) = gtk_scale_set_draw_value(scalePointer, value.gtk)
5080

81+
/**
82+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-get-has-origin">
83+
* gtk_scale_get_has_origin</a>
84+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-set-has-origin">
85+
* gtk_scale_set_has_origin</a>
86+
*/
5187
var hasOrigin: Boolean
5288
get() = gtk_scale_get_has_origin(scalePointer).bool
5389
set(value) = gtk_scale_set_has_origin(scalePointer, value.gtk)
5490

91+
/**
92+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-get-value-pos">
93+
* gtk_scale_get_value_pos</a>
94+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-set-value-pos">
95+
* gtk_scale_set_value_pos</a>
96+
*/
5597
var valuePos: PositionType
5698
get() = PositionType.valueOf(
5799
gtk_scale_get_value_pos(
@@ -60,10 +102,17 @@ class Scale(
60102
)!!
61103
set(value) = gtk_scale_set_value_pos(scalePointer, value.gtk)
62104

63-
fun getLayout() {
64-
TODO("gtk_scale_get_layout")
65-
}
105+
/**
106+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-get-layout">
107+
* gtk_scale_get_layout</a>
108+
*/
109+
val layout: Layout?
110+
get() = gtk_scale_get_layout(scalePointer).wrap()
66111

112+
/**
113+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-get-layout-offsets">
114+
* gtk_scale_get_layout_offsets</a>
115+
*/
67116
fun getLayoutOffsets(): Pair<Int, Int> {
68117
val x = cValue<IntVar>()
69118
val y = cValue<IntVar>()
@@ -73,6 +122,9 @@ class Scale(
73122
}
74123
}
75124

125+
/**
126+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-add-mark">gtk_scale_add_mark</a>
127+
*/
76128
fun addMark(
77129
value: Double,
78130
positionType: PositionType,
@@ -81,8 +133,34 @@ class Scale(
81133
gtk_scale_add_mark(scalePointer, value, positionType.gtk, markup)
82134
}
83135

136+
/**
137+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#gtk-scale-clear-marks">
138+
* gtk_scale_clear_marks</a>
139+
*/
84140
fun clearMarks() {
85141
gtk_scale_clear_marks(scalePointer)
86142
}
87143

88-
}
144+
/**
145+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#GtkScale-format-value">format-value</a>
146+
*/
147+
fun addOnFormatValueCallback(action: ScaleFormatValueFunction): SignalManager =
148+
signalManager(
149+
scalePointer,
150+
Signals.FORMAT_VALUE,
151+
StableRef.create(action).asCPointer(),
152+
staticFormatValueCallback
153+
)
154+
155+
companion object {
156+
private val staticFormatValueCallback: GCallback =
157+
staticCFunction { _: gpointer, value: Double, data: gpointer ->
158+
data.asStableRef<ScaleFormatValueFunction>().get().invoke(value).cstr
159+
}.reinterpret()
160+
}
161+
}
162+
163+
/**
164+
* @see <a href="https://developer.gnome.org/gtk3/stable/GtkScale.html#GtkScale-format-value">format-value</a>
165+
*/
166+
typealias ScaleFormatValueFunction = (value: Double) -> String

0 commit comments

Comments
 (0)