libcosmic/examples/launcher/search_result_row/mod.rs

46 lines
1.3 KiB
Rust
Raw Normal View History

2021-12-30 16:54:35 -05:00
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
2021-11-30 16:15:06 -05:00
2021-12-30 16:54:35 -05:00
use crate::icon_source;
2021-12-30 17:53:06 -05:00
use crate::BoxedSearchResult;
use crate::SearchResultObject;
mod imp;
2021-11-30 16:15:06 -05:00
glib::wrapper! {
2021-12-28 11:19:55 -05:00
pub struct SearchResultRow(ObjectSubclass<imp::SearchResultRow>)
2021-12-30 16:54:35 -05:00
@extends gtk4::Widget, gtk4::Box;
2021-11-30 16:15:06 -05:00
}
2021-12-28 11:19:55 -05:00
impl Default for SearchResultRow {
2021-11-30 16:15:06 -05:00
fn default() -> Self {
Self::new()
}
}
2021-12-28 11:19:55 -05:00
impl SearchResultRow {
2021-11-30 16:15:06 -05:00
pub fn new() -> Self {
2021-12-28 11:19:55 -05:00
glib::Object::new(&[]).expect("Failed to create SearchResultRow")
2021-11-30 16:15:06 -05:00
}
2021-12-28 11:19:55 -05:00
pub fn set_search_result(&self, search_obj: SearchResultObject) {
let self_ = imp::SearchResultRow::from_instance(self);
2021-12-28 11:08:02 -05:00
if let Ok(search_result) = search_obj.property("data") {
if let Ok(search_result) = search_result.get::<BoxedSearchResult>() {
if let Some(search_result) = search_result.0 {
self_.name.set_text(&search_result.name);
self_.description.set_text(&search_result.description);
icon_source(&self_.image, &search_result.icon);
icon_source(&self_.categoryimage, &search_result.category_icon);
}
2021-11-30 16:15:06 -05:00
}
}
}
pub fn set_shortcut(&self, indx: u32) {
2021-12-28 11:19:55 -05:00
let self_ = imp::SearchResultRow::from_instance(self);
2021-11-30 16:15:06 -05:00
self_.shortcut.set_text(&format!("Ctrl + {}", indx));
}
}