Finish the base view stuff

This commit is contained in:
Lucy 2022-03-10 12:40:41 -05:00
parent a470c3187c
commit 32375abdef
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
2 changed files with 59 additions and 10 deletions

View file

@ -1,6 +1,6 @@
use gtk4::{
prelude::*, Box as GtkBox, Image, ListBox, Orientation, PositionType, RevealerTransitionType,
Scale, Separator, Stack, Window,
prelude::*, Box as GtkBox, Image, Label, ListBox, Orientation, PositionType,
RevealerTransitionType, Scale, Separator, Stack, Window,
};
use libcosmic_widgets::LabeledItem;
use pulsectl::controllers::types::DeviceInfo;
@ -14,8 +14,32 @@ pub struct App {
outputs: Vec<DeviceInfo>,
}
impl App {
pub fn get_default_input_name(&self) -> &str {
match &self.default_input {
Some(input) => match &input.name {
Some(name) => name.as_str(),
None => "Input Device",
},
None => "No Input Device",
}
}
pub fn get_default_output_name(&self) -> &str {
match &self.default_output {
Some(output) => match &output.name {
Some(name) => name.as_str(),
None => "Output Device",
},
None => "No Output Device",
}
}
}
pub struct Widgets {
output_stack: Stack,
current_input: Label,
current_output: Label,
inputs: ListBox,
outputs: ListBox,
}
@ -49,8 +73,9 @@ impl Component for App {
input: &Sender<Self::Input>,
_output: &Sender<Self::Output>,
) -> ComponentParts<Self> {
let model = App::default();
view! {
GtkBox {
container = GtkBox {
set_orientation: Orientation::Vertical,
set_spacing: 24,
append: output_box = &GtkBox {
@ -86,16 +111,39 @@ impl Component for App {
},
append: output_stack = &Stack {
add_child: current_output = &Label {
set_text: watch! { model.name.unwrap_or_else(|| "Output Device".into()) }
set_text: watch! { model.get_default_output_name() }
},
add_child: list_outputs = &GtkBox {
append: outputs = &ListBox {
set_selection_mode: gtk4::SelectionMode::None,
set_activate_on_single_click: true,
},
add_child: outputs = &ListBox {
set_selection_mode: gtk4::SelectionMode::None,
set_activate_on_single_click: true
}
},
append: _sep = &Separator {
set_orientation: Orientation::Horizontal,
},
append: input_stack = &Stack {
add_child: current_input = &Label {
set_text: watch! { model.get_default_input_name() }
},
add_child: inputs = &ListBox {
set_selection_mode: gtk4::SelectionMode::None,
set_activate_on_single_click: true
}
}
}
}
output_stack.set_visible_child(&current_output);
input_stack.set_visible_child(&current_input);
root.set_child(Some(&container));
ComponentParts {
model,
widgets: Widgets {
output_stack,
inputs,
outputs,
current_input,
current_output,
},
}
}
}

View file

@ -6,10 +6,11 @@ extern crate relm4;
mod app;
use once_cell::sync::Lazy;
use relm4::RelmApp;
use tokio::runtime::Runtime;
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
fn main() {
println!("Hello, world!");
RelmApp::<app::App>::new("com.system76.cosmic.applets.audio").run(());
}