mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
Load "option" SVG symbol for RelayItem widget
This commit is contained in:
parent
ea7c1f91eb
commit
0382c3d8f1
3
assets/option.svg
Normal file
3
assets/option.svg
Normal 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 |
@ -207,6 +207,7 @@ struct GossipUi {
|
|||||||
about: About,
|
about: About,
|
||||||
icon: TextureHandle,
|
icon: TextureHandle,
|
||||||
placeholder_avatar: TextureHandle,
|
placeholder_avatar: TextureHandle,
|
||||||
|
options_symbol: TextureHandle,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
avatars: HashMap<PublicKeyHex, TextureHandle>,
|
avatars: HashMap<PublicKeyHex, TextureHandle>,
|
||||||
images: HashMap<Url, TextureHandle>,
|
images: HashMap<Url, TextureHandle>,
|
||||||
@ -351,17 +352,19 @@ impl GossipUi {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// how to load an svg
|
// how to load an svg
|
||||||
// let expand_right_symbol = {
|
let options_symbol = {
|
||||||
// let bytes = include_bytes!("../../assets/expand-image.svg");
|
let bytes = include_bytes!("../../assets/option.svg");
|
||||||
// let color_image = egui_extras::image::load_svg_bytes_with_size(
|
let color_image = egui_extras::image::load_svg_bytes_with_size(
|
||||||
// bytes,
|
bytes,
|
||||||
// egui_extras::image::FitTo::Size(200, 1000),
|
egui_extras::image::FitTo::Size(
|
||||||
// ).unwrap();
|
(cctx.egui_ctx.pixels_per_point() * 40.0) as u32,
|
||||||
// cctx.egui_ctx.load_texture(
|
(cctx.egui_ctx.pixels_per_point() * 40.0) as u32),
|
||||||
// "expand_right_symbol",
|
).unwrap();
|
||||||
// color_image,
|
cctx.egui_ctx.load_texture(
|
||||||
// TextureOptions::default())
|
"options_symbol",
|
||||||
// };
|
color_image,
|
||||||
|
TextureOptions::LINEAR)
|
||||||
|
};
|
||||||
|
|
||||||
let current_dpi = (cctx.egui_ctx.pixels_per_point() * 72.0) as u32;
|
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 {
|
let (override_dpi, override_dpi_value): (bool, u32) = match settings.override_dpi {
|
||||||
@ -415,6 +418,7 @@ impl GossipUi {
|
|||||||
about: crate::about::about(),
|
about: crate::about::about(),
|
||||||
icon: icon_texture_handle,
|
icon: icon_texture_handle,
|
||||||
placeholder_avatar: placeholder_avatar_texture_handle,
|
placeholder_avatar: placeholder_avatar_texture_handle,
|
||||||
|
options_symbol,
|
||||||
settings,
|
settings,
|
||||||
avatars: HashMap::new(),
|
avatars: HashMap::new(),
|
||||||
images: HashMap::new(),
|
images: HashMap::new(),
|
||||||
|
@ -53,7 +53,9 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
|||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
for relay in relays {
|
for relay in relays {
|
||||||
let mut widget =
|
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)
|
if let Some(ref assignment) = GLOBALS.relay_picker.get_relay_assignment(&relay.url)
|
||||||
{
|
{
|
||||||
widget = widget.user_count(assignment.pubkeys.len());
|
widget = widget.user_count(assignment.pubkeys.len());
|
||||||
|
@ -68,7 +68,10 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
|||||||
})
|
})
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
for relay in relays {
|
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) =
|
if let Some(ref assignment) =
|
||||||
GLOBALS.relay_picker.get_relay_assignment(&relay.url)
|
GLOBALS.relay_picker.get_relay_assignment(&relay.url)
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ pub struct RelayEntry<'a> {
|
|||||||
stroke: Option<Stroke>,
|
stroke: Option<Stroke>,
|
||||||
accent: Option<Color32>,
|
accent: Option<Color32>,
|
||||||
highlight: Option<Color32>,
|
highlight: Option<Color32>,
|
||||||
|
option_symbol: Option<&'a TextureHandle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RelayEntry<'a> {
|
impl<'a> RelayEntry<'a> {
|
||||||
@ -55,6 +56,7 @@ impl<'a> RelayEntry<'a> {
|
|||||||
stroke: None,
|
stroke: None,
|
||||||
accent: None,
|
accent: None,
|
||||||
highlight: None,
|
highlight: None,
|
||||||
|
option_symbol: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +89,11 @@ impl<'a> RelayEntry<'a> {
|
|||||||
self.highlight = Some(highlight);
|
self.highlight = Some(highlight);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn option_symbol(mut self, option_symbol: &'a TextureHandle ) -> Self {
|
||||||
|
self.option_symbol = Some(option_symbol);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RelayEntry<'a> {
|
impl<'a> RelayEntry<'a> {
|
||||||
@ -140,6 +147,7 @@ impl<'a> RelayEntry<'a> {
|
|||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
// TODO go to edit mode
|
// TODO go to edit mode
|
||||||
}
|
}
|
||||||
|
response.on_hover_cursor(CursorIcon::PointingHand);
|
||||||
draw_text_galley_at(ui, pos, galley, Some(color), Some(stroke));
|
draw_text_galley_at(ui, pos, galley, Some(color), Some(stroke));
|
||||||
} else {
|
} else {
|
||||||
let pos = rect.right_top() + vec2(-BTN_SIZE - TEXT_RIGHT, 10.0 + MARGIN_TOP);
|
let pos = rect.right_top() + vec2(-BTN_SIZE - TEXT_RIGHT, 10.0 + MARGIN_TOP);
|
||||||
@ -151,8 +159,15 @@ impl<'a> RelayEntry<'a> {
|
|||||||
} else {
|
} else {
|
||||||
ui.visuals().text_color()
|
ui.visuals().text_color()
|
||||||
};
|
};
|
||||||
let text = RichText::new("\u{2699}").size(20.0);
|
response.on_hover_cursor(CursorIcon::PointingHand);
|
||||||
draw_text_at(ui, pos, text.into(), Align::LEFT, Some(color), None);
|
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))
|
RichText::new(format!("Following: {}", count))
|
||||||
} else {
|
} else {
|
||||||
active = false;
|
active = false;
|
||||||
RichText::new("Following: -")
|
RichText::new("Following: ---")
|
||||||
};
|
};
|
||||||
let (galley, response) = allocate_text_at(ui, pos, text.into());
|
let (galley, response) = allocate_text_at(ui, pos, text.into());
|
||||||
let (color, stroke) = if !active {
|
let (color, stroke) = if !active {
|
||||||
@ -198,6 +213,7 @@ impl<'a> RelayEntry<'a> {
|
|||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
// TODO go to following page for this relay?
|
// 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));
|
draw_text_galley_at(ui, pos, galley, Some(color), Some(stroke));
|
||||||
|
|
||||||
// ---- Last event ----
|
// ---- Last event ----
|
||||||
|
Loading…
Reference in New Issue
Block a user