Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

When CSS on screen has effect? #678

Open
rossati opened this issue Dec 5, 2022 · 0 comments
Open

When CSS on screen has effect? #678

rossati opened this issue Dec 5, 2022 · 0 comments

Comments

@rossati
Copy link

rossati commented Dec 5, 2022

Hello
I have set some CSS at screen level but they don't act immediately, but only at the second run (sometimes at the third).
This happens both in Julia command line and in Visual Studio.
Here below a minimal example:

using GTK3_jll
const libgtk = libgtk3
const libgdk = libgdk3
using Gtk, Gtk.ShortNames
function fg_set_CSS(css::String)
    provider = convert(GObject,ccall((:gtk_css_provider_new, libgtk), Ptr{GObject},()))
    display = convert(GObject,ccall((:gdk_display_get_default,libgdk), Ptr{GObject}, ()))
    screen = convert(GObject,ccall((:gdk_display_get_default_screen,libgdk),Ptr{GObject},(Ptr{GObject},),display))
    ccall((:gtk_style_context_add_provider_for_screen,libgtk),Cvoid,(Ptr{GObject},Ptr{GObject}),screen,provider)
    ccall((:gtk_css_provider_load_from_data,libgtk),Bool,(Ptr{GObject}, Ptr{UInt8}, Clong, Ptr{C_NULL}),
    provider, css,-1, Ptr{Ptr{Cchar}}())
    return provider
end
function fg_reset_CSS(provider)
  display = convert(GObject,ccall((:gdk_display_get_default,libgdk), Ptr{GObject}, ()))
  screen = convert(GObject,ccall((:gdk_display_get_default_screen,libgdk),Ptr{GObject},(Ptr{GObject},),display))
  ccall((:gtk_style_context_remove_provider_for_screen,libgtk),Cvoid,(Ptr{GObject},Ptr{GObject}),screen,provider)
end
CSSStyles = """
#fg_btn {background-image: image(#aaa);font: 20px \"sans\";color:red}
#fg_btn:hover {background-image: image(#eee)}
#fg_btn:active {background-image: image(#ddd)}
#fg_window {background: navy}
#sld {min-width: 180px;}
"""
pr = fg_set_CSS(CSSStyles)
g = GtkGrid()
fg_win = GtkWindow("Minimal example")
set_gtk_property!(fg_win, :name,"fg_window")
g[1,1] = GtkButton("\u22EF\u22EF")
set_gtk_property!(g[1,1], :name,"fg_btn")
sld = GtkScale(false, 0:30)
set_gtk_property!(sld, :value_pos, 1)
set_gtk_property!(sld, :name, "sld")
set_gtk_property!(sld, :digits, 3)
g[1,4] = sld
push!(fg_win,g)
#showall(fg_win)
@idle_add showall(fg_win)
signal_connect(fg_win, :destroy) do widget
  fg_reset_CSS(pr)   # remove screen styles
  Gtk.gtk_quit()
  println("See you later alligator")
end

Thanks for any suggestion
Rossati Giovanni

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant