commit 8a77ba5f8f74070a0536a7a2b61e2965abc57117
parent 99405378972e9e3c6f42cb9f3278cbe301650118
Author: kernelkind <kernelkind@gmail.com>
Date: Sat, 5 Jul 2025 14:49:08 -0400
move `styled_button_toggleable` to notedeck_ui
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
3 files changed, 50 insertions(+), 47 deletions(-)
diff --git a/crates/notedeck_columns/src/ui/note/custom_zap.rs b/crates/notedeck_columns/src/ui/note/custom_zap.rs
@@ -9,9 +9,10 @@ use nostrdb::{Ndb, ProfileRecord, Transaction};
use notedeck::{
fonts::get_font_size, get_profile_url, name::get_display_name, Images, NotedeckTextStyle,
};
-use notedeck_ui::{app_images, colors, profile::display_name_widget, AnimationHelper, ProfilePic};
-
-use crate::ui::widgets::styled_button_toggleable;
+use notedeck_ui::{
+ app_images, colors, profile::display_name_widget, widgets::styled_button_toggleable,
+ AnimationHelper, ProfilePic,
+};
pub struct CustomZapView<'a> {
images: &'a mut Images,
diff --git a/crates/notedeck_columns/src/ui/widgets.rs b/crates/notedeck_columns/src/ui/widgets.rs
@@ -1,49 +1,7 @@
-use egui::{Button, Widget};
-use notedeck::NotedeckTextStyle;
+use egui::Widget;
+use notedeck_ui::widgets::styled_button_toggleable;
/// Sized and styled to match the figma design
pub fn styled_button(text: &str, fill_color: egui::Color32) -> impl Widget + '_ {
styled_button_toggleable(text, fill_color, true)
}
-
-pub fn styled_button_toggleable(
- text: &str,
- fill_color: egui::Color32,
- enabled: bool,
-) -> impl Widget + '_ {
- move |ui: &mut egui::Ui| -> egui::Response {
- let painter = ui.painter();
- let text_color = if ui.visuals().dark_mode {
- egui::Color32::WHITE
- } else {
- egui::Color32::BLACK
- };
-
- let galley = painter.layout(
- text.to_owned(),
- NotedeckTextStyle::Body.get_font_id(ui.ctx()),
- text_color,
- ui.available_width(),
- );
-
- let size = galley.rect.expand2(egui::vec2(16.0, 8.0)).size();
- let mut button = Button::new(galley).corner_radius(8.0);
-
- if !enabled {
- button = button
- .sense(egui::Sense::focusable_noninteractive())
- .fill(ui.visuals().noninteractive().bg_fill)
- .stroke(ui.visuals().noninteractive().bg_stroke);
- } else {
- button = button.fill(fill_color);
- }
-
- let mut resp = ui.add_sized(size, button);
-
- if !enabled {
- resp = resp.on_hover_cursor(egui::CursorIcon::NotAllowed);
- }
-
- resp
- }
-}
diff --git a/crates/notedeck_ui/src/widgets.rs b/crates/notedeck_ui/src/widgets.rs
@@ -1,5 +1,6 @@
use crate::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
use egui::{emath::GuiRounding, Pos2, Stroke};
+use notedeck::NotedeckTextStyle;
pub fn x_button(rect: egui::Rect) -> impl egui::Widget {
move |ui: &mut egui::Ui| -> egui::Response {
@@ -33,3 +34,46 @@ pub fn x_button(rect: egui::Rect) -> impl egui::Widget {
helper.take_animation_response()
}
}
+
+/// Button styled in the Notedeck theme
+pub fn styled_button_toggleable(
+ text: &str,
+ fill_color: egui::Color32,
+ enabled: bool,
+) -> impl egui::Widget + '_ {
+ move |ui: &mut egui::Ui| -> egui::Response {
+ let painter = ui.painter();
+ let text_color = if ui.visuals().dark_mode {
+ egui::Color32::WHITE
+ } else {
+ egui::Color32::BLACK
+ };
+
+ let galley = painter.layout(
+ text.to_owned(),
+ NotedeckTextStyle::Button.get_font_id(ui.ctx()),
+ text_color,
+ ui.available_width(),
+ );
+
+ let size = galley.rect.expand2(egui::vec2(16.0, 8.0)).size();
+ let mut button = egui::Button::new(galley).corner_radius(8.0);
+
+ if !enabled {
+ button = button
+ .sense(egui::Sense::focusable_noninteractive())
+ .fill(ui.visuals().noninteractive().bg_fill)
+ .stroke(ui.visuals().noninteractive().bg_stroke);
+ } else {
+ button = button.fill(fill_color);
+ }
+
+ let mut resp = ui.add_sized(size, button);
+
+ if !enabled {
+ resp = resp.on_hover_cursor(egui::CursorIcon::NotAllowed);
+ }
+
+ resp
+ }
+}