Merge follow/unfollow from kernel
Jakub Gladysz (1):
ui: add follow button
kernelkind (14):
bump nostrdb
move polling responsibility to `AccountData`
`AccountData`: decouple query from constructor
add constructor for `AccountData`
add `Contacts`
use `Contacts` in `AccountData`
expose `AccountSubs`
Unify sub for contacts in accounts & timeline
move `styled_button_toggleable` to notedeck_ui
construct NoteBuilder from existing note
send kind 3 event
add actions for follow/unfollow
add UI for (un)follow
send contact list event on account creation
This commit is contained in:
@@ -8,9 +8,9 @@ pub use picture::ProfilePic;
|
||||
pub use preview::ProfilePreview;
|
||||
|
||||
use egui::{load::TexturePoll, Label, RichText};
|
||||
use notedeck::{NostrName, NotedeckTextStyle};
|
||||
use notedeck::{IsFollowing, NostrName, NotedeckTextStyle};
|
||||
|
||||
use crate::app_images;
|
||||
use crate::{app_images, colors, widgets::styled_button_toggleable};
|
||||
|
||||
pub fn display_name_widget<'a>(
|
||||
name: &'a NostrName<'a>,
|
||||
@@ -115,3 +115,16 @@ pub fn banner(ui: &mut egui::Ui, banner_url: Option<&str>, height: f32) -> egui:
|
||||
.unwrap_or_else(|| ui.label(""))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn follow_button(following: IsFollowing) -> impl egui::Widget + 'static {
|
||||
move |ui: &mut egui::Ui| -> egui::Response {
|
||||
let (bg_color, text) = match following {
|
||||
IsFollowing::Unknown => (ui.visuals().noninteractive().bg_fill, "Unknown"),
|
||||
IsFollowing::Yes => (ui.visuals().widgets.inactive.bg_fill, "Unfollow"),
|
||||
IsFollowing::No => (colors::PINK, "Follow"),
|
||||
};
|
||||
|
||||
let enabled = following != IsFollowing::Unknown;
|
||||
ui.add(styled_button_toggleable(text, bg_color, enabled))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user