widgets: Update to relm4 next branch

This commit is contained in:
Ian Douglas Scott 2022-06-27 16:41:27 -07:00
parent d004d686bd
commit 887ff2959c
4 changed files with 27 additions and 26 deletions

View file

@ -6,12 +6,12 @@ edition = "2021"
[dependencies] [dependencies]
cascade = "1.0.0" cascade = "1.0.0"
derivative = { version = "2", optional = true } derivative = { version = "2", optional = true }
gtk4 = { version = "0.4.4", features = ["v4_4"] } gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs", features = ["v4_4"] }
gdk4 = "0.4.4" gdk4 = { git = "https://github.com/gtk-rs/gtk4-rs" }
gdk4-wayland = { version = "0.4.2", features = ["wayland_crate"], optional = true } gdk4-wayland = { git = "https://github.com/gtk-rs/gtk4-rs", features = ["wayland_crate"], optional = true }
gdk4-x11 = { version = "0.4.2", features = ["xlib"] } gdk4-x11 = { git = "https://github.com/gtk-rs/gtk4-rs", features = ["xlib"] }
gio = "0.15.2" gio = { git = "https://github.com/gtk-rs/gtk-rs-core" }
gobject-sys = "0.15.1" gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs-core" }
wayland-client = { version = "0.29.4", optional = true } wayland-client = { version = "0.29.4", optional = true }
wayland-protocols = { version = "0.29.4", features = ["client", "unstable_protocols"], optional = true } wayland-protocols = { version = "0.29.4", features = ["client", "unstable_protocols"], optional = true }
x11 = { version = "2.19.1", features = ["xlib"] } x11 = { version = "2.19.1", features = ["xlib"] }

View file

@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
relm4 = { git = "https://github.com/AaronErhardt/relm4", rev = "7404ad64ca8763f6629cadcd743947cd29e1538a" } relm4 = { git = "https://github.com/AaronErhardt/relm4", branch = "next" }
relm4-macros = { git = "https://github.com/AaronErhardt/relm4", branch = "new-approach" } relm4-macros = { git = "https://github.com/AaronErhardt/relm4", branch = "next" }
tracker = "0.1.1" tracker = "0.1.1"

View file

@ -1,6 +1,6 @@
use relm4::{ use relm4::{
gtk::{prelude::*, Align, Box as GtkBox, Label, Orientation, Widget}, gtk::{prelude::*, Align, Box as GtkBox, Label, Orientation, Widget},
ComponentParts, Sender, SimpleComponent, ComponentParts, ComponentSender, SimpleComponent,
}; };
use std::cell::RefCell; use std::cell::RefCell;
@ -21,7 +21,7 @@ pub(crate) struct LabeledItem {
#[do_not_track] #[do_not_track]
_remove_child: RefCell<Option<Widget>>, _remove_child: RefCell<Option<Widget>>,
#[do_not_track] #[do_not_track]
_sender: Sender<LabeledItemMessage>, _sender: ComponentSender<Self>,
} }
impl LabeledItem { impl LabeledItem {
@ -46,7 +46,7 @@ impl LabeledItem {
S: ToString, S: ToString,
{ {
self._sender self._sender
.send(LabeledItemMessage::Title(title.to_string())); .input(LabeledItemMessage::Title(title.to_string()));
} }
pub fn set_description<'a, O>(&self, description: O) pub fn set_description<'a, O>(&self, description: O)
@ -55,15 +55,15 @@ impl LabeledItem {
{ {
let description = description.into(); let description = description.into();
self._sender self._sender
.send(LabeledItemMessage::Desc(description.map(|s| s.to_string()))); .input(LabeledItemMessage::Desc(description.map(|s| s.to_string())));
} }
pub fn set_alignment(&self, align: Align) { pub fn set_alignment(&self, align: Align) {
self._sender.send(LabeledItemMessage::Align(align)); self._sender.input(LabeledItemMessage::Align(align));
} }
pub fn set_child(&self, child: Widget) { pub fn set_child(&self, child: Widget) {
self._sender.send(LabeledItemMessage::Child(child)); self._sender.input(LabeledItemMessage::Child(child));
} }
} }
@ -90,26 +90,28 @@ impl SimpleComponent for LabeledItem {
set_hexpand: true, set_hexpand: true,
set_spacing: 8, set_spacing: 8,
set_valign: Align::Center, set_valign: Align::Center,
&Label { Label {
add_css_class: "labeled-item-title", add_css_class: "labeled-item-title",
set_halign: Align::Start, set_halign: Align::Start,
set_label: watch! { &model._title } #[watch]
set_label: &model._title
}, },
&Label { Label {
add_css_class: "labeled-item-desc", add_css_class: "labeled-item-desc",
set_halign: Align::Start, set_halign: Align::Start,
set_visible: watch! { model._desc.is_some() }, #[watch]
set_label: watch! { &model._desc.clone().unwrap_or_default() } set_visible: model._desc.is_some(),
#[watch]
set_label: &model._desc.clone().unwrap_or_default()
}, },
} }
} }
} }
fn init_parts( fn init(
_init_params: Self::InitParams, _init_params: Self::InitParams,
root: &Self::Root, root: &Self::Root,
input: &Sender<Self::Input>, _sender: &ComponentSender<Self>,
_output: &Sender<Self::Output>,
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
let model = LabeledItem { let model = LabeledItem {
_title: String::default(), _title: String::default(),
@ -117,7 +119,7 @@ impl SimpleComponent for LabeledItem {
_align: Align::Start, _align: Align::Start,
_child: None, _child: None,
_remove_child: RefCell::new(None), _remove_child: RefCell::new(None),
_sender: input.clone(), _sender: _sender.clone(),
tracker: 0, tracker: 0,
}; };
let widgets = view_output!(); let widgets = view_output!();
@ -128,8 +130,7 @@ impl SimpleComponent for LabeledItem {
fn update( fn update(
&mut self, &mut self,
msg: Self::Input, msg: Self::Input,
_input: &Sender<Self::Input>, _sender: &ComponentSender<Self>,
_ouput: &Sender<Self::Output>,
) { ) {
self.reset(); self.reset();
match msg { match msg {

View file

@ -67,7 +67,7 @@ impl LabeledItem {
impl Default for LabeledItem { impl Default for LabeledItem {
fn default() -> Self { fn default() -> Self {
let root = GtkBox::new(Orientation::Horizontal, 0); let root = GtkBox::new(Orientation::Horizontal, 0);
let controller = imp::LabeledItem::init() let controller = imp::LabeledItem::builder()
.attach_to(&root) .attach_to(&root)
.launch(()) .launch(())
.detach(); .detach();