mirror of
https://gitlab.freedesktop.org/pipewire/helvum
synced 2026-03-15 03:26:10 +08:00
Restructure view module into ui folder, graph specific widgets into graph subfolder
This commit is contained in:
@@ -26,7 +26,7 @@ use log::info;
|
|||||||
use pipewire::{channel::Sender, spa::Direction};
|
use pipewire::{channel::Sender, spa::Direction};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
view::{self},
|
ui,
|
||||||
GtkMessage, MediaType, NodeType, PipewireLink, PipewireMessage,
|
GtkMessage, MediaType, NodeType, PipewireLink, PipewireMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ mod imp {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Application {
|
pub struct Application {
|
||||||
pub(super) graphview: view::GraphView,
|
pub(super) graphview: ui::graph::GraphView,
|
||||||
pub(super) pw_sender: OnceCell<RefCell<Sender<GtkMessage>>>,
|
pub(super) pw_sender: OnceCell<RefCell<Sender<GtkMessage>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ mod imp {
|
|||||||
.child(&self.graphview)
|
.child(&self.graphview)
|
||||||
.build();
|
.build();
|
||||||
let headerbar = gtk::HeaderBar::new();
|
let headerbar = gtk::HeaderBar::new();
|
||||||
let zoomentry = view::ZoomEntry::new(&self.graphview);
|
let zoomentry = ui::graph::ZoomEntry::new(&self.graphview);
|
||||||
headerbar.pack_end(&zoomentry);
|
headerbar.pack_end(&zoomentry);
|
||||||
|
|
||||||
let window = gtk::ApplicationWindow::builder()
|
let window = gtk::ApplicationWindow::builder()
|
||||||
@@ -163,7 +163,7 @@ impl Application {
|
|||||||
|
|
||||||
self.imp()
|
self.imp()
|
||||||
.graphview
|
.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.
|
/// Add a new port to the view.
|
||||||
@@ -177,7 +177,7 @@ impl Application {
|
|||||||
) {
|
) {
|
||||||
info!("Adding port to graph: id {}", id);
|
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.
|
// Create or delete a link if the widget emits the "port-toggled" signal.
|
||||||
port.connect_local(
|
port.connect_local(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
mod application;
|
mod application;
|
||||||
mod pipewire_connection;
|
mod pipewire_connection;
|
||||||
mod view;
|
mod ui;
|
||||||
|
|
||||||
use glib::PRIORITY_DEFAULT;
|
use glib::PRIORITY_DEFAULT;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|||||||
@@ -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) {
|
if let Some((node, _)) = self.imp().nodes.borrow_mut().get_mut(&node_id) {
|
||||||
node.add_port(port_id, port);
|
node.add_port(port_id, port);
|
||||||
} else {
|
} else {
|
||||||
24
src/ui/graph/mod.rs
Normal file
24
src/ui/graph/mod.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// 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::*;
|
||||||
@@ -19,6 +19,8 @@ use pipewire::spa::Direction;
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use super::Port;
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use glib::ParamFlags;
|
use glib::ParamFlags;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
@@ -31,7 +33,7 @@ mod imp {
|
|||||||
pub(super) pipewire_id: Cell<u32>,
|
pub(super) pipewire_id: Cell<u32>,
|
||||||
pub(super) grid: gtk::Grid,
|
pub(super) grid: gtk::Grid,
|
||||||
pub(super) label: gtk::Label,
|
pub(super) label: gtk::Label,
|
||||||
pub(super) ports: RefCell<HashMap<u32, crate::view::port::Port>>,
|
pub(super) ports: RefCell<HashMap<u32, Port>>,
|
||||||
pub(super) num_ports_in: Cell<i32>,
|
pub(super) num_ports_in: Cell<i32>,
|
||||||
pub(super) num_ports_out: Cell<i32>,
|
pub(super) num_ports_out: Cell<i32>,
|
||||||
}
|
}
|
||||||
@@ -144,7 +146,7 @@ impl Node {
|
|||||||
self.set_property("name", name);
|
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();
|
let imp = self.imp();
|
||||||
|
|
||||||
match port.direction() {
|
match port.direction() {
|
||||||
@@ -161,7 +163,7 @@ impl Node {
|
|||||||
imp.ports.borrow_mut().insert(id, port);
|
imp.ports.borrow_mut().insert(id, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_port(&self, id: u32) -> Option<super::port::Port> {
|
pub fn get_port(&self, id: u32) -> Option<Port> {
|
||||||
self.imp().ports.borrow_mut().get(&id).cloned()
|
self.imp().ports.borrow_mut().get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use gtk::{glib, prelude::*, subclass::prelude::*};
|
use gtk::{glib, prelude::*, subclass::prelude::*};
|
||||||
|
|
||||||
use crate::view;
|
use super::GraphView;
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@@ -13,7 +13,7 @@ mod imp {
|
|||||||
#[derive(gtk::CompositeTemplate)]
|
#[derive(gtk::CompositeTemplate)]
|
||||||
#[template(file = "zoomentry.ui")]
|
#[template(file = "zoomentry.ui")]
|
||||||
pub struct ZoomEntry {
|
pub struct ZoomEntry {
|
||||||
pub graphview: RefCell<Option<view::GraphView>>,
|
pub graphview: RefCell<Option<GraphView>>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub zoom_out_button: TemplateChild<gtk::Button>,
|
pub zoom_out_button: TemplateChild<gtk::Button>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
@@ -110,7 +110,7 @@ mod imp {
|
|||||||
fn properties() -> &'static [glib::ParamSpec] {
|
fn properties() -> &'static [glib::ParamSpec] {
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||||
vec![
|
vec![
|
||||||
glib::ParamSpecObject::builder::<view::GraphView>("zoomed-widget")
|
glib::ParamSpecObject::builder::<GraphView>("zoomed-widget")
|
||||||
.flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT)
|
.flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT)
|
||||||
.build(),
|
.build(),
|
||||||
]
|
]
|
||||||
@@ -129,7 +129,7 @@ mod imp {
|
|||||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||||
match pspec.name() {
|
match pspec.name() {
|
||||||
"zoomed-widget" => {
|
"zoomed-widget" => {
|
||||||
let widget: view::GraphView = value.get().unwrap();
|
let widget: GraphView = value.get().unwrap();
|
||||||
widget.connect_notify_local(
|
widget.connect_notify_local(
|
||||||
Some("zoom-factor"),
|
Some("zoom-factor"),
|
||||||
clone!(@weak self as imp => move |graphview, _| {
|
clone!(@weak self as imp => move |graphview, _| {
|
||||||
@@ -149,7 +149,7 @@ mod imp {
|
|||||||
impl ZoomEntry {
|
impl ZoomEntry {
|
||||||
/// Update the text contained in the combobox's entry to reflect the provided zoom factor.
|
/// 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) {
|
fn update_zoom_factor_text(&self, zoom_factor: f64) {
|
||||||
self.entry
|
self.entry
|
||||||
.buffer()
|
.buffer()
|
||||||
@@ -164,7 +164,7 @@ glib::wrapper! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ZoomEntry {
|
impl ZoomEntry {
|
||||||
pub fn new(zoomed_widget: &view::GraphView) -> Self {
|
pub fn new(zoomed_widget: &GraphView) -> Self {
|
||||||
glib::Object::builder()
|
glib::Object::builder()
|
||||||
.property("zoomed-widget", zoomed_widget)
|
.property("zoomed-widget", zoomed_widget)
|
||||||
.build()
|
.build()
|
||||||
@@ -18,12 +18,4 @@
|
|||||||
//!
|
//!
|
||||||
//! This module contains gtk widgets needed to present the graphical user interface.
|
//! This module contains gtk widgets needed to present the graphical user interface.
|
||||||
|
|
||||||
mod graph_view;
|
pub mod graph;
|
||||||
mod node;
|
|
||||||
mod port;
|
|
||||||
mod zoomentry;
|
|
||||||
|
|
||||||
pub use graph_view::GraphView;
|
|
||||||
pub use node::Node;
|
|
||||||
pub use port::Port;
|
|
||||||
pub use zoomentry::ZoomEntry;
|
|
||||||
Reference in New Issue
Block a user