mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 11:43:43 +00:00
Max FPS setting, and repaint at least once per second
This commit is contained in:
parent
352b674a60
commit
669bcde3f4
@ -12,6 +12,7 @@ pub const DEFAULT_VIEW_POSTS_REFERRING_TO: bool = false;
|
||||
pub const DEFAULT_VIEW_THREADED: bool = true;
|
||||
pub const DEFAULT_NUM_RELAYS_PER_PERSON: u8 = 2;
|
||||
pub const DEFAULT_MAX_RELAYS: u8 = 15;
|
||||
pub const DEFAULT_MAX_FPS: u32 = 60;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Settings {
|
||||
@ -25,6 +26,7 @@ pub struct Settings {
|
||||
pub max_relays: u8,
|
||||
pub public_key: Option<PublicKey>,
|
||||
pub encrypted_private_key: Option<EncryptedPrivateKey>,
|
||||
pub max_fps: u32,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@ -40,6 +42,7 @@ impl Default for Settings {
|
||||
max_relays: DEFAULT_MAX_RELAYS,
|
||||
public_key: None,
|
||||
encrypted_private_key: None,
|
||||
max_fps: DEFAULT_MAX_FPS,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,6 +92,7 @@ impl Settings {
|
||||
}
|
||||
}
|
||||
}
|
||||
"max_fps" => settings.max_fps = row.1.parse::<u32>().unwrap_or(DEFAULT_MAX_FPS),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -105,7 +109,7 @@ impl Settings {
|
||||
('feed_chunk', ?),('overlap', ?),('autofollow', ?),\
|
||||
('view_posts_referred_to', ?),('view_posts_referring_to', ?),\
|
||||
('view_threaded', ?),('num_relays_per_person', ?), \
|
||||
('max_relays', ?)",
|
||||
('max_relays', ?),('max_fps', ?)",
|
||||
)?;
|
||||
stmt.execute((
|
||||
self.feed_chunk,
|
||||
@ -124,6 +128,7 @@ impl Settings {
|
||||
if self.view_threaded { "1" } else { "0" },
|
||||
self.num_relays_per_person,
|
||||
self.max_relays,
|
||||
self.max_fps,
|
||||
))?;
|
||||
|
||||
// Save private key identity
|
||||
|
@ -15,6 +15,7 @@ use crate::settings::Settings;
|
||||
use eframe::{egui, IconData, Theme};
|
||||
use egui::{ColorImage, Context, ImageData, TextureHandle, TextureOptions};
|
||||
use nostr_types::{PublicKey, PublicKeyHex};
|
||||
use std::time::{Duration, Instant};
|
||||
use zeroize::Zeroize;
|
||||
|
||||
pub fn run() -> Result<(), Error> {
|
||||
@ -59,6 +60,7 @@ enum Page {
|
||||
}
|
||||
|
||||
struct GossipUi {
|
||||
next_frame: Instant,
|
||||
page: Page,
|
||||
about: About,
|
||||
icon: TextureHandle,
|
||||
@ -123,6 +125,7 @@ impl GossipUi {
|
||||
let settings = GLOBALS.settings.blocking_read().clone();
|
||||
|
||||
GossipUi {
|
||||
next_frame: Instant::now(),
|
||||
page: Page::Feed,
|
||||
about: crate::about::about(),
|
||||
icon: icon_texture_handle,
|
||||
@ -142,6 +145,13 @@ impl GossipUi {
|
||||
|
||||
impl eframe::App for GossipUi {
|
||||
fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
|
||||
// Wait until the next frame
|
||||
std::thread::sleep(self.next_frame - Instant::now());
|
||||
self.next_frame += Duration::from_secs_f32(1.0 / self.settings.max_fps as f32);
|
||||
|
||||
// Redraw at least once per second
|
||||
ctx.request_repaint_after(Duration::from_secs(1));
|
||||
|
||||
if GLOBALS
|
||||
.shutting_down
|
||||
.load(std::sync::atomic::Ordering::Relaxed)
|
||||
|
@ -77,7 +77,7 @@ pub(super) fn update(
|
||||
.on_hover_text("Definately not recommended. In fact we may remove this soon.");
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.heading("Style");
|
||||
ui.heading("User Interface");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Switch to");
|
||||
@ -102,6 +102,15 @@ pub(super) fn update(
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Maximum FPS: ")
|
||||
.on_hover_text(
|
||||
"The UI redraws every frame. By limiting the maximum FPS you can reduce load on your CPU. Takes effect immediately.",
|
||||
);
|
||||
ui.add(Slider::new(&mut app.settings.max_fps, 10..=60).text("Frames per second"));
|
||||
});
|
||||
|
||||
ui.add_space(32.0);
|
||||
ui.with_layout(Layout::top_down(Align::Center), |ui| {
|
||||
if ui.button("SAVE CHANGES").clicked() {
|
||||
|
Loading…
Reference in New Issue
Block a user