@@ 100,6 100,7 @@ impl relm::Widget for StudyPage {
}
view! {
+ #[name="page"]
gtk::Box {
child: {
expand: true
@@ 157,6 158,13 @@ impl StudyPage {
self.widgets.content.remove(&child);
}
+ let space = self.widgets.page.toplevel().unwrap().allocation();
+
+ let available_width = space.width() - 60; // ???
+ let available_height = space.height() - 60;
+
+ println!("{} {}", available_width, available_height);
+
if let Some(card) = &self.model.current_card {
let template = if self.model.flipped {
&card.card_spec.back_template
@@ 218,8 226,11 @@ impl StudyPage {
let bytes = glib::Bytes::from_owned(bytes);
- Ok(gdk_pixbuf::Pixbuf::from_stream(
+ Ok(gdk_pixbuf::Pixbuf::from_stream_at_scale(
&gio::MemoryInputStream::from_bytes(&bytes),
+ available_width,
+ available_height,
+ true,
gio::Cancellable::NONE,
)?)
});
@@ 228,7 239,13 @@ impl StudyPage {
Ok(img) => {
commit_current_text(&mut current_text);
- let img_view = gtk::Image::from_pixbuf(Some(&img));
+ let img_view = gtk::Image::builder()
+ .pixbuf(&img)
+ .width_request(0)
+ .height_request(0)
+ .halign(gtk::Align::Center)
+ .hexpand(true)
+ .build();
self.widgets.content.add(&img_view);
}
Err(err) => {