refactor: rename app_library application row to app_item
This commit is contained in:
parent
b23ec4976f
commit
6484f886ed
5 changed files with 18 additions and 22 deletions
27
examples/app_library/app_item/app_item.ui
Normal file
27
examples/app_library/app_item/app_item.ui
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="AppItem" parent="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="halign">center</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="GtkImage" id="image">
|
||||
<property name="margin-top">4</property>
|
||||
<property name="margin-bottom">4</property>
|
||||
<property name="pixel-size">80</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="name">
|
||||
<property name="halign">center</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<style>
|
||||
<class name="title-5" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
34
examples/app_library/app_item/imp.rs
Normal file
34
examples/app_library/app_item/imp.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use gtk::glib;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::CompositeTemplate;
|
||||
|
||||
#[derive(Debug, Default, CompositeTemplate)]
|
||||
#[template(file = "app_item.ui")]
|
||||
pub struct AppItem {
|
||||
#[template_child]
|
||||
pub name: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub image: TemplateChild<gtk::Image>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for AppItem {
|
||||
const NAME: &'static str = "AppItem";
|
||||
type Type = super::AppItem;
|
||||
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 AppItem {}
|
||||
impl WidgetImpl for AppItem {}
|
||||
impl BoxImpl for AppItem {}
|
||||
31
examples/app_library/app_item/mod.rs
Normal file
31
examples/app_library/app_item/mod.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use gtk4 as gtk;
|
||||
mod imp;
|
||||
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct AppItem(ObjectSubclass<imp::AppItem>)
|
||||
@extends gtk::Widget, gtk::Box;
|
||||
}
|
||||
|
||||
impl Default for AppItem {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl AppItem {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).expect("Failed to create AppItem")
|
||||
}
|
||||
|
||||
pub fn set_app_info(&self, app_info: &gio::AppInfo) {
|
||||
let self_ = imp::AppItem::from_instance(self);
|
||||
self_.name.set_text(&app_info.name());
|
||||
if let Some(icon) = app_info.icon() {
|
||||
self_.image.set_from_gicon(&icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue