Load "option" SVG symbol for RelayItem widget

This commit is contained in:
Bu5hm4nn 2023-05-17 16:56:30 -06:00
parent ea7c1f91eb
commit 0382c3d8f1
5 changed files with 44 additions and 16 deletions

3
assets/option.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 17 17">
<path fill="#FFFFFFFF" fill-rule="evenodd" d="M9.79 4.045H.99a.8.8 0 0 1 0-1.6h8.8a1.6 1.6 0 0 1 1.6-1.6h1.6a1.6 1.6 0 0 1 1.6 1.6h.8a.8.8 0 0 1 0 1.6h-.8a1.6 1.6 0 0 1-1.6 1.6h-1.6a1.6 1.6 0 0 1-1.6-1.6Zm3.2-1.6h-1.6v1.6h1.6v-1.6Zm2.4 5.6h-7.2a1.6 1.6 0 0 0-1.6-1.6h-1.6a1.6 1.6 0 0 0-1.6 1.6H.99a.8.8 0 1 0 0 1.6h2.4a1.6 1.6 0 0 0 1.6 1.6h1.6a1.6 1.6 0 0 0 1.6-1.6h7.2a.8.8 0 0 0 0-1.6Zm-8.8 0h-1.6v1.6h1.6v-1.6Zm8.8 5.6h-2.4a1.6 1.6 0 0 0-1.6-1.6h-1.6a1.6 1.6 0 0 0-1.6 1.6H.99a.8.8 0 0 0 0 1.6h7.2a1.6 1.6 0 0 0 1.6 1.6h1.6a1.6 1.6 0 0 0 1.6-1.6h2.4a.8.8 0 0 0 0-1.6Zm-4 0h-1.6v1.6h1.6v-1.6Z" clip-rule="evenodd"/>
</svg>

After

Width:  |  Height:  |  Size: 712 B

View File

@ -207,6 +207,7 @@ struct GossipUi {
about: About,
icon: TextureHandle,
placeholder_avatar: TextureHandle,
options_symbol: TextureHandle,
settings: Settings,
avatars: HashMap<PublicKeyHex, TextureHandle>,
images: HashMap<Url, TextureHandle>,
@ -351,17 +352,19 @@ impl GossipUi {
};
// how to load an svg
// let expand_right_symbol = {
// let bytes = include_bytes!("../../assets/expand-image.svg");
// let color_image = egui_extras::image::load_svg_bytes_with_size(
// bytes,
// egui_extras::image::FitTo::Size(200, 1000),
// ).unwrap();
// cctx.egui_ctx.load_texture(
// "expand_right_symbol",
// color_image,
// TextureOptions::default())
// };
let options_symbol = {
let bytes = include_bytes!("../../assets/option.svg");
let color_image = egui_extras::image::load_svg_bytes_with_size(
bytes,
egui_extras::image::FitTo::Size(
(cctx.egui_ctx.pixels_per_point() * 40.0) as u32,
(cctx.egui_ctx.pixels_per_point() * 40.0) as u32),
).unwrap();
cctx.egui_ctx.load_texture(
"options_symbol",
color_image,
TextureOptions::LINEAR)
};
let current_dpi = (cctx.egui_ctx.pixels_per_point() * 72.0) as u32;
let (override_dpi, override_dpi_value): (bool, u32) = match settings.override_dpi {
@ -415,6 +418,7 @@ impl GossipUi {
about: crate::about::about(),
icon: icon_texture_handle,
placeholder_avatar: placeholder_avatar_texture_handle,
options_symbol,
settings,
avatars: HashMap::new(),
images: HashMap::new(),

View File

@ -53,7 +53,9 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
.show(ui, |ui| {
for relay in relays {
let mut widget =
widgets::RelayEntry::new(&relay).accent(app.settings.theme.accent_color());
widgets::RelayEntry::new(&relay)
.accent(app.settings.theme.accent_color())
.option_symbol(&app.options_symbol);
if let Some(ref assignment) = GLOBALS.relay_picker.get_relay_assignment(&relay.url)
{
widget = widget.user_count(assignment.pubkeys.len());

View File

@ -68,7 +68,10 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
})
.show(ui, |ui| {
for relay in relays {
let mut widget = widgets::RelayEntry::new(&relay);
let mut widget =
widgets::RelayEntry::new(&relay)
.accent(app.settings.theme.accent_color())
.option_symbol(&app.options_symbol);
if let Some(ref assignment) =
GLOBALS.relay_picker.get_relay_assignment(&relay.url)
{

View File

@ -42,6 +42,7 @@ pub struct RelayEntry<'a> {
stroke: Option<Stroke>,
accent: Option<Color32>,
highlight: Option<Color32>,
option_symbol: Option<&'a TextureHandle>,
}
impl<'a> RelayEntry<'a> {
@ -55,6 +56,7 @@ impl<'a> RelayEntry<'a> {
stroke: None,
accent: None,
highlight: None,
option_symbol: None,
}
}
@ -87,6 +89,11 @@ impl<'a> RelayEntry<'a> {
self.highlight = Some(highlight);
self
}
pub fn option_symbol(mut self, option_symbol: &'a TextureHandle ) -> Self {
self.option_symbol = Some(option_symbol);
self
}
}
impl<'a> RelayEntry<'a> {
@ -140,6 +147,7 @@ impl<'a> RelayEntry<'a> {
if response.clicked() {
// TODO go to edit mode
}
response.on_hover_cursor(CursorIcon::PointingHand);
draw_text_galley_at(ui, pos, galley, Some(color), Some(stroke));
} else {
let pos = rect.right_top() + vec2(-BTN_SIZE - TEXT_RIGHT, 10.0 + MARGIN_TOP);
@ -151,8 +159,15 @@ impl<'a> RelayEntry<'a> {
} else {
ui.visuals().text_color()
};
let text = RichText::new("\u{2699}").size(20.0);
draw_text_at(ui, pos, text.into(), Align::LEFT, Some(color), None);
response.on_hover_cursor(CursorIcon::PointingHand);
if let Some(symbol) = self.option_symbol {
let mut mesh = Mesh::with_texture((symbol).into());
mesh.add_rect_with_uv(btn_rect.shrink(2.0), Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), color);
ui.painter().add(Shape::mesh(mesh));
} else {
let text = RichText::new("\u{2699}").size(20.0);
draw_text_at(ui, pos, text.into(), Align::LEFT, Some(color), None);
}
}
}
@ -181,7 +196,7 @@ impl<'a> RelayEntry<'a> {
RichText::new(format!("Following: {}", count))
} else {
active = false;
RichText::new("Following: -")
RichText::new("Following: ---")
};
let (galley, response) = allocate_text_at(ui, pos, text.into());
let (color, stroke) = if !active {
@ -198,6 +213,7 @@ impl<'a> RelayEntry<'a> {
if response.clicked() {
// TODO go to following page for this relay?
}
if active { response.on_hover_cursor(CursorIcon::PointingHand); }
draw_text_galley_at(ui, pos, galley, Some(color), Some(stroke));
// ---- Last event ----