update ui

This commit is contained in:
2024-04-09 16:42:13 +03:00
parent eb26ca7418
commit c376dbc01a
8 changed files with 80 additions and 76 deletions

View File

@@ -3,14 +3,14 @@ use std::cell::RefCell;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Label, Picture};
use gtk::{glib, prelude::*, BoxLayout, CompositeTemplate, Entry, Label, Image};
#[derive(CompositeTemplate, Properties, Default)]
#[properties(wrapper_type = super::CardDisplay)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_display/template.ui.xml")]
pub struct CardDisplay {
#[template_child]
pub picture: TemplateChild<Picture>,
pub image: TemplateChild<Image>,
#[template_child]
pub answer_entry: TemplateChild<Entry>,
#[template_child]
@@ -44,10 +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
self.image.set_width_request(256);
self.image.set_height_request(256);
// self.image.
// self.image.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}, prelude::*, Entry, Picture};
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, prelude::*, Entry, Image};
use rusqlite::Connection;
use crate::db::{get_db_path, get_images_store_path};
@@ -29,14 +29,14 @@ impl CardDisplay {
.build()
}
pub fn update_file_for_picture(&self) {
let picture_binding: &Picture = self.imp().picture.as_ref();
pub fn update_file_for_image(&self) {
let image_binding: &Image = self.imp().image.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)));
image_binding.set_file(Some(&path));
}
pub fn generate_card(&self) -> Option<(&RefCell<String>, &RefCell<String>)> {
let connection = Connection::open(get_db_path()).unwrap();
@@ -63,7 +63,7 @@ impl CardDisplay {
*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.update_file_for_image();
Some((&self.imp().imagepath, &self.imp().hieroglyph))
}

View File

@@ -3,14 +3,14 @@ use std::cell::RefCell;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, Button, CompositeTemplate, Label, Picture};
use gtk::{glib, prelude::*, Button, CompositeTemplate, Label, Image};
#[derive(CompositeTemplate, Properties, Default)]
#[properties(wrapper_type = super::CardEntry)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/widgets/card_entry/template.ui.xml")]
pub struct CardEntry {
#[template_child]
pub picture: TemplateChild<Picture>,
pub image: TemplateChild<Image>,
#[template_child]
pub hieroglyph_label: TemplateChild<Label>,
#[template_child]

View File

@@ -4,7 +4,7 @@ use glib::Object;
use gtk::{
gio,
glib::{self, subclass::types::ObjectSubclassIsExt},
Button, Picture,
Button, Image,
};
glib::wrapper! {
@@ -23,17 +23,17 @@ impl CardEntry {
.build()
}
pub fn get_picture_widget(&self) -> &Picture {
self.imp().picture.as_ref()
pub fn get_image_widget(&self) -> &Image {
self.imp().image.as_ref()
}
pub fn get_delete_button_widget(&self) -> &Button {
self.imp().delete_button.as_ref()
}
pub fn update_file_for_picture(&self) {
let picture_binding: &Picture = self.imp().picture.as_ref();
pub fn update_file_for_image(&self) {
let image_binding: &Image = self.imp().image.as_ref();
let path: &str = &*self.imp().imagepath.borrow().clone().to_string();
picture_binding.set_file(Some(&gio::File::for_path(path)));
image_binding.set_file(Some(&path));
}
}