Re: initialize `background-image` with a resource file

2022-08-23 Thread Andrew Potter via gtkmm-list
On Tue, Aug 23, 2022 at 10:44 AM Master via gtkmm-list 
wrote:

> The problem is that I dont know how to tell the `background-image` inside
> the style provider to "get the image from resource" instead of "file"
> please help me.
>
Hello,
You can set background image to a resource like:
background-image: url("resource:///org/custom/example/sonbg.jpg");
Of course, you must define a gresource xml (Here, I've used the gresource
prefix org/custom/example, but you will want to use your own namespace),
compile it with glib-compile-resources and include it in your build system
appropriately.

This is detailed in the GResource documentation at
https://docs.gtk.org/gio/struct.Resource.html or in the gtkmm documentation
at
https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1Resource.html#details

I have a toy application on github that does this if you need a more
concrete example. The C++ code in
https://github.com/talisein/mikuexpocountdown/blob/main/src/window.h loads
the CSS from a resource, and that css references the gresources in
https://github.com/talisein/mikuexpocountdown/tree/main/res
___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


initialize `background-image` with a resource file

2022-08-23 Thread Master via gtkmm-list
in my gtkmm app i have a label that has a background image thanks to css
provider. like this:
```
MainWindow::MainWindow():
Mylabel(Hello)
{
provider = Gtk::CssProvider::create();
provider->load_from_data(
"#LogoLabel{"
//"color:#80;"
//"color:#5485ae;"
"color:#0075ff;"
"}"
"#PleaseHitKeyLbl{"
"background-color:#337a;"
"font-size:20px;"
"}"
"#BackgroundImage{"
"background-image:url(\"file:///home/ali/Desktop/sonbg.jpg\");"
"background-size:100% 100%;"
"opacity:0.3;"
"}"
);
MyLabel.set_name("BackgroundImage");
MyLabel.get_style_context()->add_provider(provider, 1);
}
```
The problem is that I dont know how to tell the `background-image` inside
the style provider to "get the image from resource" instead of "file"
please help me.
Regards.
___
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list