Skip to content

Commit 7c8802a

Browse files
Add GdkRGBA, ColorChooserDialog, ColorButton (#533)
* Add GdkRGBA type * Add ColorChooserDialog and ColorButton types * Add ColorChooser tests
1 parent f267826 commit 7c8802a

File tree

9 files changed

+69
-7
lines changed

9 files changed

+69
-7
lines changed

src/buttons.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,7 @@ function GtkVolumeButtonLeaf(value::Real) # 0 <= value <= 1
163163
end
164164

165165
GtkFontButtonLeaf() = GtkFontButtonLeaf(ccall((:gtk_font_button_new, libgtk), Ptr{GObject}, ()))
166+
167+
GtkColorButtonLeaf() = GtkColorButtonLeaf(ccall((:gtk_color_button_new, libgtk), Ptr{GObject}, ()))
168+
GtkColorButtonLeaf(color::GdkRGBA) = GtkColorButtonLeaf(ccall((:gtk_color_button_new_with_rgba, libgtk), Ptr{GObject},
169+
(Ref{GdkRGBA},), color))

src/gdk.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ struct GdkPoint
1515
end
1616
# GdkPoint is not a GBoxed type
1717

18+
struct GdkRGBA
19+
r::Cdouble
20+
g::Cdouble
21+
b::Cdouble
22+
a::Cdouble
23+
GdkRGBA(r, g, b, a) = new(r, g, b, a)
24+
end
25+
@make_gvalue(GdkRGBA, Ptr{GdkRGBA}, :boxed, (:gdk_rgba,:libgdk))
26+
convert(::Type{GdkRGBA}, rgba::Ptr{GdkRGBA}) = unsafe_load(rgba)
27+
1828
baremodule GdkKeySyms
1929
const VoidSymbol = 0xffffff
2030
const BackSpace = 0xff08

src/gtktypes.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ end
110110
@gtktype GtkScrolledWindow
111111
@gtktype GtkAboutDialog
112112
@gtktype GtkMessageDialog
113+
@gtktype GtkColorChooserDialog
114+
@gtktype GtkColorButton
113115
@Gtype GApplication libgio g_application
114116
@Gtype GdkPixbuf libgdkpixbuf gdk_pixbuf
115117
#TODO: @gtktype GtkScaleButton

src/long_exports.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export GObject,
7676
GtkToggleToolButton,
7777
GtkTreeIter,
7878
GtkWindow,
79-
GtkEventBox
79+
GtkEventBox,
80+
GtkColorChooserDialog,
81+
GtkColorButton
8082

8183
# Gtk interfaces
8284
export GTypePlugin,

src/long_leaf_exports.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export
7474
@GtkTextBuffer,
7575
@GtkToggleButton,
7676
@GtkToggleToolButton,
77-
@GtkWindow
77+
@GtkWindow,
78+
@GtkColorChooserDialog,
79+
@GtkColorButton
7880

7981
# Gtk objects
8082
export
@@ -152,7 +154,9 @@ export
152154
GtkToggleButtonLeaf,
153155
GtkToggleToolButtonLeaf,
154156
GtkWindowLeaf,
155-
GtkEventBoxLeaf
157+
GtkEventBoxLeaf,
158+
GtkColorChooserDialogLeaf,
159+
GtkColorButtonLeaf
156160

157161

158162
# Gtk3 objects

src/selectors.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,21 @@ function save_dialog_native(title::AbstractString, parent = GtkNullContainer(),
178178
GLib.gc_unref(dlg) #destroy(dlg)
179179
return selection
180180
end
181+
182+
function GtkColorChooserDialogLeaf(title::AbstractString, parent::GtkContainer; kwargs...)
183+
return GtkColorChooserDialogLeaf(ccall((:gtk_color_chooser_dialog_new, libgtk), Ptr{GObject},
184+
(Ptr{UInt8}, Ptr{GObject}),
185+
title, parent); kwargs...)
186+
end
187+
188+
function color_chooser_dialog(title::AbstractString, parent = GtkNullContainer(); kwargs...)
189+
dlg = GtkColorChooserDialog(title, parent; kwargs...)
190+
response = run(dlg)
191+
if response == GConstants.GtkResponseType.OK
192+
selection = GAccessor.rgba(dlg)
193+
else
194+
selection = nothing
195+
end
196+
destroy(dlg)
197+
return selection
198+
end

src/short_exports.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const TreeViewColumn = GtkTreeViewColumn
7878
const VolumeButton = GtkVolumeButton
7979
const Window = GtkWindow
8080
const EventBox = GtkEventBox
81+
const ColorChooserDialog = GtkColorChooserDialog
82+
const ColorButton = GtkColorButton
8183

8284
export G_, GObject,
8385
AboutDialog,
@@ -156,7 +158,9 @@ export G_, GObject,
156158
TreeViewColumn,
157159
VolumeButton,
158160
Window,
159-
EventBox
161+
EventBox,
162+
ColorChooserDialog,
163+
ColorButton
160164

161165
const TypePlugin = GTypePlugin
162166
const Buildable = GtkBuildable

src/short_leaf_exports.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
@g_type_delegate TreeViewColumn = GtkTreeViewColumn
7575
@g_type_delegate VolumeButton = GtkVolumeButton
7676
@g_type_delegate Window = GtkWindow
77+
@g_type_delegate ColorChooserDialog = GtkColorChooserDialog
78+
@g_type_delegate ColorButton = GtkColorButton
7779

7880
export @G_,
7981
@AboutDialog,
@@ -149,7 +151,9 @@ export @G_,
149151
@TreeView,
150152
@TreeViewColumn,
151153
@VolumeButton,
152-
@Window
154+
@Window,
155+
@ColorChooserDialog,
156+
@ColorButton
153157

154158
export G_Leaf,
155159
AboutDialogLeaf,
@@ -222,7 +226,9 @@ export G_Leaf,
222226
TreeViewLeaf,
223227
TreeViewColumnLeaf,
224228
VolumeButtonLeaf,
225-
WindowLeaf
229+
WindowLeaf,
230+
ColorChooserDialog,
231+
ColorButton
226232

227233
# Gtk 3
228234
@g_type_delegate Grid = GtkGrid

test/gui.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,13 @@ w = Window(b, "VolumeButton", 50, 50)|>showall
416416
destroy(w)
417417
end
418418

419+
@testset "ColorButton" begin
420+
b = ColorButton(Gtk.GdkRGBA(0, 0.8, 1.0, 0.3))
421+
w = Window(b, "ColorButton", 50, 50)|>showall
422+
GAccessor.rgba(ColorChooser(b), GLib.mutable(Gtk.GdkRGBA(0, 0, 0, 0)))
423+
destroy(w)
424+
end
425+
419426
@testset "combobox" begin
420427
combo = ComboBoxText()
421428
choices = ["Strawberry", "Vanilla", "Chocolate"]
@@ -615,13 +622,18 @@ end
615622
#@test get_value(tr)[1] == choices[2]
616623
#destroy(w)
617624

618-
@testset "Selectors" begin
625+
@testset "File Chooser" begin
619626
dlg = FileChooserDialog("Select file", Null(), GtkFileChooserAction.OPEN,
620627
(("_Cancel", GtkResponseType.CANCEL),
621628
("_Open", GtkResponseType.ACCEPT)))
622629
destroy(dlg)
623630
end
624631

632+
@testset "Color Chooser" begin
633+
dlg = ColorChooserDialog("Select color", Null())
634+
destroy(dlg)
635+
end
636+
625637
@testset "List view" begin
626638
ls=ListStore(Int32,Bool)
627639
push!(ls,(44,true))

0 commit comments

Comments
 (0)