From 8464a1d22c68d185420d7204c1314bcde7ae18c7 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Thu, 21 Nov 2024 15:25:20 -0500 Subject: [PATCH 1/2] disable post button if draft buffer empty closes: https://github.com/damus-io/notedeck/issues/417 Signed-off-by: kernelkind --- src/ui/note/post.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ui/note/post.rs b/src/ui/note/post.rs index 1308c17..3cfbc4c 100644 --- a/src/ui/note/post.rs +++ b/src/ui/note/post.rs @@ -209,7 +209,10 @@ impl<'a> PostView<'a> { ui.with_layout(egui::Layout::right_to_left(egui::Align::BOTTOM), |ui| { if ui - .add_sized([91.0, 32.0], egui::Button::new("Post now")) + .add_sized( + [91.0, 32.0], + post_button(!self.draft.buffer.is_empty()), + ) .clicked() { let new_post = NewPost::new( @@ -236,6 +239,23 @@ impl<'a> PostView<'a> { } } +fn post_button(interactive: bool) -> impl egui::Widget { + move |ui: &mut egui::Ui| { + let button = egui::Button::new("Post now"); + if interactive { + ui.add(button) + } else { + ui.add( + button + .sense(egui::Sense::hover()) + .fill(ui.visuals().widgets.noninteractive.bg_fill) + .stroke(ui.visuals().widgets.noninteractive.bg_stroke), + ) + .on_hover_cursor(egui::CursorIcon::NotAllowed) + } + } +} + mod preview { use super::*; From 4133570c2e2e8c7ab03d3edec2f69b4f392cde18 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 22 Nov 2024 12:57:50 -0800 Subject: [PATCH 2/2] ui: simply hide post button if buffer is empty Fixes: 8464a1d22c68 ("disable post button if draft buffer empty") Signed-off-by: William Casarin --- src/ui/note/post.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/ui/note/post.rs b/src/ui/note/post.rs index 3cfbc4c..660c5a6 100644 --- a/src/ui/note/post.rs +++ b/src/ui/note/post.rs @@ -208,10 +208,15 @@ impl<'a> PostView<'a> { } ui.with_layout(egui::Layout::right_to_left(egui::Align::BOTTOM), |ui| { + if self.draft.buffer.is_empty() { + // Don't render button if our buffer is empty + return None; + } + if ui .add_sized( [91.0, 32.0], - post_button(!self.draft.buffer.is_empty()), + egui::Button::new("Post now") ) .clicked() { @@ -239,23 +244,6 @@ impl<'a> PostView<'a> { } } -fn post_button(interactive: bool) -> impl egui::Widget { - move |ui: &mut egui::Ui| { - let button = egui::Button::new("Post now"); - if interactive { - ui.add(button) - } else { - ui.add( - button - .sense(egui::Sense::hover()) - .fill(ui.visuals().widgets.noninteractive.bg_fill) - .stroke(ui.visuals().widgets.noninteractive.bg_stroke), - ) - .on_hover_cursor(egui::CursorIcon::NotAllowed) - } - } -} - mod preview { use super::*;