version badges

This commit is contained in:
Ward from fusion-voyager-3 2024-06-27 01:11:41 +03:00
parent 2e8b590ffd
commit 58bab67b9f

View File

@ -4,6 +4,7 @@ use adw::*;
use adw::{prelude::*, subclass::prelude::*}; use adw::{prelude::*, subclass::prelude::*};
use glib::{subclass::Signal, Properties}; use glib::{subclass::Signal, Properties};
use gtk::{Align, glib, Orientation, SizeGroupMode, SelectionMode}; use gtk::{Align, glib, Orientation, SizeGroupMode, SelectionMode};
use gtk::Orientation::Horizontal;
use crate::apt_update_page::AptPackageSocket; use crate::apt_update_page::AptPackageSocket;
// ANCHOR: custom_button // ANCHOR: custom_button
@ -46,10 +47,9 @@ impl ObjectImpl for AptPackageRow {
let obj = self.obj(); let obj = self.obj();
let prefix_box = gtk::Box::new(Orientation::Horizontal, 0); let prefix_box = gtk::Box::new(Orientation::Horizontal, 0);
prefix_box.append(&create_version_badge("1.0-100-pika1".to_string(), "1.1-101-pika1".to_string()));
obj.add_prefix(&prefix_box); obj.add_prefix(&prefix_box);
obj.add_prefix(&create_version_badge("1.0-100-pika1".to_string(), "1.1-101-pika1".to_string()));
// Bind label to number // Bind label to number
// `SYNC_CREATE` ensures that the label will be immediately set // `SYNC_CREATE` ensures that the label will be immediately set
//let obj = self.obj(); //let obj = self.obj();
@ -72,18 +72,24 @@ impl ActionRowImpl for AptPackageRow {}
fn create_version_badge(installed_version: String, candidate_version: String) -> gtk::ListBox { fn create_version_badge(installed_version: String, candidate_version: String) -> gtk::ListBox {
let (base_version, installed_diff, candidate_diff) = get_diff_by_prefix(installed_version, candidate_version); let (base_version, installed_diff, candidate_diff) = get_diff_by_prefix(installed_version, candidate_version);
let badge_box = gtk::Box::builder().build(); let badge_box = gtk::Box::builder()
.halign(Align::Start)
.hexpand(false)
.orientation(Orientation::Horizontal)
.margin_start(5)
.margin_end(5)
.margin_bottom(5)
.margin_top(5)
.build();
let group_size = gtk::SizeGroup::new(SizeGroupMode::Both); let installed_version_box = gtk::Box::builder()
.halign(Align::Start)
let installed_version_box = gtk::Box::new(Orientation::Horizontal, 0); .hexpand(false)
.orientation(Orientation::Horizontal)
.build();
let installed_version_base_version_label = gtk::Label::builder() let installed_version_base_version_label = gtk::Label::builder()
.label(&base_version) .label(&base_version)
.margin_start(5)
.margin_end(5)
.margin_bottom(1)
.margin_top(1)
.valign(Align::Center) .valign(Align::Center)
.halign(Align::Start) .halign(Align::Start)
.hexpand(false) .hexpand(false)
@ -92,10 +98,6 @@ fn create_version_badge(installed_version: String, candidate_version: String) ->
let installed_diff_label = gtk::Label::builder() let installed_diff_label = gtk::Label::builder()
.label(installed_diff) .label(installed_diff)
.margin_start(5)
.margin_end(5)
.margin_bottom(1)
.margin_top(1)
.valign(Align::Center) .valign(Align::Center)
.halign(Align::Start) .halign(Align::Start)
.hexpand(false) .hexpand(false)
@ -105,18 +107,21 @@ fn create_version_badge(installed_version: String, candidate_version: String) ->
installed_version_box.append(&installed_version_base_version_label.clone()); installed_version_box.append(&installed_version_base_version_label.clone());
installed_version_box.append(&installed_diff_label); installed_version_box.append(&installed_diff_label);
group_size.add_widget(&installed_version_box);
let label_seprator = gtk::Separator::builder().build(); let label_separator = gtk::Separator::builder()
.margin_start(5)
.margin_end(5)
.margin_bottom(5)
.margin_top(5).build();
let candidate_version_box = gtk::Box::new(Orientation::Horizontal, 0); let candidate_version_box = gtk::Box::builder()
.halign(Align::Start)
.hexpand(false)
.orientation(Orientation::Horizontal)
.build();
let candidate_version_base_version_label = gtk::Label::builder() let candidate_version_base_version_label = gtk::Label::builder()
.label(base_version) .label(base_version)
.margin_start(5)
.margin_end(5)
.margin_bottom(1)
.margin_top(1)
.valign(Align::Center) .valign(Align::Center)
.halign(Align::Start) .halign(Align::Start)
.hexpand(false) .hexpand(false)
@ -125,10 +130,6 @@ fn create_version_badge(installed_version: String, candidate_version: String) ->
let candidate_diff_label = gtk::Label::builder() let candidate_diff_label = gtk::Label::builder()
.label(candidate_diff) .label(candidate_diff)
.margin_start(5)
.margin_end(5)
.margin_bottom(1)
.margin_top(1)
.valign(Align::Center) .valign(Align::Center)
.halign(Align::Start) .halign(Align::Start)
.hexpand(false) .hexpand(false)
@ -138,20 +139,15 @@ fn create_version_badge(installed_version: String, candidate_version: String) ->
candidate_version_box.append(&candidate_version_base_version_label); candidate_version_box.append(&candidate_version_base_version_label);
candidate_version_box.append(&candidate_diff_label); candidate_version_box.append(&candidate_diff_label);
group_size.add_widget(&candidate_diff_label);
badge_box.append(&installed_version_box); badge_box.append(&installed_version_box);
badge_box.append(&label_seprator); badge_box.append(&label_separator);
badge_box.append(&candidate_version_box); badge_box.append(&candidate_version_box);
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::End)
.margin_start(5)
.margin_end(5)
.margin_bottom(5)
.margin_top(5)
.build(); .build();
boxedlist.add_css_class("boxed-list"); boxedlist.add_css_class("boxed-list");