move styled_button_toggleable to notedeck_ui
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -9,9 +9,10 @@ use nostrdb::{Ndb, ProfileRecord, Transaction};
|
|||||||
use notedeck::{
|
use notedeck::{
|
||||||
fonts::get_font_size, get_profile_url, name::get_display_name, Images, NotedeckTextStyle,
|
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 notedeck_ui::{
|
||||||
|
app_images, colors, profile::display_name_widget, widgets::styled_button_toggleable,
|
||||||
use crate::ui::widgets::styled_button_toggleable;
|
AnimationHelper, ProfilePic,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct CustomZapView<'a> {
|
pub struct CustomZapView<'a> {
|
||||||
images: &'a mut Images,
|
images: &'a mut Images,
|
||||||
|
|||||||
@@ -1,49 +1,7 @@
|
|||||||
use egui::{Button, Widget};
|
use egui::Widget;
|
||||||
use notedeck::NotedeckTextStyle;
|
use notedeck_ui::widgets::styled_button_toggleable;
|
||||||
|
|
||||||
/// Sized and styled to match the figma design
|
/// Sized and styled to match the figma design
|
||||||
pub fn styled_button(text: &str, fill_color: egui::Color32) -> impl Widget + '_ {
|
pub fn styled_button(text: &str, fill_color: egui::Color32) -> impl Widget + '_ {
|
||||||
styled_button_toggleable(text, fill_color, true)
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
|
use crate::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
|
||||||
use egui::{emath::GuiRounding, Pos2, Stroke};
|
use egui::{emath::GuiRounding, Pos2, Stroke};
|
||||||
|
use notedeck::NotedeckTextStyle;
|
||||||
|
|
||||||
pub fn x_button(rect: egui::Rect) -> impl egui::Widget {
|
pub fn x_button(rect: egui::Rect) -> impl egui::Widget {
|
||||||
move |ui: &mut egui::Ui| -> egui::Response {
|
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()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user