Skip to content

Commit

Permalink
cleanups, more Pango functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Jan 15, 2023
1 parent 9086562 commit 14ab5f5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Gtk4"
uuid = "9db2cae5-386f-4011-9d63-a5602296539b"
version = "0.3.0"
version = "0.3.1"

[deps]
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
Expand Down
34 changes: 17 additions & 17 deletions src/GdkPixbufLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ eval(include("gen/gdkpixbuf_functions"))
end

# define accessor methods
skiplist = [ :file_info ]

for func in filter(x->startswith(string(x),"get_"),Base.names(G_,all=true))
ms=methods(getfield(GdkPixbufLib.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.isgetter(m) || continue
eval(GLib.gen_getter(func,v,m))
let skiplist = [ :file_info ]
for func in filter(x->startswith(string(x),"get_"),Base.names(G_,all=true))
ms=methods(getfield(GdkPixbufLib.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.isgetter(m) || continue
eval(GLib.gen_getter(func,v,m))
end
end
end

for func in filter(x->startswith(string(x),"set_"),Base.names(G_,all=true))
ms=methods(getfield(GdkPixbufLib.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.issetter(m) || continue
eval(GLib.gen_setter(func,v,m))
for func in filter(x->startswith(string(x),"set_"),Base.names(G_,all=true))
ms=methods(getfield(GdkPixbufLib.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.issetter(m) || continue
eval(GLib.gen_setter(func,v,m))
end
end
end

Expand Down
39 changes: 20 additions & 19 deletions src/Gtk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,27 @@ import .GLib: set_gtk_property!, get_gtk_property, run,
signal_handler_is_connected

# define accessor methods in Gtk4
skiplist = [:selected_rows, :selected, :selection_bounds, # handwritten methods from Gtk.jl are probably better
:filter, :string, :first, :error] # conflicts with Base exports

for func in filter(x->startswith(string(x),"get_"),Base.names(G_,all=true))
ms=methods(getfield(Gtk4.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.isgetter(m) || continue
eval(GLib.gen_getter(func,v,m))
let skiplist = [:selected_rows, :selected, :selection_bounds, # handwritten methods from Gtk.jl are probably better
:filter, :string, :first, :error] # conflicts with Base exports
for func in filter(x->startswith(string(x),"get_"),Base.names(G_,all=true))
ms=methods(getfield(Gtk4.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.isgetter(m) || continue
eval(GLib.gen_getter(func,v,m))
end
end
end

for func in filter(x->startswith(string(x),"set_"),Base.names(G_,all=true))
ms=methods(getfield(Gtk4.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.issetter(m) || continue
eval(GLib.gen_setter(func,v,m))
for func in filter(x->startswith(string(x),"set_"),Base.names(G_,all=true))
ms=methods(getfield(Gtk4.G_,func))
v=Symbol(string(func)[5:end])
v in skiplist && continue
for m in ms
GLib.issetter(m) || continue
eval(GLib.gen_setter(func,v,m))
end
end
end

Expand Down Expand Up @@ -112,8 +113,8 @@ function __init__()
Base.get(ENV, "XDG_DATA_DIRS", nothing)::Union{String,Nothing},
]), Sys.iswindows() ? ";" : ":")

gtype_wrapper_cache_init()
gboxed_cache_init()
gtype_wrapper_cache_init()
gboxed_cache_init()

if Sys.islinux() || Sys.isfreebsd()
# Needed by xkbcommon:
Expand Down
27 changes: 22 additions & 5 deletions src/Pango/Pango.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using ..GLib
using Glib_jll
using Pango_jll

import Base: convert, copy
import Base: convert, copy, length, getindex, iterate
import CEnum: @cenum, CEnum
import BitFlags: @bitflag, BitFlag

Expand Down Expand Up @@ -56,9 +56,26 @@ function __init__()
gboxed_cache_init()
end

default_font_map() = Pango.G_.font_map_get_default()
PangoLayout(cr::cairoContext) = Pango.G_.create_layout(cr)
PangoLayout(c::PangoContext) = Pango.G_.Layout_new(c)
PangoContext(fm::PangoFontMap) = Pango.G_.create_context(fm)
default_font_map() = G_.font_map_get_default()
length(fm::PangoFontMap) = length(GListModel(fm))
getindex(fm::PangoFontMap, i::Integer) = getindex(GListModel(fm),i)
iterate(fm::PangoFontMap, i=0) = iterate(GListModel(fm), i)
eltype(::Type{PangoFontMap}) = PangoFontFamily
Base.keys(fm::PangoFontMap) = 1:length(fm)

length(ff::PangoFontFamily) = length(GListModel(ff))
getindex(ff::PangoFontFamily, i::Integer) = getindex(GListModel(ff),i)
iterate(ff::PangoFontFamily, i=0) = iterate(GListModel(ff), i)
eltype(::Type{PangoFontFamily}) = PangoFontFace
Base.keys(ff::PangoFontFamily) = 1:length(ff)

PangoFontDescription() = G_.FontDescription_new()
PangoFontDescription(s::AbstractString) = G_.font_description_from_string(s)

PangoLayout(cr::cairoContext) = G_.create_layout(cr)
PangoLayout(c::PangoContext) = G_.Layout_new(c)

PangoContext(fm::PangoFontMap) = G_.create_context(fm)
getindex(pc::PangoContext, fd::PangoFontDescription) = G_.load_font(pc, fd)

end
4 changes: 0 additions & 4 deletions src/cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mutable struct GtkCanvas <: GtkDrawingArea # NOT a GType
function GtkCanvas(w = -1, h = -1)
da = G_.DrawingArea_new()
G_.set_size_request(da, w, h)
ids = Vector{Culong}(undef, 0)
widget = new(da.handle, false, nothing, nothing)

function on_realize(da::GtkWidget)
Expand Down Expand Up @@ -56,9 +55,6 @@ mutable struct GtkCanvas <: GtkDrawingArea # NOT a GType
end
end
const GtkCanvasLeaf = GtkCanvas
macro GtkCanvas(args...)
:( GtkCanvas($(map(esc, args)...)) )
end

function resize(config::Function, widget::GtkCanvas)
widget.resize = config
Expand Down
29 changes: 19 additions & 10 deletions test/families.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ using Test

@testset "families" begin

fm=Pango.default_font_map()
fams=Pango.G_.list_families(fm)
for fam in fams
@test isa(fam,PangoFontFamily)
end
fm=Pango.default_font_map()
l=length(fm)
i=0
for fam in fm
@test isa(fam, PangoFontFamily)
i=i+1
end
@test l == i

if length(fams)>0
faces=Pango.G_.list_faces(fams[1])
for face in faces
@test isa(face,PangoFontFace)
if length(fm)>0
l=length(fm[1])
i=0
for face in fm[1]
@test isa(face,PangoFontFace)
i=i+1
end
@test l == i
if length(fm[1])>0
@test isa(fm[1][1],PangoFontFace)
end
end
end

end
2 changes: 1 addition & 1 deletion test/layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ width,height=Pango.size(l)
@test logical.width == width
@test logical.height == height

#fd=Pango.get_font_description(l)
fd=Pango.font_description(l)


end

0 comments on commit 14ab5f5

Please sign in to comment.