Re: initialize `background-image` with a resource file
Andrew Potter via gtkmm-list <[email protected]> Tue, 23 Aug 2022 12:21:19 -0700
| Newsgroups | gmane.comp.gnome.gtkmm |
|---|---|
| Message-ID | <CABgWb1K--iwL+db+9EWaiEGRTnED1KoQ-n2ijGYX971vjgr79w@mail.gmail.com> |
--===============8926227563109266971== Content-Type: multipart/alternative; boundary="000000000000b6ee6305e6ed7868" --000000000000b6ee6305e6ed7868 Content-Type: text/plain; charset="UTF-8" On Tue, Aug 23, 2022 at 10:44 AM Master via gtkmm-list <[email protected]> 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 --000000000000b6ee6305e6ed7868 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr">On Tue, Aug 23, 2022 at 10:44 AM Master v= ia gtkmm-list <<a href=3D"mailto:[email protected]">gtkmm-list@gnome.= org</a>> wrote:<br></div><div class=3D"gmail_quote"><blockquote class=3D= "gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2= 04,204,204);padding-left:1ex"><div dir=3D"rtl"><div dir=3D"ltr">The problem= is that I dont know how to tell the `background-image` inside the style pr= ovider to "get the image from resource" instead of "file&quo= t; please help me.=C2=A0</div></div></blockquote><div>Hello,</div><div>You = can set background image to a resource like:<br></div><table class=3D"gmail= -highlight gmail-tab-size gmail-js-file-line-container gmail-js-code-nav-co= ntainer gmail-js-tagsearch-file" style=3D"border-spacing:0px;border-collaps= e:collapse;color:rgb(36,41,47);font-family:-apple-system,BlinkMacSystemFont= ,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji&qu= ot;,"Segoe UI Emoji";font-size:14px"><tbody style=3D"box-sizing:b= order-box"><tr style=3D"box-sizing:border-box"><td id=3D"gmail-LC17" class= =3D"gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style=3D"box-= sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;over= flow:visible;font-family:ui-monospace,SFMono-Regular,"SF Mono",Me= nlo,Consolas,"Liberation Mono",monospace;font-size:12px;white-spa= ce:pre"><span class=3D"gmail-pl-c1" style=3D"box-sizing:border-box">backgro= und-image</span><span class=3D"gmail-pl-kos" style=3D"box-sizing:border-box= ">:</span> <span class=3D"gmail-pl-en" style=3D"box-sizing:border-box">url<= /span>(<span class=3D"gmail-pl-s" style=3D"box-sizing:border-box">"res= ource:///org/custom/example/sonbg.jpg"</span>);</td></tr><tr style=3D"= box-sizing:border-box;background-color:transparent"><td id=3D"gmail-L18" cl= ass=3D"gmail-blob-num gmail-js-line-number gmail-js-code-nav-line-number gm= ail-js-blob-rnum" style=3D"box-sizing:border-box;padding:0px 10px;width:50p= x;min-width:50px;font-family:ui-monospace,SFMono-Regular,"SF Mono"= ;,Menlo,Consolas,"Liberation Mono",monospace;font-size:12px;line-= height:20px;text-align:right;white-space:nowrap;vertical-align:top"></td></= tr></tbody></table>Of course, you must define a gresource xml (Here, I'= ve used the gresource prefix org/custom/example, but you will want to use y= our own namespace), compile it with glib-compile-resources and include it i= n your build system appropriately.</div><div class=3D"gmail_quote"><br></di= v><div class=3D"gmail_quote">This is detailed in the GResource documentatio= n at=C2=A0<a href=3D"https://docs.gtk.org/gio/struct.Resource.html">https:/= /docs.gtk.org/gio/struct.Resource.html</a> or in the gtkmm documentation at= =C2=A0<a href=3D"https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1Re= source.html#details">https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1= _1Resource.html#details</a></div><div class=3D"gmail_quote"><br></div><div = class=3D"gmail_quote">I have a toy application on github that does this if = you need a more concrete example. The C++ code in=C2=A0<a href=3D"https://g= ithub.com/talisein/mikuexpocountdown/blob/main/src/window.h">https://github= .com/talisein/mikuexpocountdown/blob/main/src/window.h</a> loads the CSS fr= om a resource, and that css references the gresources in=C2=A0<a href=3D"ht= tps://github.com/talisein/mikuexpocountdown/tree/main/res">https://github.c= om/talisein/mikuexpocountdown/tree/main/res</a></div></div> --000000000000b6ee6305e6ed7868-- --===============8926227563109266971== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ gtkmm-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/gtkmm-list --===============8926227563109266971==--