Remove duplicates

This commit is contained in:
hodasemi 2022-01-31 08:56:34 +01:00
parent 0ada3bfa28
commit ad11a23c9e
4 changed files with 36 additions and 6 deletions

View file

@ -141,7 +141,7 @@ impl Device {
.iter() .iter()
.map(|kind| { .map(|kind| {
( (
format!("{:?}", kind), code_to_string(kind),
match self.device.abs_info(kind) { match self.device.abs_info(kind) {
Some(abs_info) => Descriptor::Slider { Some(abs_info) => Descriptor::Slider {
min: abs_info.minimum, min: abs_info.minimum,
@ -165,7 +165,7 @@ impl Device {
.iter() .iter()
.map(|kind| { .map(|kind| {
( (
format!("{:?}", kind), code_to_string(kind),
match self.device.abs_info(kind) { match self.device.abs_info(kind) {
Some(abs_info) => Descriptor::Slider { Some(abs_info) => Descriptor::Slider {
min: abs_info.minimum, min: abs_info.minimum,
@ -182,7 +182,7 @@ impl Device {
.iter() .iter()
.map(|kind| { .map(|kind| {
( (
format!("{:?}", kind), code_to_string(kind),
match self.device.abs_info(kind) { match self.device.abs_info(kind) {
Some(abs_info) => Descriptor::Slider { Some(abs_info) => Descriptor::Slider {
min: abs_info.minimum, min: abs_info.minimum,
@ -197,7 +197,7 @@ impl Device {
EventType::EV_KEY => Some( EventType::EV_KEY => Some(
kinds kinds
.iter() .iter()
.map(|kind| (format!("{:?}", kind), Descriptor::Button)) .map(|kind| (code_to_string(kind), Descriptor::Button))
.collect(), .collect(),
), ),

View file

@ -666,3 +666,16 @@ pub fn ev_reps() -> &'static [EventCode] {
&EVENT_CODES &EVENT_CODES
} }
pub fn code_to_string(code: &EventCode) -> String {
match code {
EventCode::EV_KEY(key) => format!("{:?}", key),
EventCode::EV_REL(rel) => format!("{:?}", rel),
EventCode::EV_ABS(abs) => format!("{:?}", abs),
EventCode::EV_REP(rep) => format!("{:?}", rep),
EventCode::EV_FF(ff) => format!("{:?}", ff),
EventCode::EV_FF_STATUS(ffs) => format!("{:?}", ffs),
_ => panic!(),
}
}

View file

@ -55,7 +55,24 @@ pub fn draw_graph_editor(
node_finder_area = node_finder_area.current_pos(pos); node_finder_area = node_finder_area.current_pos(pos);
} }
node_finder_area.show(ctx, |ui| { node_finder_area.show(ctx, |ui| {
if let Some(node_device) = node_finder.show(devices, virtual_device.is_none(), ui) { // don't allow a nodes to be duplicated
let devs: Vec<&Device> = devices
.iter()
.filter(|device| {
let mut allow = true;
for (_node_id, node) in state.graph.nodes.iter() {
if node.op_name == device.name() {
allow = false;
break;
}
}
allow
})
.collect();
if let Some(node_device) = node_finder.show(&devs, virtual_device.is_none(), ui) {
let new_node = state.graph.add_node(node_device.to_descriptor()); let new_node = state.graph.add_node(node_device.to_descriptor());
state state
.node_positions .node_positions

View file

@ -41,7 +41,7 @@ impl NodeFinder {
/// the next frame. /// the next frame.
pub fn show<'a>( pub fn show<'a>(
&mut self, &mut self,
devices: &'a [Device], devices: &'a [&Device],
allow_virt_dev: bool, allow_virt_dev: bool,
ui: &mut Ui, ui: &mut Ui,
) -> Option<SelectedDevice<'a>> { ) -> Option<SelectedDevice<'a>> {