rename search result object and row
This commit is contained in:
parent
f95fa068f3
commit
f0542071d4
7 changed files with 35 additions and 35 deletions
61
examples/launcher/search_result_row/application_row.ui
Normal file
61
examples/launcher/search_result_row/application_row.ui
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="SearchResultRow" parent="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="spacing">12</property>
|
||||
<property name="margin-start">4</property>
|
||||
<property name="margin-end">4</property>
|
||||
<property name="hexpand">true</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="categoryimage">
|
||||
<property name="pixel-size">20</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage" id="image">
|
||||
<property name="margin-top">4</property>
|
||||
<property name="margin-bottom">4</property>
|
||||
<property name="pixel-size">36</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="halign">fill</property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="margin-top">4</property>
|
||||
<property name="margin-end">4</property>
|
||||
<property name="margin-bottom">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="name">
|
||||
<property name="halign">start</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="max-width-chars">40</property>
|
||||
<style>
|
||||
<class name="title-4" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="description">
|
||||
<property name="halign">start</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="max-width-chars">50</property>
|
||||
<style>
|
||||
<class name="body" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
<object class="GtkLabel" id="shortcut">
|
||||
<property name="halign">end</property>
|
||||
<property name="wrap">false</property>
|
||||
<style>
|
||||
<class name="body" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
40
examples/launcher/search_result_row/imp.rs
Normal file
40
examples/launcher/search_result_row/imp.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use gtk::glib;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::CompositeTemplate;
|
||||
|
||||
#[derive(Debug, Default, CompositeTemplate)]
|
||||
#[template(file = "application_row.ui")]
|
||||
pub struct SearchResultRow {
|
||||
#[template_child]
|
||||
pub name: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub description: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub shortcut: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub image: TemplateChild<gtk::Image>,
|
||||
#[template_child]
|
||||
pub categoryimage: TemplateChild<gtk::Image>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for SearchResultRow {
|
||||
const NAME: &'static str = "SearchResultRow";
|
||||
type Type = super::SearchResultRow;
|
||||
type ParentType = gtk::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
Self::bind_template(klass);
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for SearchResultRow {}
|
||||
impl WidgetImpl for SearchResultRow {}
|
||||
impl BoxImpl for SearchResultRow {}
|
||||
45
examples/launcher/search_result_row/mod.rs
Normal file
45
examples/launcher/search_result_row/mod.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use crate::icon_source;
|
||||
use crate::BoxedSearchResult;
|
||||
use gtk4 as gtk;
|
||||
mod imp;
|
||||
|
||||
use crate::SearchResultObject;
|
||||
use gtk::glib;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SearchResultRow(ObjectSubclass<imp::SearchResultRow>)
|
||||
@extends gtk::Widget, gtk::Box;
|
||||
}
|
||||
|
||||
impl Default for SearchResultRow {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl SearchResultRow {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).expect("Failed to create SearchResultRow")
|
||||
}
|
||||
|
||||
pub fn set_search_result(&self, search_obj: SearchResultObject) {
|
||||
let self_ = imp::SearchResultRow::from_instance(self);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_shortcut(&self, indx: u32) {
|
||||
let self_ = imp::SearchResultRow::from_instance(self);
|
||||
self_.shortcut.set_text(&format!("Ctrl + {}", indx));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue