commit cc03f24920171f8bd0e854b587a4295b4c3dd37e
parent aa0c1012db92d0dd57e551a0a2edf03281d54f2b
Author: William Casarin <jb55@jb55.com>
Date: Wed, 16 Apr 2025 22:25:44 -0700
refactor: move input buttons ui into its own fn
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 31 insertions(+), 40 deletions(-)
diff --git a/crates/notedeck_columns/src/ui/note/post.rs b/crates/notedeck_columns/src/ui/note/post.rs
@@ -367,46 +367,7 @@ impl<'a, 'd> PostView<'a, 'd> {
self.transfer_uploads(ui);
self.show_upload_errors(ui);
- let post_action = ui
- .horizontal(|ui| {
- ui.with_layout(
- egui::Layout::left_to_right(egui::Align::BOTTOM),
- |ui| {
- self.show_upload_media_button(ui);
- },
- );
-
- ui.with_layout(egui::Layout::right_to_left(egui::Align::BOTTOM), |ui| {
- let post_button_clicked = ui
- .add_sized(
- [91.0, 32.0],
- post_button(!self.draft.buffer.is_empty()),
- )
- .clicked();
-
- let shortcut_pressed = ui.input(|i| {
- (i.modifiers.ctrl || i.modifiers.command)
- && i.key_pressed(egui::Key::Enter)
- });
-
- if post_button_clicked
- || (!self.draft.buffer.is_empty() && shortcut_pressed)
- {
- let output = self.draft.buffer.output();
- let new_post = NewPost::new(
- output.text,
- self.poster.to_full(),
- self.draft.uploaded_media.clone(),
- output.mentions,
- );
- Some(NewPostAction::new(self.post_type.clone(), new_post))
- } else {
- None
- }
- })
- .inner
- })
- .inner;
+ let post_action = ui.horizontal(|ui| self.input_buttons(ui)).inner;
let action = note_response
.and_then(|nr| nr.action.map(PostAction::QuotedNoteAction))
@@ -422,6 +383,36 @@ impl<'a, 'd> PostView<'a, 'd> {
.inner
}
+ fn input_buttons(&mut self, ui: &mut egui::Ui) -> Option<NewPostAction> {
+ ui.with_layout(egui::Layout::left_to_right(egui::Align::BOTTOM), |ui| {
+ self.show_upload_media_button(ui);
+ });
+
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::BOTTOM), |ui| {
+ let post_button_clicked = ui
+ .add_sized([91.0, 32.0], post_button(!self.draft.buffer.is_empty()))
+ .clicked();
+
+ let shortcut_pressed = ui.input(|i| {
+ (i.modifiers.ctrl || i.modifiers.command) && i.key_pressed(egui::Key::Enter)
+ });
+
+ if post_button_clicked || (!self.draft.buffer.is_empty() && shortcut_pressed) {
+ let output = self.draft.buffer.output();
+ let new_post = NewPost::new(
+ output.text,
+ self.poster.to_full(),
+ self.draft.uploaded_media.clone(),
+ output.mentions,
+ );
+ Some(NewPostAction::new(self.post_type.clone(), new_post))
+ } else {
+ None
+ }
+ })
+ .inner
+ }
+
fn show_media(&mut self, ui: &mut egui::Ui) {
let mut to_remove = Vec::new();
for (i, media) in self.draft.uploaded_media.iter().enumerate() {