add expandables

This commit is contained in:
Ward from fusion-voyager-3 2024-07-04 14:37:12 +03:00
parent 669f169a79
commit 346411c02f
3 changed files with 78 additions and 6 deletions

View File

@ -2,6 +2,5 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/target/debug/build/rust-apt-bdd275358b00de07/out/cxxbridge/crate/rust-apt" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -8,6 +8,8 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment=""> <list default="true" id="df2ca9e1-e07d-43f4-bc68-0a6113fc1fa2" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/apt_package_row/imp.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/apt_package_row/imp.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/apt_package_row/imp.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/apt_package_row/imp.rs" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -101,6 +103,11 @@
<workItem from="1719510804090" duration="7000" /> <workItem from="1719510804090" duration="7000" />
<workItem from="1719609702948" duration="9756000" /> <workItem from="1719609702948" duration="9756000" />
<workItem from="1719635307639" duration="18000" /> <workItem from="1719635307639" duration="18000" />
<workItem from="1719797505365" duration="10000" />
<workItem from="1719797522707" duration="698000" />
<workItem from="1719847278228" duration="8841000" />
<workItem from="1719872581190" duration="4000" />
<workItem from="1720090281244" duration="2690000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -8,6 +8,7 @@ use gtk::Orientation::Horizontal;
use crate::apt_update_page::AptPackageSocket; use crate::apt_update_page::AptPackageSocket;
use pretty_bytes::converter::convert; use pretty_bytes::converter::convert;
use std::env; use std::env;
use std::os::unix::raw::nlink_t;
// ANCHOR: custom_button // ANCHOR: custom_button
// Object holding the state // Object holding the state
@ -262,7 +263,7 @@ fn create_expandable_content(apt_package_row: &impl IsA<ExpanderRow>, expandable
expandable_page_selection_box.add_css_class("linked"); expandable_page_selection_box.add_css_class("linked");
// //
let description_page_button = gtk::ToggleButton::builder() let description_page_button = gtk::ToggleButton::builder()
.label(t!("description_page_button_label")) .label(t!("description_button_label"))
.active(true) .active(true)
.build(); .build();
let extra_info_page_button = gtk::ToggleButton::builder() let extra_info_page_button = gtk::ToggleButton::builder()
@ -291,10 +292,28 @@ fn create_expandable_content(apt_package_row: &impl IsA<ExpanderRow>, expandable
.vexpand(true) .vexpand(true)
.build(); .build();
// //
description_page_button.connect_clicked(clone!(@strong expandable_bin, @strong description_page_button => move |_|{
if description_page_button.is_active() {
expandable_bin.set_child(Some(&description_stack_page(&package_description)));
}
}));
extra_info_page_button.connect_clicked(clone!(@strong expandable_bin, @strong extra_info_page_button => move |_|{
if extra_info_page_button.is_active() {
expandable_bin.set_child(Some(&extra_info_stack_page(&package_maintainer, package_size, package_installed_size)));
}
}));
uris_page_button.connect_clicked(clone!(@strong expandable_bin, @strong uris_page_button => move |_|{
if uris_page_button.is_active() {
expandable_bin.set_child(Some(&uris_stack_page(&package_source_uri)));
}
}));
apt_package_row.connect_expanded_notify(clone!(@strong expandable_bin, @strong expandable_box, @strong apt_package_row, @strong description_page_button => move |apt_package_row| { apt_package_row.connect_expanded_notify(clone!(@strong expandable_bin, @strong expandable_box, @strong apt_package_row, @strong description_page_button => move |apt_package_row| {
if apt_package_row.property("expanded") { if apt_package_row.property("expanded") {
expandable_bin.set_child(Some(&extra_info_stack_page(&package_maintainer, package_size, package_installed_size)));
description_page_button.set_active(true); description_page_button.set_active(true);
description_page_button.emit_by_name::<()>("clicked", &[]);
expandable_box.append(&expandable_bin) expandable_box.append(&expandable_bin)
} else { } else {
expandable_box.remove(&expandable_bin) expandable_box.remove(&expandable_bin)
@ -304,12 +323,59 @@ fn create_expandable_content(apt_package_row: &impl IsA<ExpanderRow>, expandable
// //
} }
fn uris_stack_page(package_source_uri: &str) -> gtk::Box {
let uris_content_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
.orientation(Orientation::Vertical)
.build();
let uris_text_buffer = gtk::TextBuffer::builder()
.text(package_source_uri.to_owned()+"\n")
.build();
let uris_text_view = gtk::TextView::builder()
.buffer(&uris_text_buffer)
.hexpand(true)
.vexpand(true)
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.editable(false)
.buffer(&uris_text_buffer)
.build();
uris_content_box.append(&uris_text_view);
uris_content_box
}
fn description_stack_page(package_description: &str) -> gtk::Box {
let description_content_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
.orientation(Orientation::Vertical)
.build();
let description_text_buffer = gtk::TextBuffer::builder()
.text(package_description.to_owned()+"\n")
.build();
let description_text_view = gtk::TextView::builder()
.buffer(&description_text_buffer)
.hexpand(true)
.vexpand(true)
.margin_top(15)
.margin_bottom(15)
.margin_start(15)
.margin_end(15)
.editable(false)
.buffer(&description_text_buffer)
.build();
description_content_box.append(&description_text_view);
description_content_box
}
fn extra_info_stack_page(package_maintainer: &str, package_size: u64, package_installed_size: u64) -> gtk::Box { fn extra_info_stack_page(package_maintainer: &str, package_size: u64, package_installed_size: u64) -> gtk::Box {
let extra_info_badges_content_box = gtk::Box::builder() let extra_info_badges_content_box = gtk::Box::builder()
.hexpand(true) .hexpand(true)
.vexpand(true) .vexpand(true)
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
.sensitive(false)
.build(); .build();
let extra_info_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both); let extra_info_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
let extra_info_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both); let extra_info_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both);
@ -367,8 +433,8 @@ fn create_color_badge(
let boxedlist = gtk::ListBox::builder() let boxedlist = gtk::ListBox::builder()
.selection_mode(SelectionMode::None) .selection_mode(SelectionMode::None)
.halign(Align::Center) .halign(Align::Start)
.valign(Align::End) .valign(Align::Start)
.margin_start(10) .margin_start(10)
.margin_end(10) .margin_end(10)
.margin_bottom(10) .margin_bottom(10)