Commit f610f7d6 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

use a GtkEventBox & don't recolors the icons.

The icons are being recolored whenever the export dialog post backdrop state
Disable that as we don't need it.
parent cd33aaca
Pipeline #114172 passed with stages
in 9 minutes and 51 seconds
......@@ -4,6 +4,9 @@
padding: 6px;
}
/* Don't recolor the icons. */
.icon, .icon:backdrop { color: @theme_fg_color; }
.no-results-label {
font-size: 32px;
font-weight: bold;
......
......@@ -113,10 +113,10 @@
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_bottom">18</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">0</property>
<property name="margin_bottom">18</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
......@@ -132,6 +132,9 @@
<property name="can_focus">False</property>
<property name="pixel_size">16</property>
<property name="icon_name">image-missing-symbolic</property>
<style>
<class name="icon"/>
</style>
</object>
<packing>
<property name="expand">False</property>
......@@ -175,6 +178,9 @@
<property name="can_focus">False</property>
<property name="pixel_size">32</property>
<property name="icon_name">image-missing-symbolic</property>
<style>
<class name="icon"/>
</style>
</object>
<packing>
<property name="expand">False</property>
......@@ -218,6 +224,9 @@
<property name="can_focus">False</property>
<property name="pixel_size">64</property>
<property name="icon_name">image-missing-symbolic</property>
<style>
<class name="icon"/>
</style>
</object>
<packing>
<property name="expand">False</property>
......
......@@ -23,8 +23,8 @@ sources = files(
'models/icon.rs',
'models/icons.rs',
'models/mod.rs',
'widgets/icons.rs',
'widgets/export.rs',
'widgets/icons.rs',
'widgets/mod.rs',
'widgets/window.rs',
'application.rs',
......
use crate::application::Action;
use crate::models::Icon;
use glib::Sender;
use gtk::prelude::*;
use std::cell::RefCell;
use std::collections::HashMap;
......@@ -78,7 +79,6 @@ impl IconsViewContext {
icons_view_context.init();
icons_view_context.fill(icons);
icons_view_context.connect_signals();
icons_view_context
}
......@@ -100,26 +100,13 @@ impl IconsViewContext {
fn fill(&mut self, icons: Vec<Icon>) {
for icon in icons {
let icon_view = IconView::new(icon.clone());
let icon_view = IconView::new(self.sender.clone(), icon.clone());
self.icons_container.add(&icon_view.widget);
self.icons_views.insert(icon_view.widget, icon);
self.icons_views.insert(icon_view.widget, icon.clone());
}
self.widget.add(&self.icons_container);
}
fn connect_signals(&self) {
let sender = self.sender.clone();
let icons_views = self.icons_views.clone();
self.icons_container.connect_child_activated(move |_, child| {
match icons_views.get(child) {
Some(icon) => {
sender.send(Action::Export(icon.clone())).unwrap();
}
None => error!("Export Dialog: Couldn't find the icon"),
};
});
}
pub fn filter(&mut self, search_str: String) {
self.n_last_search_results = 0;
let icons_views = self.icons_views.clone();
......@@ -144,22 +131,37 @@ impl IconsViewContext {
struct IconView {
pub widget: gtk::FlowBoxChild,
icon: Icon,
sender: Sender<Action>,
}
impl IconView {
pub fn new(icon: Icon) -> IconView {
let icon_name = icon.name.as_str();
pub fn new(sender: Sender<Action>, icon: Icon) -> IconView {
let widget = gtk::FlowBoxChild::new();
let icon_view = IconView { widget, icon, sender };
icon_view.init();
icon_view
}
widget.set_halign(gtk::Align::Center);
widget.set_valign(gtk::Align::Center);
fn init(&self) {
// FlowBoxChild -> EventBox -> GtkImage
self.widget.set_halign(gtk::Align::Center);
self.widget.set_valign(gtk::Align::Center);
self.widget.set_tooltip_text(Some(&self.icon.name));
let icon_img = gtk::Image::new_from_icon_name(Some(icon_name), gtk::IconSize::Dnd);
widget.set_tooltip_text(Some(icon_name));
widget.add(&icon_img);
let event_box = gtk::EventBox::new();
let icon_view = IconView { widget };
icon_view
let icon = self.icon.clone();
let sender = self.sender.clone();
event_box.connect_button_press_event(move |_, _| {
sender.send(Action::Export(icon.clone())).unwrap();
gtk::Inhibit(false)
});
event_box.show();
self.widget.add(&event_box);
let icon_img = gtk::Image::new_from_icon_name(Some(&self.icon.name), gtk::IconSize::Dnd);
icon_img.get_style_context().add_class("icon");
event_box.add(&icon_img);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment