remove templates for app_library and cleanup window styling
This commit is contained in:
parent
7c0cf048ee
commit
346701b16d
15 changed files with 185 additions and 256 deletions
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GridItem" 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-start">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">64</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>
|
||||
|
|
@ -1,17 +1,14 @@
|
|||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gtk4::glib;
|
||||
use gtk4::prelude::*;
|
||||
use glib;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use gtk4::CompositeTemplate;
|
||||
|
||||
#[derive(Debug, Default, CompositeTemplate)]
|
||||
#[template(file = "grid_item.ui")]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct GridItem {
|
||||
#[template_child]
|
||||
pub name: TemplateChild<gtk4::Label>,
|
||||
#[template_child]
|
||||
pub image: TemplateChild<gtk4::Image>,
|
||||
pub name: Rc<RefCell<gtk4::Label>>,
|
||||
pub image: Rc<RefCell<gtk4::Image>>,
|
||||
pub index: Cell<u32>,
|
||||
}
|
||||
|
||||
|
|
@ -20,14 +17,6 @@ impl ObjectSubclass for GridItem {
|
|||
const NAME: &'static str = "GridItem";
|
||||
type Type = super::GridItem;
|
||||
type ParentType = gtk4::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 GridItem {}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
use cascade::cascade;
|
||||
use gdk4::ContentProvider;
|
||||
use gdk4::Display;
|
||||
use gio::File;
|
||||
use gio::Icon;
|
||||
use gtk4::pango::EllipsizeMode;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use gtk4::traits::WidgetExt;
|
||||
use gtk4::Align;
|
||||
use gtk4::DragSource;
|
||||
use gtk4::IconTheme;
|
||||
use gtk4::Image;
|
||||
use gtk4::Label;
|
||||
use gtk4::Orientation;
|
||||
use gtk4::{gio, glib};
|
||||
|
||||
use crate::app_group::AppGroup;
|
||||
|
|
@ -15,8 +21,8 @@ mod imp;
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct GridItem(ObjectSubclass<imp::GridItem>)
|
||||
@extends gtk4::Widget, gtk4::Box,
|
||||
@implements gtk4::Accessible, gtk4::Actionable, gtk4::Buildable, gtk4::ConstraintTarget;
|
||||
@extends gtk4::Widget, gtk4::Box,
|
||||
@implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget, gtk4::Orientable;
|
||||
}
|
||||
|
||||
impl Default for GridItem {
|
||||
|
|
@ -27,12 +33,46 @@ impl Default for GridItem {
|
|||
|
||||
impl GridItem {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).expect("Failed to create GridItem")
|
||||
let self_ = glib::Object::new(&[]).expect("Failed to create GridItem");
|
||||
let imp = imp::GridItem::from_instance(&self_);
|
||||
|
||||
cascade! {
|
||||
&self_;
|
||||
..set_orientation(Orientation::Vertical);
|
||||
..set_halign(Align::Center);
|
||||
..set_hexpand(true);
|
||||
..set_margin_top(4);
|
||||
..set_margin_bottom(4);
|
||||
..set_margin_end(4);
|
||||
..set_margin_start(4);
|
||||
};
|
||||
|
||||
let image = cascade! {
|
||||
Image::new();
|
||||
..set_margin_top(4);
|
||||
..set_margin_bottom(4);
|
||||
..set_pixel_size(64);
|
||||
};
|
||||
self_.append(&image);
|
||||
|
||||
let name = cascade! {
|
||||
Label::new(None);
|
||||
..set_halign(Align::Center);
|
||||
..set_hexpand(true);
|
||||
..set_ellipsize(EllipsizeMode::End);
|
||||
..add_css_class("title-5");
|
||||
};
|
||||
self_.append(&name);
|
||||
|
||||
imp.name.replace(name);
|
||||
imp.image.replace(image);
|
||||
|
||||
self_
|
||||
}
|
||||
|
||||
pub fn set_app_info(&self, app_info: &gio::DesktopAppInfo) {
|
||||
let self_ = imp::GridItem::from_instance(self);
|
||||
self_.name.set_text(&app_info.name());
|
||||
self_.name.borrow().set_text(&app_info.name());
|
||||
|
||||
let drag_controller = DragSource::builder()
|
||||
.name("application library drag source")
|
||||
|
|
@ -48,7 +88,7 @@ impl GridItem {
|
|||
let icon = app_info
|
||||
.icon()
|
||||
.unwrap_or(Icon::for_string("image-missing").expect("Failed to set default icon"));
|
||||
self_.image.set_from_gicon(&icon);
|
||||
self_.image.borrow().set_from_gicon(&icon);
|
||||
drag_controller.connect_drag_begin(glib::clone!(@weak icon, => move |_self, drag| {
|
||||
drag.set_selected_action(gdk4::DragAction::MOVE);
|
||||
// set drag source icon if possible...
|
||||
|
|
@ -72,14 +112,14 @@ impl GridItem {
|
|||
pub fn set_group_info(&self, app_group: AppGroup) {
|
||||
let self_ = imp::GridItem::from_instance(self);
|
||||
if let Ok(name) = app_group.property("name") {
|
||||
self_.name.set_text(
|
||||
self_.name.borrow().set_text(
|
||||
&name
|
||||
.get::<String>()
|
||||
.expect("property name needs to be a string."),
|
||||
);
|
||||
}
|
||||
if let Ok(icon) = app_group.property("icon") {
|
||||
self_.image.set_from_icon_name(Some(
|
||||
self_.image.borrow().set_from_icon_name(Some(
|
||||
&icon
|
||||
.get::<String>()
|
||||
.expect("Property name needs to be a String."),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue