use ActionRow widget for DropDown menu

This commit is contained in:
yggverse 2024-11-20 10:36:21 +02:00
parent fa9c2b4fbc
commit bb42239749
4 changed files with 26 additions and 28 deletions

View File

@ -23,7 +23,10 @@ impl Gemini {
let widget = Rc::new(Widget::new());
// Add new identity option
widget.form.list.append(None, "Create new..", true);
widget
.form
.list
.append(None, "Create new..", "Auto-generated certificate");
// Collect additional options from database
match profile.identity.gemini.database.records() {
@ -35,21 +38,15 @@ impl Gemini {
Err(reason) => todo!("{reason}"),
};
// Get name from subject
let name = certificate.subject_name().unwrap();
// Get expiration time
let expires = certificate
.not_valid_after()
.unwrap()
.format_iso8601()
.unwrap();
// Append record option
widget.form.list.append(
Some(identity.id),
&format!("{name} ({expires})"),
true,
&certificate.subject_name().unwrap(),
&certificate
.not_valid_after()
.unwrap()
.format_iso8601()
.unwrap(),
);
}
}

View File

@ -1,13 +1,14 @@
mod item;
use item::Item;
use adw::ActionRow;
use gtk::{
gio::{
prelude::{Cast, CastNone},
ListStore,
},
prelude::ListItemExt,
DropDown, Label, ListItem, SignalListItemFactory,
DropDown, ListItem, SignalListItemFactory,
};
pub struct List {
@ -33,12 +34,12 @@ impl List {
let item = list_item.item().and_downcast::<Item>().unwrap();
// Update menu item
list_item.set_child(Some(&Label::new(Some(&item.label()))));
// @TODO
println!("{:?}", item.profile_identity_gemini_id_option());
println!("{:?}", item.label());
println!("{:?}", item.is_enabled());
list_item.set_child(Some(
&ActionRow::builder()
.title(item.title())
.subtitle(item.subtitle())
.build(),
));
});
// Init list `GObject`
@ -50,10 +51,10 @@ impl List {
// Actions
/// Append new item with `profile_identity_gemini_id` as `key` and label as `value`
pub fn append(&self, profile_identity_gemini_id: Option<i64>, label: &str, is_enabled: bool) {
/// Append new item
pub fn append(&self, profile_identity_gemini_id: Option<i64>, title: &str, subtitle: &str) {
self.model
.append(&Item::new(profile_identity_gemini_id, label, is_enabled));
.append(&Item::new(profile_identity_gemini_id, title, subtitle));
}
// Events

View File

@ -12,7 +12,7 @@ impl Item {
// Constructors
/// Create new `GObject` with formatted properties
pub fn new(profile_identity_gemini_id: Option<i64>, label: &str, is_enabled: bool) -> Self {
pub fn new(profile_identity_gemini_id: Option<i64>, title: &str, subtitle: &str) -> Self {
Object::builder()
.property(
"profile_identity_gemini_id",
@ -21,8 +21,8 @@ impl Item {
None => PROFILE_IDENTITY_GEMINI_ID_NONE,
},
)
.property("label", label)
.property("is_enabled", is_enabled)
.property("title", title)
.property("subtitle", subtitle)
.build()
}

View File

@ -14,9 +14,9 @@ pub struct Item {
#[property(get, set)]
profile_identity_gemini_id: Cell<i64>,
#[property(get, set)]
label: RefCell<String>,
title: RefCell<String>,
#[property(get, set)]
is_enabled: Cell<bool>,
subtitle: RefCell<String>,
}
#[glib::object_subclass]