From 97560a3efde5f11b03f10e1654dc6f059b158271 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Sun, 22 Aug 2021 19:49:44 +0200 Subject: [PATCH] components: Add CustomEntry --- po/POTFILES.in | 1 + src/components/custom_entry.rs | 46 ++++++++++++++++++++++++++++++++++ src/components/mod.rs | 2 ++ src/meson.build | 1 + 4 files changed, 50 insertions(+) create mode 100644 src/components/custom_entry.rs diff --git a/po/POTFILES.in b/po/POTFILES.in index 41d6c374..76eec5fd 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/components/custom_entry.rs b/src/components/custom_entry.rs new file mode 100644 index 00000000..759316a5 --- /dev/null +++ b/src/components/custom_entry.rs @@ -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) + @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() + } +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 5d2e3e74..d80ef5a3 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -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; diff --git a/src/meson.build b/src/meson.build index ee7f4d2a..294b9139 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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',