move styled_button_toggleable to notedeck_ui

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-05 14:49:08 -04:00
parent 9940537897
commit 8a77ba5f8f
3 changed files with 50 additions and 47 deletions

View File

@@ -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,

View File

@@ -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
}
}

View File

@@ -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
}
}