Use a Revealer instead of a Stack

This commit is contained in:
Lucy 2022-03-16 12:52:30 -04:00
parent 50f64f3187
commit d4b67bb990
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1

View file

@ -1,8 +1,6 @@
use gtk4::{ use gtk4::{
glib::{self, clone}, glib::clone, prelude::*, Box as GtkBox, Button, Image, Label, ListBox, Orientation,
prelude::*, PositionType, Revealer, RevealerTransitionType, Scale, Separator, Window,
Box as GtkBox, Button, Image, Label, ListBox, Orientation, PositionType, Scale, Separator,
Stack, Window,
}; };
use libcosmic_widgets::LabeledItem; use libcosmic_widgets::LabeledItem;
use libpulse_binding::volume::Volume; use libpulse_binding::volume::Volume;
@ -185,36 +183,44 @@ impl SimpleComponent for App {
&Separator { &Separator {
set_orientation: Orientation::Horizontal, set_orientation: Orientation::Horizontal,
}, },
append: output_stack = &Stack { &GtkBox {
add_child: outputs = &ListBox { set_orientation: Orientation::Vertical,
set_selection_mode: gtk4::SelectionMode::None, &Button {
set_activate_on_single_click: true
},
add_child: open_outputs_button = &Button {
set_child: current_output = Some(&Label) { set_child: current_output = Some(&Label) {
set_text: watch! { model.get_default_output_name() } set_text: watch! { model.get_default_output_name() }
}, },
connect_clicked(input, output_stack, outputs) => move |_| { connect_clicked(input, outputs_revealer) => move |_| {
send!(input, Input::UpdateOutputs); send!(input, Input::UpdateOutputs);
output_stack.set_visible_child(&outputs); outputs_revealer.set_reveal_child(!outputs_revealer.reveals_child());
}
},
append: outputs_revealer = &Revealer {
set_transition_type: RevealerTransitionType::SlideDown,
set_child: outputs = Some(&ListBox) {
set_selection_mode: gtk4::SelectionMode::None,
set_activate_on_single_click: true
} }
} }
}, },
&Separator { &Separator {
set_orientation: Orientation::Horizontal, set_orientation: Orientation::Horizontal,
}, },
append: input_stack = &Stack { &GtkBox {
add_child: inputs = &ListBox { set_orientation: Orientation::Vertical,
set_selection_mode: gtk4::SelectionMode::None, &Button {
set_activate_on_single_click: true
},
add_child: open_inputs_button = &Button {
set_child: current_input = Some(&Label) { set_child: current_input = Some(&Label) {
set_text: watch! { model.get_default_input_name() } set_text: watch! { model.get_default_input_name() }
}, },
connect_clicked(input, input_stack, inputs) => move |_| { connect_clicked(input, inputs_revealer) => move |_| {
send!(input, Input::UpdateInputs); send!(input, Input::UpdateInputs);
input_stack.set_visible_child(&inputs); inputs_revealer.set_reveal_child(!inputs_revealer.reveals_child());
}
},
append: inputs_revealer = &Revealer {
set_transition_type: RevealerTransitionType::SlideDown,
set_child: inputs = Some(&ListBox) {
set_selection_mode: gtk4::SelectionMode::None,
set_activate_on_single_click: true
} }
} }
} }
@ -230,12 +236,6 @@ impl SimpleComponent for App {
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
let model = App::default(); let model = App::default();
let widgets = view_output!(); let widgets = view_output!();
widgets
.output_stack
.set_visible_child(&widgets.open_outputs_button);
widgets
.input_stack
.set_visible_child(&widgets.open_inputs_button);
ComponentParts { model, widgets } ComponentParts { model, widgets }
} }