mirror of
https://github.com/damus-io/notedeck.git
synced 2024-09-19 13:16:34 +00:00
update to latest egui
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
d38fcf80b9
commit
95c836b375
@ -1,7 +1,7 @@
|
|||||||
{ pkgs ? import <nixpkgs> {}, use_android ? true }:
|
{ pkgs ? import <nixpkgs> {}, use_android ? true }:
|
||||||
with pkgs;
|
with pkgs;
|
||||||
let
|
let
|
||||||
x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers ];
|
x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ];
|
||||||
ndk-version = "24.0.8215888";
|
ndk-version = "24.0.8215888";
|
||||||
#ndk-version = "21.0.6113669";
|
#ndk-version = "21.0.6113669";
|
||||||
|
|
||||||
|
26
src/app.rs
26
src/app.rs
@ -7,7 +7,7 @@ use crate::ui::padding;
|
|||||||
use crate::Result;
|
use crate::Result;
|
||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::widgets::Spinner;
|
use egui::widgets::Spinner;
|
||||||
use egui::{Context, Frame, Margin, TextureHandle, TextureId};
|
use egui::{Context, Frame, ImageSource, Margin, TextureHandle, TextureId};
|
||||||
use egui_extras::Size;
|
use egui_extras::Size;
|
||||||
use enostr::{ClientMessage, EventId, Filter, Profile, Pubkey, RelayEvent, RelayMessage};
|
use enostr::{ClientMessage, EventId, Filter, Profile, Pubkey, RelayEvent, RelayMessage};
|
||||||
use poll_promise::Promise;
|
use poll_promise::Promise;
|
||||||
@ -94,7 +94,11 @@ fn relay_setup(pool: &mut RelayPool, ctx: &egui::Context) {
|
|||||||
|
|
||||||
fn send_initial_filters(pool: &mut RelayPool, relay_url: &str) {
|
fn send_initial_filters(pool: &mut RelayPool, relay_url: &str) {
|
||||||
let filter = Filter::new().limit(100).kinds(vec![1, 42]).pubkeys(
|
let filter = Filter::new().limit(100).kinds(vec![1, 42]).pubkeys(
|
||||||
["32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".into()].into(),
|
[
|
||||||
|
Pubkey::from_hex("32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245")
|
||||||
|
.unwrap(),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let subid = "initial";
|
let subid = "initial";
|
||||||
@ -109,7 +113,7 @@ fn send_initial_filters(pool: &mut RelayPool, relay_url: &str) {
|
|||||||
|
|
||||||
fn try_process_event(damus: &mut Damus, ctx: &egui::Context) {
|
fn try_process_event(damus: &mut Damus, ctx: &egui::Context) {
|
||||||
let amount = 0.2;
|
let amount = 0.2;
|
||||||
if ctx.input(|i| i.key_pressed(egui::Key::PlusEquals)) {
|
if ctx.input(|i| i.key_pressed(egui::Key::Plus)) {
|
||||||
ctx.set_pixels_per_point(ctx.pixels_per_point() + amount);
|
ctx.set_pixels_per_point(ctx.pixels_per_point() + amount);
|
||||||
} else if ctx.input(|i| i.key_pressed(egui::Key::Minus)) {
|
} else if ctx.input(|i| i.key_pressed(egui::Key::Minus)) {
|
||||||
ctx.set_pixels_per_point(ctx.pixels_per_point() - amount);
|
ctx.set_pixels_per_point(ctx.pixels_per_point() - amount);
|
||||||
@ -321,22 +325,22 @@ fn render_pfp(ui: &mut egui::Ui, img_cache: &mut ImageCache, url: &str) {
|
|||||||
ui.label("❌");
|
ui.label("❌");
|
||||||
}
|
}
|
||||||
Some(Ok(img)) => {
|
Some(Ok(img)) => {
|
||||||
pfp_image(ui, img.into(), pfp_size);
|
pfp_image(ui, img, pfp_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Ok(img)) => {
|
Some(Ok(img)) => {
|
||||||
pfp_image(ui, img.into(), pfp_size);
|
pfp_image(ui, img, pfp_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pfp_image(ui: &mut egui::Ui, img: TextureId, size: f32) -> egui::Response {
|
fn pfp_image<'a>(ui: &mut egui::Ui, img: impl Into<ImageSource<'a>>, size: f32) -> egui::Response {
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|
||||||
//img.show_max_size(ui, egui::vec2(size, size))
|
//img.show_max_size(ui, egui::vec2(size, size))
|
||||||
ui.image(img, egui::vec2(size, size))
|
ui.image(img)
|
||||||
//.with_options()
|
//.with_options()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,8 +651,8 @@ fn add_test_events(damus: &mut Damus) {
|
|||||||
// For inspiration and more examples, go to https://emilk.github.io/egui
|
// For inspiration and more examples, go to https://emilk.github.io/egui
|
||||||
|
|
||||||
let test_event = Event {
|
let test_event = Event {
|
||||||
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string().into(),
|
id: EventId::from_hex("6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb").unwrap(),
|
||||||
pubkey: "f0a6ff7f70b872de6d82c8daec692a433fd23b6a49f25923c6f034df715cdeec".to_string().into(),
|
pubkey: Pubkey::from_hex("f0a6ff7f70b872de6d82c8daec692a433fd23b6a49f25923c6f034df715cdeec").unwrap(),
|
||||||
created_at: 1667781968,
|
created_at: 1667781968,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
@ -657,8 +661,8 @@ fn add_test_events(damus: &mut Damus) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let test_event2 = Event {
|
let test_event2 = Event {
|
||||||
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string().into(),
|
id: EventId::from_hex("6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb").unwrap(),
|
||||||
pubkey: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".to_string().into(),
|
pubkey: Pubkey::from_hex("32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245").unwrap(),
|
||||||
created_at: 1667781968,
|
created_at: 1667781968,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
|
@ -42,85 +42,5 @@ impl FrameHistory {
|
|||||||
Does not include GPU usage, nor overhead for sending data to GPU.",
|
Does not include GPU usage, nor overhead for sending data to GPU.",
|
||||||
);
|
);
|
||||||
egui::warn_if_debug_build(ui);
|
egui::warn_if_debug_build(ui);
|
||||||
|
|
||||||
if !cfg!(target_arch = "wasm32") {
|
|
||||||
egui::CollapsingHeader::new("📊 CPU usage history")
|
|
||||||
.default_open(false)
|
|
||||||
.show(ui, |ui| {
|
|
||||||
self.graph(ui);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn graph(&mut self, ui: &mut egui::Ui) -> egui::Response {
|
|
||||||
use egui::*;
|
|
||||||
|
|
||||||
ui.label("egui CPU usage history");
|
|
||||||
|
|
||||||
let history = &self.frame_times;
|
|
||||||
|
|
||||||
// TODO(emilk): we should not use `slider_width` as default graph width.
|
|
||||||
let height = ui.spacing().slider_width;
|
|
||||||
let size = vec2(ui.available_size_before_wrap().x, height);
|
|
||||||
let (rect, response) = ui.allocate_at_least(size, Sense::hover());
|
|
||||||
let style = ui.style().noninteractive();
|
|
||||||
|
|
||||||
let graph_top_cpu_usage = 0.010;
|
|
||||||
let graph_rect = Rect::from_x_y_ranges(history.max_age()..=0.0, graph_top_cpu_usage..=0.0);
|
|
||||||
let to_screen = emath::RectTransform::from_to(graph_rect, rect);
|
|
||||||
|
|
||||||
let mut shapes = Vec::with_capacity(3 + 2 * history.len());
|
|
||||||
shapes.push(Shape::Rect(epaint::RectShape {
|
|
||||||
rect,
|
|
||||||
rounding: style.rounding,
|
|
||||||
fill: ui.visuals().extreme_bg_color,
|
|
||||||
stroke: ui.style().noninteractive().bg_stroke,
|
|
||||||
}));
|
|
||||||
|
|
||||||
let rect = rect.shrink(4.0);
|
|
||||||
let color = ui.visuals().text_color();
|
|
||||||
let line_stroke = Stroke::new(1.0, color);
|
|
||||||
|
|
||||||
if let Some(pointer_pos) = response.hover_pos() {
|
|
||||||
let y = pointer_pos.y;
|
|
||||||
shapes.push(Shape::line_segment(
|
|
||||||
[pos2(rect.left(), y), pos2(rect.right(), y)],
|
|
||||||
line_stroke,
|
|
||||||
));
|
|
||||||
let cpu_usage = to_screen.inverse().transform_pos(pointer_pos).y;
|
|
||||||
let text = format!("{:.1} ms", 1e3 * cpu_usage);
|
|
||||||
shapes.push(ui.fonts(|f| {
|
|
||||||
Shape::text(
|
|
||||||
f,
|
|
||||||
pos2(rect.left(), y),
|
|
||||||
egui::Align2::LEFT_BOTTOM,
|
|
||||||
text,
|
|
||||||
TextStyle::Monospace.resolve(ui.style()),
|
|
||||||
color,
|
|
||||||
)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
let circle_color = color;
|
|
||||||
let radius = 2.0;
|
|
||||||
let right_side_time = ui.input(|i| i.time); // Time at right side of screen
|
|
||||||
|
|
||||||
for (time, cpu_usage) in history.iter() {
|
|
||||||
let age = (right_side_time - time) as f32;
|
|
||||||
let pos = to_screen.transform_pos_clamped(Pos2::new(age, cpu_usage));
|
|
||||||
|
|
||||||
shapes.push(Shape::line_segment(
|
|
||||||
[pos2(pos.x, rect.bottom()), pos],
|
|
||||||
line_stroke,
|
|
||||||
));
|
|
||||||
|
|
||||||
if cpu_usage < graph_top_cpu_usage {
|
|
||||||
shapes.push(Shape::circle_filled(pos, radius, circle_color));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.painter().extend(shapes);
|
|
||||||
|
|
||||||
response
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::result::Result;
|
use crate::result::Result;
|
||||||
use egui::{Color32, ColorImage, TextureHandle};
|
use egui::{Color32, ColorImage, SizeHint, TextureHandle};
|
||||||
use egui_extras::image::FitTo;
|
|
||||||
use image::imageops::FilterType;
|
use image::imageops::FilterType;
|
||||||
use poll_promise::Promise;
|
use poll_promise::Promise;
|
||||||
|
|
||||||
@ -90,8 +89,10 @@ fn parse_img_response(response: ehttp::Response) -> Result<ColorImage> {
|
|||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_scope!("load_svg");
|
puffin::profile_scope!("load_svg");
|
||||||
|
|
||||||
let mut color_image =
|
let mut color_image = egui_extras::image::load_svg_bytes_with_size(
|
||||||
egui_extras::image::load_svg_bytes_with_size(&response.bytes, FitTo::Size(size, size))?;
|
&response.bytes,
|
||||||
|
Some(SizeHint::Size(size, size)),
|
||||||
|
)?;
|
||||||
round_image(&mut color_image);
|
round_image(&mut color_image);
|
||||||
Ok(color_image)
|
Ok(color_image)
|
||||||
} else if content_type.starts_with("image/") {
|
} else if content_type.starts_with("image/") {
|
||||||
|
Loading…
Reference in New Issue
Block a user