Skip to content

Commit

Permalink
add a couple of methods and fix docs for GtkStack
Browse files Browse the repository at this point in the history
Also make the check for Gtk.jl more robust
  • Loading branch information
jwahlstrand committed Oct 14, 2023
1 parent eafd0bb commit d21e935
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions 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.5.3"
version = "0.5.4"

[deps]
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
Expand All @@ -26,7 +26,7 @@ hicolor_icon_theme_jll = "059c91fe-1bad-52ad-bddd-f7b78713c282"

[compat]
BitFlags = "0.1.5"
CEnum = "0.4.2"
CEnum = "0.4, 0.5"
Cairo = "1.0.0"
Cairo_jll = "1.16.0"
ColorTypes = "0.10, 0.11"
Expand Down
3 changes: 3 additions & 0 deletions docs/src/manual/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,16 @@ Julia interface methods defined for `GtkNotebook`:
The `GtkStack` widget is a lot like `GtkNotebook`, but a separate widget `GtkStackSwitcher` controls what page is shown.
An interface very similar to `GtkNotebook` is defined:
```julia
win = GtkWindow("GtkStack")
s = GtkStack()
sw = GtkStackSwitcher()
stack(sw,s)
vbox = GtkBox(:v)
push!(vbox, sw)
push!(vbox, s)
push!(s, GtkLabel("First label"), "id1", "Label 1") # first string is an id, second is a label
push!(s, GtkLabel("Second label"), "id2", "Label 2") # widget can be retrieved using s[id]
win[]=vbox
```

Julia interface methods defined for `GtkStack`:
Expand Down
2 changes: 1 addition & 1 deletion src/Gtk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function set_EGL_vendorlib_dirs(dirs)
end

function __init__()
in(:Gtk, names(Main, imported=true)) && error("Gtk4 is incompatible with Gtk.")
in("Gtk",[x.name for x in keys(Base.loaded_modules)]) && error("Gtk4 is incompatible with Gtk.")

# Set XDG_DATA_DIRS so that Gtk can find its icons and schemas
ENV["XDG_DATA_DIRS"] = join(filter(x -> x !== nothing, [
Expand Down
19 changes: 14 additions & 5 deletions src/layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,16 @@ function pushfirst!(w::GtkNotebook, x::GtkWidget, label::Union{GtkWidget, Abstra
G_.prepend_page(w, x, label) + 1
w
end
function push!(w::GtkNotebook, x::GtkWidget, label::Union{GtkWidget, AbstractString})
if isa(label, AbstractString)
label = G_.Label_new(label)
end
function push!(w::GtkNotebook, x::GtkWidget, label::AbstractString)
widget = G_.Label_new(label)
G_.append_page(w, x, widget) + 1
w
end
function push!(w::GtkNotebook, x::GtkWidget, label::GtkWidget)
G_.append_page(w, x, label) + 1
w
end

function splice!(w::GtkNotebook, i::Integer)
G_.remove_page(w, i - 1)
w
Expand Down Expand Up @@ -269,8 +272,14 @@ push!(s::GtkStack, x::GtkWidget, name::AbstractString) = (G_.add_named(s,x,name)
push!(s::GtkStack, x::GtkWidget, name::AbstractString, title::AbstractString) = (G_.add_titled(s,x,name,title); s)
getindex(s::GtkStack, name::AbstractString) = G_.get_child_by_name(s,name)
setindex!(s::GtkStack, x::GtkWidget, name::AbstractString) = G_.add_named(s,x,name)
delete!(s::GtkStack, x::GtkWidget) = (G_.remove(s,x); s)

stack(w::GtkStackSwitcher, s::GtkStack) = G_.set_stack(w,s)
function empty!(s::GtkStack)
while (w = G_.get_first_child(s)) !== nothing
G_.remove(s,w)
end
s
end

## GtkPopover

Expand Down

0 comments on commit d21e935

Please sign in to comment.