move sized_button into ui/widgets as styled_button
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use egui::{emath::GuiRounding, Pos2, Stroke};
|
||||
use egui::{emath::GuiRounding, Button, Pos2, Stroke, Widget};
|
||||
use notedeck::NotedeckTextStyle;
|
||||
|
||||
use super::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
|
||||
|
||||
@@ -34,3 +35,27 @@ pub fn x_button(rect: egui::Rect) -> impl egui::Widget {
|
||||
helper.take_animation_response()
|
||||
}
|
||||
}
|
||||
|
||||
/// Sized and styled to match the figma design
|
||||
pub fn styled_button(text: &str, fill_color: egui::Color32) -> 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(),
|
||||
);
|
||||
|
||||
ui.add_sized(
|
||||
galley.rect.expand2(egui::vec2(16.0, 8.0)).size(),
|
||||
Button::new(galley).corner_radius(8.0).fill(fill_color),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user