move close_button to ui/widgets.rs as x_button
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ pub mod thread;
|
|||||||
pub mod timeline;
|
pub mod timeline;
|
||||||
pub mod username;
|
pub mod username;
|
||||||
pub mod wallet;
|
pub mod wallet;
|
||||||
|
pub mod widgets;
|
||||||
|
|
||||||
pub use accounts::AccountsView;
|
pub use accounts::AccountsView;
|
||||||
pub use mention::Mention;
|
pub use mention::Mention;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use egui::emath::GuiRounding;
|
use egui::{vec2, FontId, Layout, Pos2, Rect, ScrollArea, UiBuilder, Vec2b};
|
||||||
use egui::{vec2, FontId, Layout, Pos2, Rect, ScrollArea, Stroke, UiBuilder, Vec2b};
|
|
||||||
use nostrdb::{Ndb, ProfileRecord, Transaction};
|
use nostrdb::{Ndb, ProfileRecord, Transaction};
|
||||||
use notedeck::{fonts::get_font_size, Images, NotedeckTextStyle};
|
use notedeck::{fonts::get_font_size, Images, NotedeckTextStyle};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
@@ -9,6 +8,7 @@ use crate::{
|
|||||||
ui::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE},
|
ui::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::widgets::x_button;
|
||||||
use super::{profile::get_profile_url, ProfilePic};
|
use super::{profile::get_profile_url, ProfilePic};
|
||||||
|
|
||||||
pub struct SearchResultsView<'a> {
|
pub struct SearchResultsView<'a> {
|
||||||
@@ -90,7 +90,7 @@ impl<'a> SearchResultsView<'a> {
|
|||||||
UiBuilder::new()
|
UiBuilder::new()
|
||||||
.max_rect(close_section_rect)
|
.max_rect(close_section_rect)
|
||||||
.layout(Layout::right_to_left(egui::Align::Center)),
|
.layout(Layout::right_to_left(egui::Align::Center)),
|
||||||
|ui| ui.add(close_button(button_resp.rect)).clicked(),
|
|ui| ui.add(x_button(button_resp.rect)).clicked(),
|
||||||
)
|
)
|
||||||
.inner
|
.inner
|
||||||
};
|
};
|
||||||
@@ -168,36 +168,3 @@ fn user_result<'a>(
|
|||||||
pfp_resp.union(helper.take_animation_response())
|
pfp_resp.union(helper.take_animation_response())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_button(rect: egui::Rect) -> impl egui::Widget {
|
|
||||||
move |ui: &mut egui::Ui| -> egui::Response {
|
|
||||||
let max_width = rect.width();
|
|
||||||
let helper = AnimationHelper::new_from_rect(ui, "user_search_close", rect);
|
|
||||||
|
|
||||||
let fill_color = ui.visuals().text_color();
|
|
||||||
|
|
||||||
let radius = max_width / (2.0 * ICON_EXPANSION_MULTIPLE);
|
|
||||||
|
|
||||||
let painter = ui.painter();
|
|
||||||
let ppp = ui.ctx().pixels_per_point();
|
|
||||||
let nw_edge = helper
|
|
||||||
.scale_pos_from_center(Pos2::new(-radius, radius))
|
|
||||||
.round_to_pixel_center(ppp);
|
|
||||||
let se_edge = helper
|
|
||||||
.scale_pos_from_center(Pos2::new(radius, -radius))
|
|
||||||
.round_to_pixel_center(ppp);
|
|
||||||
let sw_edge = helper
|
|
||||||
.scale_pos_from_center(Pos2::new(-radius, -radius))
|
|
||||||
.round_to_pixel_center(ppp);
|
|
||||||
let ne_edge = helper
|
|
||||||
.scale_pos_from_center(Pos2::new(radius, radius))
|
|
||||||
.round_to_pixel_center(ppp);
|
|
||||||
|
|
||||||
let line_width = helper.scale_1d_pos(2.0);
|
|
||||||
|
|
||||||
painter.line_segment([nw_edge, se_edge], Stroke::new(line_width, fill_color));
|
|
||||||
painter.line_segment([ne_edge, sw_edge], Stroke::new(line_width, fill_color));
|
|
||||||
|
|
||||||
helper.take_animation_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
36
crates/notedeck_columns/src/ui/widgets.rs
Normal file
36
crates/notedeck_columns/src/ui/widgets.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use egui::{emath::GuiRounding, Pos2, Stroke};
|
||||||
|
|
||||||
|
use super::anim::{AnimationHelper, ICON_EXPANSION_MULTIPLE};
|
||||||
|
|
||||||
|
pub fn x_button(rect: egui::Rect) -> impl egui::Widget {
|
||||||
|
move |ui: &mut egui::Ui| -> egui::Response {
|
||||||
|
let max_width = rect.width();
|
||||||
|
let helper = AnimationHelper::new_from_rect(ui, "user_search_close", rect);
|
||||||
|
|
||||||
|
let fill_color = ui.visuals().text_color();
|
||||||
|
|
||||||
|
let radius = max_width / (2.0 * ICON_EXPANSION_MULTIPLE);
|
||||||
|
|
||||||
|
let painter = ui.painter();
|
||||||
|
let ppp = ui.ctx().pixels_per_point();
|
||||||
|
let nw_edge = helper
|
||||||
|
.scale_pos_from_center(Pos2::new(-radius, radius))
|
||||||
|
.round_to_pixel_center(ppp);
|
||||||
|
let se_edge = helper
|
||||||
|
.scale_pos_from_center(Pos2::new(radius, -radius))
|
||||||
|
.round_to_pixel_center(ppp);
|
||||||
|
let sw_edge = helper
|
||||||
|
.scale_pos_from_center(Pos2::new(-radius, -radius))
|
||||||
|
.round_to_pixel_center(ppp);
|
||||||
|
let ne_edge = helper
|
||||||
|
.scale_pos_from_center(Pos2::new(radius, radius))
|
||||||
|
.round_to_pixel_center(ppp);
|
||||||
|
|
||||||
|
let line_width = helper.scale_1d_pos(2.0);
|
||||||
|
|
||||||
|
painter.line_segment([nw_edge, se_edge], Stroke::new(line_width, fill_color));
|
||||||
|
painter.line_segment([ne_edge, sw_edge], Stroke::new(line_width, fill_color));
|
||||||
|
|
||||||
|
helper.take_animation_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user