TextView doesn't work in ListView #1689
-
It just doesn't display and I can't find any way to make it. I bind its buffer's property to the property I need, and if the text view is placed elsewhere it works, but if it's inside an entry of a list view, it just doesn't display anything and doesn't resize. To repro:
let content_label_binding = task_object
- .bind_property("content", &content_label, "label")
+ .bind_property("content", &content_label.buffer(), "text")
.sync_create()
.build();
> > > The patch to apply is here! <<<
From eb39d272fe0d02a30252c967a3af47653af8e1a3 Mon Sep 17 00:00:00 2001
From: WhiteBlackGoose <[email protected]>
Date: Fri, 23 Feb 2024 15:58:42 +0100
Subject: [PATCH] =?UTF-8?q?label=20->=20textview=20repro=20(=F0=9F=8D=92)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/resources/task_row.ui | 2 +-
src/task_row/imp.rs | 4 ++--
src/task_row/mod.rs | 22 ++++++----------------
3 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/src/resources/task_row.ui b/src/resources/task_row.ui
index d97d0e3..1b280e1 100644
--- a/src/resources/task_row.ui
+++ b/src/resources/task_row.ui
@@ -10,7 +10,7 @@
</object>
</child>
<child>
- <object class="GtkLabel" id="content_label">
+ <object class="GtkTextView" id="content_label">
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
diff --git a/src/task_row/imp.rs b/src/task_row/imp.rs
index f32279e..ec41057 100644
--- a/src/task_row/imp.rs
+++ b/src/task_row/imp.rs
@@ -4,7 +4,7 @@ use gio::{
glib::{self, Binding},
subclass::prelude::{ObjectImpl, ObjectSubclass},
};
-use gtk::subclass::widget::WidgetClassExt;
+use gtk::{subclass::widget::WidgetClassExt, Button, TextView};
use gtk::{
subclass::{
prelude::BoxImpl,
@@ -20,7 +20,7 @@ pub struct TaskRow {
#[template_child]
pub completed_button: TemplateChild<CheckButton>,
#[template_child]
- pub content_label: TemplateChild<Label>,
+ pub content_label: TemplateChild<TextView>,
// Vector holding the bindings to properties of `TaskObject`
pub bindings: RefCell<Vec<Binding>>,
}
diff --git a/src/task_row/mod.rs b/src/task_row/mod.rs
index e760ae3..57f6ee7 100644
--- a/src/task_row/mod.rs
+++ b/src/task_row/mod.rs
@@ -3,7 +3,11 @@ use gio::{
prelude::{ObjectExt, ToValue},
subclass::prelude::ObjectSubclassIsExt,
};
-use gtk::pango::{AttrInt, AttrList};
+use gtk::{
+ pango::{AttrInt, AttrList},
+ prelude::TextViewExt,
+ traits::ButtonExt,
+};
use crate::task_object::TaskObject;
@@ -43,28 +47,14 @@ impl TaskRow {
// Bind `task_object.content` to `task_row.content_label.label`
let content_label_binding = task_object
- .bind_property("content", &content_label, "label")
+ .bind_property("content", &content_label.buffer(), "text")
.sync_create()
.build();
// Save binding
bindings.push(content_label_binding);
// Bind `task_object.completed` to `task_row.content_label.attributes`
- let content_label_binding = task_object
- .bind_property("completed", &content_label, "attributes")
- .sync_create()
- .transform_to(|_, active| {
- let attribute_list = AttrList::new();
- if active {
- // If "active" is true, content of the label will be strikethrough
- let attribute = AttrInt::new_strikethrough(true);
- attribute_list.insert(attribute);
- }
- Some(attribute_list.to_value())
- })
- .build();
// Save binding
- bindings.push(content_label_binding);
}
pub fn unbind(&self) {
--
2.42.0 If needed, I'll prepare a single file repro without building on top of that todo example |
Beta Was this translation helpful? Give feedback.
Answered by
zecakeh
Apr 12, 2024
Replies: 1 comment
-
It shows up if you set |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bilelmoussaoui
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It shows up if you set
hexpand
totrue
on the GtkTextView.