layout and fix

This commit is contained in:
leca 2024-04-08 16:34:14 +03:00
parent 5f768be350
commit 1be42eb584
8 changed files with 40 additions and 14 deletions

View File

@ -38,6 +38,14 @@
<property name="vexpand">true</property>
<child>
<object class="GtkBox" id="cards_container">
<property name="valign">GTK_ALIGN_FILL</property>
<property name="halign">GTK_ALIGN_FILL</property>
<property name="orientation">vertical</property>
<property name="hexpand">true</property>
<property name="hexpand-set">true</property>
<property name="vexpand">true</property>
<property name="vexpand-set">true</property>
<property name="homogeneous">true</property>
<property name="orientation">vertical</property>
<property name="halign">GTK_ALIGN_FILL</property>
<property name="valign">GTK_ALIGN_FILL</property>

View File

@ -5,6 +5,7 @@
<child>
<object class="GtkBox" id="content">
<property name="orientation">vertical</property>
<property name="valign">GTK_ALIGN_CENTER</property>
<child>
<object class="CardDisplay" id="card_display"></object>
</child>

View File

@ -6,9 +6,6 @@
<property name="width-request">512</property>
<child>
<object class="GtkBox" id="content">
<property name="orientation">vertical</property>
<property name="halign">GTK_ALIGN_CENTER</property>
<property name="valign">GTK_ALIGN_CENTER</property>
<child>
<object class="GtkPicture" id="picture">
<property name="halign">GTK_ALIGN_CENTER</property>

View File

@ -7,6 +7,12 @@
<property name="valign">GTK_ALIGN_CENTER</property>
</object>
</child>
<child>
<object class="GtkLabel" id="error_message">
<property name="visible">false</property>
<property name="label">No card image found in database. If you think this is an error, please, create an issue.</property>
</object>
</child>
<child>
<object class="GtkEntry" id="answer_entry">
<property name="halign">GTK_ALIGN_CENTER</property>

View File

@ -3,26 +3,26 @@
<template class="CardEntry" parent="GtkWidget">
<child>
<object class="GtkPicture" id="picture">
<property name="halign">GTK_ALIGN_CENTER</property>
<property name="halign">GTK_ALIGN_START</property>
<property name="valign">GTK_ALIGN_CENTER</property>
</object>
</child>
<child>
<object class="GtkLabel" id="hieroglyph_label">
<property name="halign">GTK_ALIGN_START</property>
<property name="valign">GTK_ALIGN_START</property>
<property name="valign">GTK_ALIGN_CENTER</property>
</object>
</child>
<child>
<object class="GtkLabel" id="reading_label">
<property name="halign">GTK_ALIGN_START</property>
<property name="valign">GTK_ALIGN_START</property>
<property name="valign">GTK_ALIGN_CENTER</property>
</object>
</child>
<child>
<object class="GtkButton" id="delete_button">
<property name="halign">GTK_ALIGN_END</property>
<property name="valign">GTK_ALIGN_END</property>
<property name="valign">GTK_ALIGN_CENTER</property>
<property name="label">delete</property>
</object>
</child>

View File

@ -84,7 +84,7 @@ impl ObjectImpl for MemoryCardsEditScene {
);
binding.imp().update_card_list();
}));
self.update_card_list();
// self.update_card_list();
}
}
@ -139,8 +139,10 @@ impl MemoryCardsEditScene {
let connection = Connection::open(get_db_path()).unwrap();
let imagepath = card.imagepath();
let imagename = &Path::new(&imagepath).file_name().unwrap().to_str().unwrap();
dbg!("removing {}", imagename);
fs::remove_file(get_images_store_path() + "/" + &imagename).expect("Could not remove file!");
connection.execute("DELETE FROM cards WHERE imagename = ?1", [&imagename]).unwrap();
self_binding.imp().query_cards(None);
self_binding.imp().update_card_list();
}));
card.update_file_for_picture();

View File

@ -3,7 +3,7 @@ use std::cell::RefCell;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Picture};
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Label, Picture};
#[derive(CompositeTemplate, Properties, Default)]
#[properties(wrapper_type = super::CardDisplay)]
@ -13,6 +13,8 @@ pub struct CardDisplay {
pub picture: TemplateChild<Picture>,
#[template_child]
pub answer_entry: TemplateChild<Entry>,
#[template_child]
pub error_message: TemplateChild<Label>,
#[property(get, set)]
pub imagepath: RefCell<String>,
#[property(get, set)]
@ -42,6 +44,10 @@ impl ObjectImpl for CardDisplay {
let layout_manager: BoxLayout = BoxLayout::new(gtk::Orientation::Vertical);
self.obj().set_layout_manager(Some(layout_manager));
self.picture.set_width_request(256);
self.picture.set_height_request(256);
// self.picture.
// self.picture.set
}
fn dispose(&self) {

View File

@ -3,7 +3,7 @@ mod imp;
use std::cell::RefCell;
use glib::Object;
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Entry, Picture};
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, prelude::*, Entry, Picture};
use rusqlite::Connection;
use crate::db::{get_db_path, get_images_store_path};
@ -32,10 +32,13 @@ impl CardDisplay {
pub fn update_file_for_picture(&self) {
let picture_binding: &Picture = self.imp().picture.as_ref();
let path: &str = &*self.imp().imagepath.borrow().clone().to_string();
if path == "" {
self.imp().error_message.set_visible(true);
return;
}
picture_binding.set_file(Some(&gio::File::for_path(path)));
}
pub fn generate_card(&self) -> (&RefCell<String>, &RefCell<String>) {
pub fn generate_card(&self) -> Option<(&RefCell<String>, &RefCell<String>)> {
let connection = Connection::open(get_db_path()).unwrap();
let mut stmt = connection.prepare("SELECT imagename, hieroglyph FROM cards ORDER BY RANDOM() LIMIT 1").unwrap();
@ -52,14 +55,17 @@ impl CardDisplay {
for i in random_card_iter {
random_card = Some(i.unwrap());
}
let random_card: Card = random_card.unwrap();
let random_card: Card = match random_card {
Some(card) => card,
None => return None
};
*self.imp().imagepath.borrow_mut() = get_images_store_path() + "/" + random_card.imagename.as_str();
*self.imp().hieroglyph.borrow_mut() = random_card.hieroglyph;
self.update_file_for_picture();
(&self.imp().imagepath, &self.imp().hieroglyph)
Some((&self.imp().imagepath, &self.imp().hieroglyph))
}
pub fn get_answer_entry(&self) -> &Entry {