From 475a83fab7a5727b5a4ac1147829e6ebca8b0808 Mon Sep 17 00:00:00 2001 From: "Tom A. Wagner" Date: Wed, 19 Jul 2023 12:26:59 +0200 Subject: [PATCH] Restructure view module into ui folder, graph specific widgets into graph subfolder --- src/application.rs | 10 +++++----- src/main.rs | 2 +- src/{view => ui/graph}/graph_view.rs | 2 +- src/ui/graph/mod.rs | 24 ++++++++++++++++++++++++ src/{view => ui/graph}/node.rs | 8 +++++--- src/{view => ui/graph}/port.rs | 0 src/{view => ui/graph}/zoomentry.rs | 12 ++++++------ src/{view => ui/graph}/zoomentry.ui | 0 src/{view => ui}/mod.rs | 10 +--------- 9 files changed, 43 insertions(+), 25 deletions(-) rename src/{view => ui/graph}/graph_view.rs (99%) create mode 100644 src/ui/graph/mod.rs rename src/{view => ui/graph}/node.rs (96%) rename src/{view => ui/graph}/port.rs (100%) rename src/{view => ui/graph}/zoomentry.rs (93%) rename src/{view => ui/graph}/zoomentry.ui (100%) rename src/{view => ui}/mod.rs (84%) diff --git a/src/application.rs b/src/application.rs index 41ade3a..cbd887f 100644 --- a/src/application.rs +++ b/src/application.rs @@ -26,7 +26,7 @@ use log::info; use pipewire::{channel::Sender, spa::Direction}; use crate::{ - view::{self}, + ui, GtkMessage, MediaType, NodeType, PipewireLink, PipewireMessage, }; @@ -39,7 +39,7 @@ mod imp { #[derive(Default)] pub struct Application { - pub(super) graphview: view::GraphView, + pub(super) graphview: ui::graph::GraphView, pub(super) pw_sender: OnceCell>>, } @@ -58,7 +58,7 @@ mod imp { .child(&self.graphview) .build(); let headerbar = gtk::HeaderBar::new(); - let zoomentry = view::ZoomEntry::new(&self.graphview); + let zoomentry = ui::graph::ZoomEntry::new(&self.graphview); headerbar.pack_end(&zoomentry); let window = gtk::ApplicationWindow::builder() @@ -163,7 +163,7 @@ impl Application { self.imp() .graphview - .add_node(id, view::Node::new(name, id), node_type); + .add_node(id, ui::graph::Node::new(name, id), node_type); } /// Add a new port to the view. @@ -177,7 +177,7 @@ impl Application { ) { info!("Adding port to graph: id {}", id); - let port = view::Port::new(id, name, direction, media_type); + let port = ui::graph::Port::new(id, name, direction, media_type); // Create or delete a link if the widget emits the "port-toggled" signal. port.connect_local( diff --git a/src/main.rs b/src/main.rs index e4ce325..b44d701 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ mod application; mod pipewire_connection; -mod view; +mod ui; use glib::PRIORITY_DEFAULT; use gtk::prelude::*; diff --git a/src/view/graph_view.rs b/src/ui/graph/graph_view.rs similarity index 99% rename from src/view/graph_view.rs rename to src/ui/graph/graph_view.rs index 7b154a1..c602a3c 100644 --- a/src/view/graph_view.rs +++ b/src/ui/graph/graph_view.rs @@ -652,7 +652,7 @@ impl GraphView { } } - pub fn add_port(&self, node_id: u32, port_id: u32, port: crate::view::port::Port) { + pub fn add_port(&self, node_id: u32, port_id: u32, port: Port) { if let Some((node, _)) = self.imp().nodes.borrow_mut().get_mut(&node_id) { node.add_port(port_id, port); } else { diff --git a/src/ui/graph/mod.rs b/src/ui/graph/mod.rs new file mode 100644 index 0000000..c904553 --- /dev/null +++ b/src/ui/graph/mod.rs @@ -0,0 +1,24 @@ +// Copyright 2021 Tom A. Wagner +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 3 as published by +// the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// SPDX-License-Identifier: GPL-3.0-only + +mod graph_view; +pub use graph_view::*; +mod node; +pub use node::*; +mod port; +pub use port::*; +mod zoomentry; +pub use zoomentry::*; \ No newline at end of file diff --git a/src/view/node.rs b/src/ui/graph/node.rs similarity index 96% rename from src/view/node.rs rename to src/ui/graph/node.rs index 844cd67..530590a 100644 --- a/src/view/node.rs +++ b/src/ui/graph/node.rs @@ -19,6 +19,8 @@ use pipewire::spa::Direction; use std::collections::HashMap; +use super::Port; + mod imp { use glib::ParamFlags; use once_cell::sync::Lazy; @@ -31,7 +33,7 @@ mod imp { pub(super) pipewire_id: Cell, pub(super) grid: gtk::Grid, pub(super) label: gtk::Label, - pub(super) ports: RefCell>, + pub(super) ports: RefCell>, pub(super) num_ports_in: Cell, pub(super) num_ports_out: Cell, } @@ -144,7 +146,7 @@ impl Node { self.set_property("name", name); } - pub fn add_port(&mut self, id: u32, port: super::port::Port) { + pub fn add_port(&mut self, id: u32, port: Port) { let imp = self.imp(); match port.direction() { @@ -161,7 +163,7 @@ impl Node { imp.ports.borrow_mut().insert(id, port); } - pub fn get_port(&self, id: u32) -> Option { + pub fn get_port(&self, id: u32) -> Option { self.imp().ports.borrow_mut().get(&id).cloned() } diff --git a/src/view/port.rs b/src/ui/graph/port.rs similarity index 100% rename from src/view/port.rs rename to src/ui/graph/port.rs diff --git a/src/view/zoomentry.rs b/src/ui/graph/zoomentry.rs similarity index 93% rename from src/view/zoomentry.rs rename to src/ui/graph/zoomentry.rs index 719d1a7..59e0941 100644 --- a/src/view/zoomentry.rs +++ b/src/ui/graph/zoomentry.rs @@ -1,6 +1,6 @@ use gtk::{glib, prelude::*, subclass::prelude::*}; -use crate::view; +use super::GraphView; mod imp { use std::cell::RefCell; @@ -13,7 +13,7 @@ mod imp { #[derive(gtk::CompositeTemplate)] #[template(file = "zoomentry.ui")] pub struct ZoomEntry { - pub graphview: RefCell>, + pub graphview: RefCell>, #[template_child] pub zoom_out_button: TemplateChild, #[template_child] @@ -110,7 +110,7 @@ mod imp { fn properties() -> &'static [glib::ParamSpec] { static PROPERTIES: Lazy> = Lazy::new(|| { vec![ - glib::ParamSpecObject::builder::("zoomed-widget") + glib::ParamSpecObject::builder::("zoomed-widget") .flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT) .build(), ] @@ -129,7 +129,7 @@ mod imp { fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { match pspec.name() { "zoomed-widget" => { - let widget: view::GraphView = value.get().unwrap(); + let widget: GraphView = value.get().unwrap(); widget.connect_notify_local( Some("zoom-factor"), clone!(@weak self as imp => move |graphview, _| { @@ -149,7 +149,7 @@ mod imp { impl ZoomEntry { /// Update the text contained in the combobox's entry to reflect the provided zoom factor. /// - /// This does not update the associated [`view::GraphView`]s zoom level. + /// This does not update the associated [`GraphView`]s zoom level. fn update_zoom_factor_text(&self, zoom_factor: f64) { self.entry .buffer() @@ -164,7 +164,7 @@ glib::wrapper! { } impl ZoomEntry { - pub fn new(zoomed_widget: &view::GraphView) -> Self { + pub fn new(zoomed_widget: &GraphView) -> Self { glib::Object::builder() .property("zoomed-widget", zoomed_widget) .build() diff --git a/src/view/zoomentry.ui b/src/ui/graph/zoomentry.ui similarity index 100% rename from src/view/zoomentry.ui rename to src/ui/graph/zoomentry.ui diff --git a/src/view/mod.rs b/src/ui/mod.rs similarity index 84% rename from src/view/mod.rs rename to src/ui/mod.rs index c4775e6..532b6bd 100644 --- a/src/view/mod.rs +++ b/src/ui/mod.rs @@ -18,12 +18,4 @@ //! //! This module contains gtk widgets needed to present the graphical user interface. -mod graph_view; -mod node; -mod port; -mod zoomentry; - -pub use graph_view::GraphView; -pub use node::Node; -pub use port::Port; -pub use zoomentry::ZoomEntry; +pub mod graph; \ No newline at end of file