Skip to content

Commit 34f9e56

Browse files
committed
fix small UI bugs
1 parent 1fc747d commit 34f9e56

File tree

4 files changed

+59
-26
lines changed

4 files changed

+59
-26
lines changed

content/module-list.ui

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<object class="GtkBox">
5454
<property name="orientation">vertical</property>
5555
<child>
56-
<object class="GtkLabel">
56+
<object class="GtkLabel" id="basic_list_label">
5757
<property name="label">Basic Modules</property>
5858
<property name="xalign">0.0</property>
5959
<style>
@@ -70,7 +70,7 @@
7070
</object>
7171
</child>
7272
<child>
73-
<object class="GtkLabel">
73+
<object class="GtkLabel" id="input_output_list_label">
7474
<property name="label">Input/Output Modules</property>
7575
<property name="xalign">0.0</property>
7676
<style>
@@ -87,7 +87,7 @@
8787
</object>
8888
</child>
8989
<child>
90-
<object class="GtkLabel">
90+
<object class="GtkLabel" id="gate_list_label">
9191
<property name="label">Gate Modules</property>
9292
<property name="xalign">0.0</property>
9393
<style>
@@ -104,8 +104,8 @@
104104
</object>
105105
</child>
106106
<child>
107-
<object class="GtkLabel">
108-
<property name="label">Combinational Blocks</property>
107+
<object class="GtkLabel" id="combinational_list_label">
108+
<property name="label">Combinational Modules</property>
109109
<property name="xalign">0.0</property>
110110
<style>
111111
<class name="module_list_label"/>
@@ -121,7 +121,7 @@
121121
</object>
122122
</child>
123123
<child>
124-
<object class="GtkLabel">
124+
<object class="GtkLabel" id="latch_list_label">
125125
<property name="label">Latch Modules</property>
126126
<property name="xalign">0.0</property>
127127
<style>
@@ -138,7 +138,7 @@
138138
</object>
139139
</child>
140140
<child>
141-
<object class="GtkLabel">
141+
<object class="GtkLabel" id="flip_flop_list_label">
142142
<property name="label">Flip-Flop Modules</property>
143143
<property name="xalign">0.0</property>
144144
<style>
@@ -155,7 +155,7 @@
155155
</object>
156156
</child>
157157
<child>
158-
<object class="GtkLabel">
158+
<object class="GtkLabel" id="custom_list_label">
159159
<property name="label">Custom Modules</property>
160160
<property name="xalign">0.0</property>
161161
<style>
@@ -206,4 +206,4 @@
206206
</item>
207207
</section>
208208
</menu>
209-
</interface>
209+
</interface>

src/application/user_settings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Default for UserSettings {
2828
match instance.create_config() {
2929
Ok(_) => (),
3030
Err(_create_config_err) => {
31-
println!("Failed to create config, saving will not be enabled");
31+
error!("Failed to create config, saving will not be enabled");
3232
}
3333
}
3434
}

src/ui/circuit_view.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,12 @@ impl CircuitViewTemplate {
420420
fn drag_begin(&self, position: Vector2<i32>) {
421421
let selection = self.plot_provider.borrow().with(|p| p.selection().clone());
422422
match selection {
423-
Some(Selection::MoveBlock(block)) => self.application.borrow().new_action(
424-
Action::NewBlock(self.plot_provider.borrow().clone(), *block),
425-
),
423+
Some(Selection::MoveBlock(block)) => {
424+
let app = self.application.borrow();
425+
app.new_action(Action::NewBlock(self.plot_provider.borrow().clone(), *block));
426+
let window = app.imp().window().borrow();
427+
window.as_ref().unwrap().module_list().unselect_items();
428+
}
426429
Some(Selection::Many(block_ids)) => {
427430
if self.shift_down.get() && self.selection_shift_click(block_ids, position) {
428431
self.drawing_area.queue_draw();

src/ui/module_list.rs

+43-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*};
1+
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*, StateFlags};
22

33
use crate::{
44
application::{selection::*, Application},
@@ -70,6 +70,14 @@ impl ModuleList {
7070
pub fn show_search(&self) {
7171
self.imp().search_bar.set_search_mode(true);
7272
}
73+
74+
pub fn unselect_items(&self) {
75+
self.imp().lists().iter().for_each(|(list, _)|
76+
list.selected_rows().iter().for_each(|item|
77+
item.unset_state_flags(StateFlags::SELECTED)
78+
)
79+
);
80+
}
7381
}
7482

7583
#[gtk::template_callbacks]
@@ -103,24 +111,38 @@ pub struct ModuleListTemplate {
103111

104112
#[template_child]
105113
basic_list_box: TemplateChild<gtk::ListBox>,
114+
#[template_child]
115+
basic_list_label: TemplateChild<gtk::Label>,
106116

107117
#[template_child]
108118
input_output_list_box: TemplateChild<gtk::ListBox>,
119+
#[template_child]
120+
input_output_list_label: TemplateChild<gtk::Label>,
109121

110122
#[template_child]
111123
gate_list_box: TemplateChild<gtk::ListBox>,
124+
#[template_child]
125+
gate_list_label: TemplateChild<gtk::Label>,
112126

113127
#[template_child]
114128
combinational_list_box: TemplateChild<gtk::ListBox>,
129+
#[template_child]
130+
combinational_list_label: TemplateChild<gtk::Label>,
115131

116132
#[template_child]
117133
latch_list_box: TemplateChild<gtk::ListBox>,
134+
#[template_child]
135+
latch_list_label: TemplateChild<gtk::Label>,
118136

119137
#[template_child]
120138
flip_flop_list_box: TemplateChild<gtk::ListBox>,
139+
#[template_child]
140+
flip_flop_list_label: TemplateChild<gtk::Label>,
121141

122142
#[template_child]
123143
custom_list_box: TemplateChild<gtk::ListBox>,
144+
#[template_child]
145+
custom_list_label: TemplateChild<gtk::Label>,
124146

125147
#[template_child]
126148
search_bar: TemplateChild<gtk::SearchBar>,
@@ -143,14 +165,15 @@ impl ModuleListTemplate {
143165
}
144166
}
145167

146-
fn lists(&self) -> [&gtk::ListBox; 6] {
168+
fn lists(&self) -> [(&gtk::ListBox, &gtk::Label); 7] {
147169
[
148-
&self.basic_list_box,
149-
&self.input_output_list_box,
150-
&self.gate_list_box,
151-
&self.latch_list_box,
152-
&self.flip_flop_list_box,
153-
&self.custom_list_box,
170+
(&self.basic_list_box, &self.basic_list_label),
171+
(&self.input_output_list_box, &self.input_output_list_label),
172+
(&self.gate_list_box, &self.gate_list_label),
173+
(&self.combinational_list_box, &self.combinational_list_label),
174+
(&self.latch_list_box, &self.latch_list_label),
175+
(&self.flip_flop_list_box, &self.flip_flop_list_label),
176+
(&self.custom_list_box, &self.custom_list_label)
154177
]
155178
}
156179

@@ -207,6 +230,9 @@ impl ModuleListTemplate {
207230
.button(gdk::ffi::GDK_BUTTON_SECONDARY as u32)
208231
.build();
209232
item.add_controller(&right_click_gesture);
233+
// item.connect_state_flags_changed(|item, flags| {
234+
// item.unset_state_flags(StateFlags::SELECTED);
235+
// });
210236

211237
let name = module.name().to_owned();
212238
let is_builtin = module.builtin();
@@ -239,7 +265,7 @@ impl ModuleListTemplate {
239265
}
240266

241267
fn clear_list(&self) {
242-
self.lists().iter().for_each(|list| {
268+
self.lists().iter().for_each(|(list, _)| {
243269
while let Some(row) = list.row_at_index(0) {
244270
list.remove(&row);
245271
}
@@ -263,19 +289,23 @@ impl ModuleListTemplate {
263289
}
264290

265291
fn n_visible(&self) -> u32 {
266-
self.lists().iter().map(|list| list.n_visible()).sum()
292+
self.lists().iter().map(|(list, _)| list.n_visible()).sum()
267293
}
268294

269295
fn filter(&self, search_text: Option<String>) {
270296
if let Some(search_text) = search_text {
271-
self.lists().iter().for_each(move |list| {
297+
self.lists().iter().for_each(move |(list, label)| {
272298
let search_text = search_text.clone();
273299
list.set_filter_func(move |item| Self::filter_func(item, &search_text));
300+
label.set_visible(list.n_visible() != 0);
274301
});
275302
} else {
276303
self.lists()
277304
.iter()
278-
.for_each(|list| list.unset_filter_func());
305+
.for_each(|(list, label)| {
306+
list.unset_filter_func();
307+
label.set_visible(true);
308+
});
279309
}
280310

281311
self.stack.set_visible_child_name(if self.n_visible() == 0 {
@@ -333,7 +363,7 @@ impl ObjectImpl for ModuleListTemplate {
333363
};
334364
self.lists()
335365
.iter()
336-
.for_each(|list| list.set_sort_func(order_alphabetically));
366+
.for_each(|(list, _)| list.set_sort_func(order_alphabetically));
337367
}
338368
}
339369

0 commit comments

Comments
 (0)