Move port coloring into view

The controller still determines the ports media type, but instead of coloring
the port itself, the media type is passed to the constructor, which then colors the port.
This commit is contained in:
Tom A. Wagner
2021-03-28 21:03:43 +02:00
parent 269ce18b29
commit 48821be18d
2 changed files with 33 additions and 18 deletions

View File

@@ -1,3 +1,7 @@
use gtk::WidgetExt;
use crate::controller::MediaType;
/// Graphical representation of a pipewire port.
pub struct Port {
pub widget: gtk::Button,
@@ -6,9 +10,24 @@ pub struct Port {
}
impl Port {
pub fn new(id: u32, name: &str, direction: pipewire::port::Direction) -> Self {
pub fn new(
id: u32,
name: &str,
direction: pipewire::port::Direction,
media_type: Option<MediaType>,
) -> Self {
let widget = gtk::Button::with_label(name);
// Color the port according to its media type.
match media_type {
Some(MediaType::Video) => widget.add_css_class("video"),
Some(MediaType::Audio) => widget.add_css_class("audio"),
Some(MediaType::Midi) => widget.add_css_class("midi"),
None => {}
}
Self {
widget: gtk::Button::with_label(name),
widget,
id,
direction,
}