Finish the base view stuff
This commit is contained in:
parent
a470c3187c
commit
32375abdef
2 changed files with 59 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use gtk4::{
|
use gtk4::{
|
||||||
prelude::*, Box as GtkBox, Image, ListBox, Orientation, PositionType, RevealerTransitionType,
|
prelude::*, Box as GtkBox, Image, Label, ListBox, Orientation, PositionType,
|
||||||
Scale, Separator, Stack, Window,
|
RevealerTransitionType, Scale, Separator, Stack, Window,
|
||||||
};
|
};
|
||||||
use libcosmic_widgets::LabeledItem;
|
use libcosmic_widgets::LabeledItem;
|
||||||
use pulsectl::controllers::types::DeviceInfo;
|
use pulsectl::controllers::types::DeviceInfo;
|
||||||
|
|
@ -14,8 +14,32 @@ pub struct App {
|
||||||
outputs: Vec<DeviceInfo>,
|
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 {
|
pub struct Widgets {
|
||||||
output_stack: Stack,
|
output_stack: Stack,
|
||||||
|
current_input: Label,
|
||||||
|
current_output: Label,
|
||||||
inputs: ListBox,
|
inputs: ListBox,
|
||||||
outputs: ListBox,
|
outputs: ListBox,
|
||||||
}
|
}
|
||||||
|
|
@ -49,8 +73,9 @@ impl Component for App {
|
||||||
input: &Sender<Self::Input>,
|
input: &Sender<Self::Input>,
|
||||||
_output: &Sender<Self::Output>,
|
_output: &Sender<Self::Output>,
|
||||||
) -> ComponentParts<Self> {
|
) -> ComponentParts<Self> {
|
||||||
|
let model = App::default();
|
||||||
view! {
|
view! {
|
||||||
GtkBox {
|
container = GtkBox {
|
||||||
set_orientation: Orientation::Vertical,
|
set_orientation: Orientation::Vertical,
|
||||||
set_spacing: 24,
|
set_spacing: 24,
|
||||||
append: output_box = &GtkBox {
|
append: output_box = &GtkBox {
|
||||||
|
|
@ -86,16 +111,39 @@ impl Component for App {
|
||||||
},
|
},
|
||||||
append: output_stack = &Stack {
|
append: output_stack = &Stack {
|
||||||
add_child: current_output = &Label {
|
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 {
|
add_child: outputs = &ListBox {
|
||||||
append: outputs = &ListBox {
|
set_selection_mode: gtk4::SelectionMode::None,
|
||||||
set_selection_mode: gtk4::SelectionMode::None,
|
set_activate_on_single_click: true
|
||||||
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(¤t_output);
|
||||||
|
input_stack.set_visible_child(¤t_input);
|
||||||
|
root.set_child(Some(&container));
|
||||||
|
ComponentParts {
|
||||||
|
model,
|
||||||
|
widgets: Widgets {
|
||||||
|
output_stack,
|
||||||
|
inputs,
|
||||||
|
outputs,
|
||||||
|
current_input,
|
||||||
|
current_output,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,11 @@ extern crate relm4;
|
||||||
mod app;
|
mod app;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use relm4::RelmApp;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
RelmApp::<app::App>::new("com.system76.cosmic.applets.audio").run(());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue