Initial implementation of #6 Gresource support.
This commit is contained in:
@@ -10,6 +10,10 @@ gdk = "0.6"
|
||||
glib = "0.3"
|
||||
gio = "0.2"
|
||||
gdk-pixbuf = "0.2"
|
||||
libc = "0.2"
|
||||
|
||||
gio-sys = "0.4"
|
||||
glib-sys = "^0.4"
|
||||
|
||||
loggerv = "0.4"
|
||||
log = "0.3"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
Command::new("glib-compile-resources")
|
||||
.args(&["--generate", "resources.xml"])
|
||||
.current_dir("src/resources")
|
||||
.status()
|
||||
.unwrap();
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
<object class="GtkFlowBox" id="flowbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="halign">baseline</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<property name="column_spacing">5</property>
|
||||
|
||||
@@ -47,6 +47,7 @@ mod widgets;
|
||||
mod headerbar;
|
||||
|
||||
mod utils;
|
||||
mod static_resource;
|
||||
|
||||
use views::podcasts_view;
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/org/gtk/hammond">
|
||||
<file>banner.png</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
@@ -0,0 +1,18 @@
|
||||
extern crate gio_sys;
|
||||
extern crate glib_sys;
|
||||
extern crate libc;
|
||||
|
||||
use std;
|
||||
|
||||
// https://github.com/sunnyone/gresource-gtkrs-example/blob/master/src/static_resource.rs
|
||||
// TODO: slomo mentioned that the unsafe could be removed and use a safe API instead.
|
||||
pub fn init() {
|
||||
let res_bytes = include_bytes!("resources/resources.gresource");
|
||||
unsafe {
|
||||
// gbytes and resource will not be freed
|
||||
let gbytes =
|
||||
glib_sys::g_bytes_new(res_bytes.as_ptr() as *const libc::c_void, res_bytes.len());
|
||||
let resource = gio_sys::g_resource_new_from_data(gbytes, std::ptr::null_mut());
|
||||
gio_sys::g_resources_register(resource);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use hammond_data::models::Podcast;
|
||||
use hammond_data::index_feed::Database;
|
||||
|
||||
use widgets::podcast::*;
|
||||
use static_resource;
|
||||
|
||||
fn show_empty_view(stack: >k::Stack) {
|
||||
let builder = gtk::Builder::new_from_string(include_str!("../../gtk/empty_view.ui"));
|
||||
@@ -61,8 +62,10 @@ fn create_flowbox_child(db: &Database, pd: &Podcast) -> gtk::FlowBoxChild {
|
||||
}
|
||||
|
||||
fn configure_banner(db: &Database, pd: &Podcast, banner: >k::Image, banner_title: >k::Label) {
|
||||
// TODO: use GResource instead.
|
||||
let bann = Pixbuf::new_from_file_at_scale("hammond-gtk/gtk/banner.png", 256, 256, true);
|
||||
// TODO: move .ui files into gresources and refactor.
|
||||
static_resource::init();
|
||||
|
||||
let bann = Pixbuf::new_from_resource_at_scale("/org/gtk/hammond/banner.png", 256, 256, true);
|
||||
if let Ok(b) = bann {
|
||||
banner.set_from_pixbuf(&b);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user