Skip to content

Commit

Permalink
fix small UI bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Spydr06 committed Feb 2, 2024
1 parent 1fc747d commit 34f9e56
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
18 changes: 9 additions & 9 deletions content/module-list.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="basic_list_label">
<property name="label">Basic Modules</property>
<property name="xalign">0.0</property>
<style>
Expand All @@ -70,7 +70,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="input_output_list_label">
<property name="label">Input/Output Modules</property>
<property name="xalign">0.0</property>
<style>
Expand All @@ -87,7 +87,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="gate_list_label">
<property name="label">Gate Modules</property>
<property name="xalign">0.0</property>
<style>
Expand All @@ -104,8 +104,8 @@
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Combinational Blocks</property>
<object class="GtkLabel" id="combinational_list_label">
<property name="label">Combinational Modules</property>
<property name="xalign">0.0</property>
<style>
<class name="module_list_label"/>
Expand All @@ -121,7 +121,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="latch_list_label">
<property name="label">Latch Modules</property>
<property name="xalign">0.0</property>
<style>
Expand All @@ -138,7 +138,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="flip_flop_list_label">
<property name="label">Flip-Flop Modules</property>
<property name="xalign">0.0</property>
<style>
Expand All @@ -155,7 +155,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="custom_list_label">
<property name="label">Custom Modules</property>
<property name="xalign">0.0</property>
<style>
Expand Down Expand Up @@ -206,4 +206,4 @@
</item>
</section>
</menu>
</interface>
</interface>
2 changes: 1 addition & 1 deletion src/application/user_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Default for UserSettings {
match instance.create_config() {
Ok(_) => (),
Err(_create_config_err) => {
println!("Failed to create config, saving will not be enabled");
error!("Failed to create config, saving will not be enabled");
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/ui/circuit_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,12 @@ impl CircuitViewTemplate {
fn drag_begin(&self, position: Vector2<i32>) {
let selection = self.plot_provider.borrow().with(|p| p.selection().clone());
match selection {
Some(Selection::MoveBlock(block)) => self.application.borrow().new_action(
Action::NewBlock(self.plot_provider.borrow().clone(), *block),
),
Some(Selection::MoveBlock(block)) => {
let app = self.application.borrow();
app.new_action(Action::NewBlock(self.plot_provider.borrow().clone(), *block));
let window = app.imp().window().borrow();
window.as_ref().unwrap().module_list().unselect_items();
}
Some(Selection::Many(block_ids)) => {
if self.shift_down.get() && self.selection_shift_click(block_ids, position) {
self.drawing_area.queue_draw();
Expand Down
56 changes: 43 additions & 13 deletions src/ui/module_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*};
use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*, StateFlags};

use crate::{
application::{selection::*, Application},
Expand Down Expand Up @@ -70,6 +70,14 @@ impl ModuleList {
pub fn show_search(&self) {
self.imp().search_bar.set_search_mode(true);
}

pub fn unselect_items(&self) {
self.imp().lists().iter().for_each(|(list, _)|
list.selected_rows().iter().for_each(|item|
item.unset_state_flags(StateFlags::SELECTED)
)
);
}
}

#[gtk::template_callbacks]
Expand Down Expand Up @@ -103,24 +111,38 @@ pub struct ModuleListTemplate {

#[template_child]
basic_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
basic_list_label: TemplateChild<gtk::Label>,

#[template_child]
input_output_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
input_output_list_label: TemplateChild<gtk::Label>,

#[template_child]
gate_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
gate_list_label: TemplateChild<gtk::Label>,

#[template_child]
combinational_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
combinational_list_label: TemplateChild<gtk::Label>,

#[template_child]
latch_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
latch_list_label: TemplateChild<gtk::Label>,

#[template_child]
flip_flop_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
flip_flop_list_label: TemplateChild<gtk::Label>,

#[template_child]
custom_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
custom_list_label: TemplateChild<gtk::Label>,

#[template_child]
search_bar: TemplateChild<gtk::SearchBar>,
Expand All @@ -143,14 +165,15 @@ impl ModuleListTemplate {
}
}

fn lists(&self) -> [&gtk::ListBox; 6] {
fn lists(&self) -> [(&gtk::ListBox, &gtk::Label); 7] {
[
&self.basic_list_box,
&self.input_output_list_box,
&self.gate_list_box,
&self.latch_list_box,
&self.flip_flop_list_box,
&self.custom_list_box,
(&self.basic_list_box, &self.basic_list_label),
(&self.input_output_list_box, &self.input_output_list_label),
(&self.gate_list_box, &self.gate_list_label),
(&self.combinational_list_box, &self.combinational_list_label),
(&self.latch_list_box, &self.latch_list_label),
(&self.flip_flop_list_box, &self.flip_flop_list_label),
(&self.custom_list_box, &self.custom_list_label)
]
}

Expand Down Expand Up @@ -207,6 +230,9 @@ impl ModuleListTemplate {
.button(gdk::ffi::GDK_BUTTON_SECONDARY as u32)
.build();
item.add_controller(&right_click_gesture);
// item.connect_state_flags_changed(|item, flags| {
// item.unset_state_flags(StateFlags::SELECTED);
// });

let name = module.name().to_owned();
let is_builtin = module.builtin();
Expand Down Expand Up @@ -239,7 +265,7 @@ impl ModuleListTemplate {
}

fn clear_list(&self) {
self.lists().iter().for_each(|list| {
self.lists().iter().for_each(|(list, _)| {
while let Some(row) = list.row_at_index(0) {
list.remove(&row);
}
Expand All @@ -263,19 +289,23 @@ impl ModuleListTemplate {
}

fn n_visible(&self) -> u32 {
self.lists().iter().map(|list| list.n_visible()).sum()
self.lists().iter().map(|(list, _)| list.n_visible()).sum()
}

fn filter(&self, search_text: Option<String>) {
if let Some(search_text) = search_text {
self.lists().iter().for_each(move |list| {
self.lists().iter().for_each(move |(list, label)| {
let search_text = search_text.clone();
list.set_filter_func(move |item| Self::filter_func(item, &search_text));
label.set_visible(list.n_visible() != 0);
});
} else {
self.lists()
.iter()
.for_each(|list| list.unset_filter_func());
.for_each(|(list, label)| {
list.unset_filter_func();
label.set_visible(true);
});
}

self.stack.set_visible_child_name(if self.n_visible() == 0 {
Expand Down Expand Up @@ -333,7 +363,7 @@ impl ObjectImpl for ModuleListTemplate {
};
self.lists()
.iter()
.for_each(|list| list.set_sort_func(order_alphabetically));
.for_each(|(list, _)| list.set_sort_func(order_alphabetically));
}
}

Expand Down

0 comments on commit 34f9e56

Please sign in to comment.