components: Add CustomEntry

This commit is contained in:
Kai A. Hiller 2021-08-22 19:49:44 +02:00
parent 0deb8457b0
commit 97560a3efd
4 changed files with 50 additions and 0 deletions

View file

@ -34,6 +34,7 @@ data/resources/ui/window.ui
src/application.rs
src/components/avatar.rs
src/components/context_menu_bin.rs
src/components/custom_entry.rs
src/components/label_with_widgets.rs
src/components/in_app_notification.rs
src/components/mod.rs

View file

@ -0,0 +1,46 @@
use adw::subclass::prelude::*;
use gtk::glib;
use gtk::subclass::prelude::*;
mod imp {
use super::*;
#[derive(Debug, Default)]
pub struct CustomEntry {}
#[glib::object_subclass]
impl ObjectSubclass for CustomEntry {
const NAME: &'static str = "CustomEntry";
type Type = super::CustomEntry;
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
klass.set_css_name("entry");
}
}
impl ObjectImpl for CustomEntry {}
impl WidgetImpl for CustomEntry {}
impl BinImpl for CustomEntry {}
}
glib::wrapper! {
/// Wrapper object acting as an entry.
///
/// Wrap your custom widgets with CustomEntry to get stock entry styling and
/// behavior for free.
pub struct CustomEntry(ObjectSubclass<imp::CustomEntry>)
@extends gtk::Widget, adw::Bin;
}
impl CustomEntry {
pub fn new() -> Self {
glib::Object::new(&[]).expect("Failed to create CustomEntry")
}
}
impl Default for CustomEntry {
fn default() -> Self {
Self::new()
}
}

View file

@ -1,5 +1,6 @@
mod avatar;
mod context_menu_bin;
mod custom_entry;
mod in_app_notification;
mod label_with_widgets;
mod pill;
@ -8,6 +9,7 @@ mod spinner_button;
pub use self::avatar::Avatar;
pub use self::context_menu_bin::{ContextMenuBin, ContextMenuBinExt, ContextMenuBinImpl};
pub use self::custom_entry::CustomEntry;
pub use self::in_app_notification::InAppNotification;
pub use self::label_with_widgets::LabelWithWidgets;
pub use self::pill::Pill;

View file

@ -22,6 +22,7 @@ sources = files(
'application.rs',
'components/avatar.rs',
'components/context_menu_bin.rs',
'components/custom_entry.rs',
'components/label_with_widgets.rs',
'components/mod.rs',
'components/pill.rs',