Allow LabeledItem to be used as a regular widget, hopefully

This commit is contained in:
Lucy 2022-02-28 15:23:01 -05:00
parent 724f7f5a9f
commit feee2bacc3
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
2 changed files with 19 additions and 5 deletions

View file

@ -1,5 +1,5 @@
use gtk4::{prelude::*, Align, Label, Orientation, Widget};
use relm4::{ComponentBuilder, ComponentParts, Sender, SimpleComponent};
use relm4::{ComponentParts, Sender, SimpleComponent};
use std::cell::RefCell;
#[derive(Debug)]
@ -107,7 +107,7 @@ impl SimpleComponent for LabeledItem {
root: &Self::Root,
input: &Sender<Self::Input>,
_output: &Sender<Self::Output>,
) -> ComponentParts<Self, Self::Widgets> {
) -> ComponentParts<Self> {
let model = LabeledItem {
_title: String::default(),
_desc: None,

View file

@ -2,15 +2,15 @@ mod imp;
use gtk4::{glib::IsA, prelude::*, Align, Orientation, Widget};
use relm4::{Component, ComponentController, ComponentParts, Controller};
use std::cell::Ref;
use std::{cell::Ref, ops::Deref};
pub struct LabeledItem {
root: gtk4::Box,
controller: Controller<imp::LabeledItem, gtk4::Box, imp::AppWidgets, imp::LabeledItemMessage>,
controller: Controller<imp::LabeledItem>,
}
impl LabeledItem {
fn inner(&self) -> Ref<'_, ComponentParts<imp::LabeledItem, imp::AppWidgets>> {
fn inner(&self) -> Ref<'_, ComponentParts<imp::LabeledItem>> {
self.controller.state().get()
}
@ -72,3 +72,17 @@ impl Default for LabeledItem {
Self { root, controller }
}
}
impl AsRef<Widget> for LabeledItem {
fn as_ref(&self) -> &Widget {
self.root.upcast_ref()
}
}
impl Deref for LabeledItem {
type Target = gtk4::Box;
fn deref(&self) -> &Self::Target {
&self.root
}
}