clippy and fmt

This commit is contained in:
Mike Dilger 2023-02-28 12:57:00 +13:00
parent 874a0a85c8
commit 386b10150d
6 changed files with 163 additions and 124 deletions

View File

@ -247,8 +247,7 @@ impl Settings {
// Save theme name
if let Some(ref name) = self.theme {
let mut stmt =
db.prepare("REPLACE INTO SETTINGS (key, value) VALUES ('theme', ?)")?;
let mut stmt = db.prepare("REPLACE INTO SETTINGS (key, value) VALUES ('theme', ?)")?;
stmt.execute((name,))?;
} else {
// Otherwise delete any such setting

View File

@ -124,23 +124,24 @@ fn render_a_feed(
y: app.current_scroll_offset * 2.0, // double speed
})
.show(ui, |ui| {
Frame::none().fill(super::theme::current_theme().feed_scroll_fill())
Frame::none()
.fill(super::theme::current_theme().feed_scroll_fill())
.show(ui, |ui| {
for id in feed.iter() {
render_post_maybe_fake(
app,
ctx,
frame,
ui,
FeedPostParams {
id: *id,
indent: 0,
as_reply_to: false,
threaded,
},
);
}
});
for id in feed.iter() {
render_post_maybe_fake(
app,
ctx,
frame,
ui,
FeedPostParams {
id: *id,
indent: 0,
as_reply_to: false,
threaded,
},
);
}
});
});
}
@ -282,41 +283,41 @@ fn render_post_actual(
let theme = super::theme::current_theme();
let inner_response = Frame::none()
.inner_margin( theme.feed_frame_inner_margin() )
.outer_margin( theme.feed_frame_outer_margin() )
.rounding( theme.feed_frame_rounding() )
.shadow( theme.feed_frame_shadow() )
.fill( theme.feed_frame_fill(is_new, is_main_event) )
.stroke( theme.feed_frame_stroke(is_new, is_main_event) )
.show(ui, |ui| {
if is_main_event {
thin_red_separator(ui);
}
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
// Indents first (if threaded)
if threaded {
let space = 100.0 * (10.0 - (1000.0 / (indent as f32 + 100.0)));
ui.add_space(space);
if indent > 0 {
ui.label(RichText::new(format!("{}>", indent)).italics().weak());
}
.inner_margin(theme.feed_frame_inner_margin())
.outer_margin(theme.feed_frame_outer_margin())
.rounding(theme.feed_frame_rounding())
.shadow(theme.feed_frame_shadow())
.fill(theme.feed_frame_fill(is_new, is_main_event))
.stroke(theme.feed_frame_stroke(is_new, is_main_event))
.show(ui, |ui| {
if is_main_event {
thin_red_separator(ui);
}
if person.muted > 0 {
ui.label(RichText::new("MUTED POST").monospace().italics());
} else {
render_post_inner(app, ctx, ui, event, person, is_main_event, as_reply_to);
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
// Indents first (if threaded)
if threaded {
let space = 100.0 * (10.0 - (1000.0 / (indent as f32 + 100.0)));
ui.add_space(space);
if indent > 0 {
ui.label(RichText::new(format!("{}>", indent)).italics().weak());
}
}
if person.muted > 0 {
ui.label(RichText::new("MUTED POST").monospace().italics());
} else {
render_post_inner(app, ctx, ui, event, person, is_main_event, as_reply_to);
}
});
if is_main_event {
thin_red_separator(ui);
}
});
if is_main_event {
thin_red_separator(ui);
}
});
// Mark post as viewed if hovered AND we are not scrolling
if inner_response.response.hovered() && app.current_scroll_offset == 0.0 {
app.viewed.insert(id);
@ -326,7 +327,10 @@ fn render_post_actual(
let bottom = ui.next_widget_position();
app.height.insert(id, bottom.y - top.y);
thin_separator(ui, super::theme::current_theme().feed_post_separator_stroke() );
thin_separator(
ui,
super::theme::current_theme().feed_post_separator_stroke(),
);
if threaded && !as_reply_to {
let replies = Globals::get_replies_sync(id);
@ -630,10 +634,13 @@ fn render_post_inner(
if app.settings.reactions {
let default_reaction_icon = match self_already_reacted {
true => "",
false => ""
false => "",
};
if ui
.add(Label::new(RichText::new(default_reaction_icon).size(20.0)).sense(Sense::click()))
.add(
Label::new(RichText::new(default_reaction_icon).size(20.0))
.sense(Sense::click()),
)
.clicked()
{
let _ = GLOBALS
@ -658,14 +665,26 @@ fn render_post_inner(
}
fn thin_red_separator(ui: &mut Ui) {
thin_separator(ui, Stroke { width: 1.0, color: Color32::from_rgb(160, 0, 0) } );
thin_separator(
ui,
Stroke {
width: 1.0,
color: Color32::from_rgb(160, 0, 0),
},
);
}
fn thin_blue_separator(ui: &mut Ui) {
thin_separator(ui, Stroke { width: 1.0, color: Color32::from_rgb(0, 0, 160) } );
thin_separator(
ui,
Stroke {
width: 1.0,
color: Color32::from_rgb(0, 0, 160),
},
);
}
fn thin_separator(ui: &mut Ui, stroke: Stroke ) {
fn thin_separator(ui: &mut Ui, stroke: Stroke) {
let mut style = ui.style_mut();
style.visuals.widgets.noninteractive.bg_stroke = stroke;
ui.add(Separator::default().spacing(0.0));

View File

@ -1,4 +1,4 @@
use super::{GossipUi, theme};
use super::{theme, GossipUi};
use crate::comms::ToOverlordMessage;
use crate::GLOBALS;
use eframe::egui::{self, TextBuffer};

View File

@ -4,13 +4,13 @@ use crate::tags::HighlightType;
use super::Theme;
use eframe::egui;
use eframe::egui::style::Selection;
use eframe::egui::style::WidgetVisuals;
use eframe::egui::style::Widgets;
use eframe::egui::FontDefinitions;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Visuals;
use eframe::egui::style::Selection;
use eframe::egui::style::WidgetVisuals;
use eframe::egui::style::Widgets;
use eframe::epaint::Color32;
use eframe::epaint::FontFamily;
use eframe::epaint::FontId;
@ -18,28 +18,25 @@ use eframe::epaint::Rounding;
use eframe::epaint::Shadow;
use eframe::epaint::Stroke;
#[derive(Default)]
pub(crate) struct Gossip {
dark_mode: bool,
}
impl Default for Gossip {
fn default() -> Self {
Self { dark_mode: false }
}
}
impl Theme for Gossip {
fn dark_mode(&mut self, dark_mode: bool) {
self.dark_mode = dark_mode;
}
fn is_dark_mode(&self) -> bool {
return self.dark_mode
self.dark_mode
}
fn name(&self) -> &'static str {
return "Gossip Default"
"Gossip Default"
}
fn make_copy(&self) -> std::sync::Arc<dyn Theme> {
std::sync::Arc::new( Self{ dark_mode: self.dark_mode } )
std::sync::Arc::new(Self {
dark_mode: self.dark_mode,
})
}
fn get_style(&self) -> eframe::egui::Style {
let mut style = egui::Style::default();
@ -267,7 +264,7 @@ impl Theme for Gossip {
collapsing_header_frame: false,
};
}
return style
style
}
fn font_definitions(&self) -> FontDefinitions {
@ -371,12 +368,22 @@ impl Theme for Gossip {
Color32::WHITE
}
}
fn feed_post_separator_stroke(&self) -> eframe::egui::Stroke { eframe::egui::Stroke::default() }
fn feed_frame_inner_margin(&self) -> eframe::egui::Margin { eframe::egui::Margin::default() }
fn feed_frame_outer_margin(&self) -> eframe::egui::Margin { eframe::egui::Margin::default() }
fn feed_frame_rounding(&self) -> eframe::egui::Rounding { eframe::egui::Rounding::default() }
fn feed_frame_shadow(&self) -> eframe::epaint::Shadow { eframe::epaint::Shadow::default() }
fn feed_frame_fill(&self, is_new: bool, _:bool) -> eframe::egui::Color32 {
fn feed_post_separator_stroke(&self) -> eframe::egui::Stroke {
eframe::egui::Stroke::default()
}
fn feed_frame_inner_margin(&self) -> eframe::egui::Margin {
eframe::egui::Margin::default()
}
fn feed_frame_outer_margin(&self) -> eframe::egui::Margin {
eframe::egui::Margin::default()
}
fn feed_frame_rounding(&self) -> eframe::egui::Rounding {
eframe::egui::Rounding::default()
}
fn feed_frame_shadow(&self) -> eframe::epaint::Shadow {
eframe::epaint::Shadow::default()
}
fn feed_frame_fill(&self, is_new: bool, _: bool) -> eframe::egui::Color32 {
if is_new {
if self.dark_mode {
Color32::from_rgb(60, 0, 0)
@ -391,5 +398,7 @@ impl Theme for Gossip {
}
}
}
fn feed_frame_stroke(&self, _:bool, _:bool ) -> eframe::egui::Stroke { Stroke::NONE }
fn feed_frame_stroke(&self, _: bool, _: bool) -> eframe::egui::Stroke {
Stroke::NONE
}
}

View File

@ -1,15 +1,15 @@
use eframe::egui::{TextStyle, TextFormat, FontTweak, FontData, FontDefinitions};
use eframe::epaint::{FontId, FontFamily};
use std::collections::BTreeMap;
use eframe::egui::{FontData, FontDefinitions, FontTweak, TextFormat, TextStyle};
use eframe::epaint::{FontFamily, FontId};
use lazy_static::lazy_static;
use std::sync::{ Mutex, Arc, RwLock };
use std::collections::BTreeMap;
use std::sync::{Arc, Mutex, RwLock};
use crate::tags::HighlightType;
mod gossip;
mod roundy;
pub(crate) trait Theme : Send + Sync {
pub(crate) trait Theme: Send + Sync {
// user facing name
fn name(&self) -> &'static str;
@ -28,11 +28,11 @@ pub(crate) trait Theme : Send + Sync {
fn feed_scroll_fill(&self) -> eframe::egui::Color32;
fn feed_post_separator_stroke(&self) -> eframe::egui::Stroke;
fn feed_frame_inner_margin(&self) -> eframe::egui::Margin;
fn feed_frame_outer_margin(&self) -> eframe::egui::Margin;
fn feed_frame_rounding(&self) -> eframe::egui::Rounding;
fn feed_frame_shadow(&self) -> eframe::epaint::Shadow;
fn feed_frame_fill(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Color32;
fn feed_frame_stroke(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Stroke;
fn feed_frame_outer_margin(&self) -> eframe::egui::Margin;
fn feed_frame_rounding(&self) -> eframe::egui::Rounding;
fn feed_frame_shadow(&self) -> eframe::epaint::Shadow;
fn feed_frame_fill(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Color32;
fn feed_frame_stroke(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Stroke;
}
struct ThemePicker {
@ -51,35 +51,34 @@ impl ThemePicker {
fn set_dark_mode(&mut self, dark_mode: bool) {
self.current_theme.write().unwrap().dark_mode(dark_mode);
}
fn pick(&mut self, name: &Option<String> ) {
fn pick(&mut self, name: &Option<String>) {
match name {
Some(name) if name.as_str() == self.roundy.read().unwrap().name() => {
self.current_theme = self.roundy.clone();
},
}
_ => {
self.current_theme = self.gossip_theme.clone();
},
}
}
}
fn current_theme(&self) -> Arc<dyn Theme> {
return self.current_theme.read().unwrap().make_copy()
return self.current_theme.read().unwrap().make_copy();
}
}
impl Default for ThemePicker {
fn default() -> Self {
let gossip_theme_rc = Arc::new( RwLock::new( gossip::Gossip::default() ));
let me = ThemePicker {
let gossip_theme_rc = Arc::new(RwLock::new(gossip::Gossip::default()));
ThemePicker {
gossip_theme: gossip_theme_rc.clone(),
roundy: Arc::new( RwLock::new( roundy::Roundy::default() )),
roundy: Arc::new(RwLock::new(roundy::Roundy::default())),
current_theme: gossip_theme_rc,
};
return me
}
}
}
lazy_static! {
static ref CURRENT_THEME_INSTANCE: Mutex<ThemePicker> = Mutex::new( ThemePicker::default() );
static ref CURRENT_THEME_INSTANCE: Mutex<ThemePicker> = Mutex::new(ThemePicker::default());
}
pub(crate) fn list_themes() -> Vec<&'static str> {
@ -87,9 +86,9 @@ pub(crate) fn list_themes() -> Vec<&'static str> {
}
/// Set dark_mode enabled or disabled
pub(crate) fn set_dark_mode( dark_mode: bool, egui_ctx: &eframe::egui::Context ) {
pub(crate) fn set_dark_mode(dark_mode: bool, egui_ctx: &eframe::egui::Context) {
let mut theme_picker = CURRENT_THEME_INSTANCE.lock().unwrap();
theme_picker.set_dark_mode( dark_mode );
theme_picker.set_dark_mode(dark_mode);
let theme = theme_picker.current_theme();
@ -101,9 +100,13 @@ pub(crate) fn set_dark_mode( dark_mode: bool, egui_ctx: &eframe::egui::Context )
}
/// Switch between Themes preserving dark_mode selection
pub(crate) fn switch( name: &Option<String>, egui_ctx: &eframe::egui::Context ) {
let current_mode = CURRENT_THEME_INSTANCE.lock().unwrap().current_theme().is_dark_mode();
CURRENT_THEME_INSTANCE.lock().unwrap().pick( name );
pub(crate) fn switch(name: &Option<String>, egui_ctx: &eframe::egui::Context) {
let current_mode = CURRENT_THEME_INSTANCE
.lock()
.unwrap()
.current_theme()
.is_dark_mode();
CURRENT_THEME_INSTANCE.lock().unwrap().pick(name);
set_dark_mode(current_mode, egui_ctx);
}

View File

@ -4,14 +4,14 @@ use crate::tags::HighlightType;
use super::Theme;
use eframe::egui;
use eframe::egui::style::Selection;
use eframe::egui::style::WidgetVisuals;
use eframe::egui::style::Widgets;
use eframe::egui::FontDefinitions;
use eframe::egui::Margin;
use eframe::egui::TextFormat;
use eframe::egui::TextStyle;
use eframe::egui::Visuals;
use eframe::egui::style::Selection;
use eframe::egui::style::WidgetVisuals;
use eframe::egui::style::Widgets;
use eframe::epaint::Color32;
use eframe::epaint::FontFamily;
use eframe::epaint::FontId;
@ -19,28 +19,25 @@ use eframe::epaint::Rounding;
use eframe::epaint::Shadow;
use eframe::epaint::Stroke;
#[derive(Default)]
pub(crate) struct Roundy {
dark_mode: bool,
}
impl Default for Roundy {
fn default() -> Self {
Self { dark_mode: false }
}
}
impl Theme for Roundy {
fn dark_mode(&mut self, dark_mode: bool) {
self.dark_mode = dark_mode;
}
fn is_dark_mode(&self) -> bool {
return self.dark_mode
self.dark_mode
}
fn name(&self) -> &'static str {
return "Roundy"
"Roundy"
}
fn make_copy(&self) -> std::sync::Arc<dyn Theme> {
std::sync::Arc::new( Self{ dark_mode: self.dark_mode } )
std::sync::Arc::new(Self {
dark_mode: self.dark_mode,
})
}
fn get_style(&self) -> eframe::egui::Style {
let mut style = egui::Style::default();
@ -271,7 +268,7 @@ impl Theme for Roundy {
collapsing_header_frame: false,
};
}
return style
style
}
fn font_definitions(&self) -> FontDefinitions {
@ -368,13 +365,25 @@ impl Theme for Roundy {
}
// feed styling
fn feed_scroll_fill(&self) -> eframe::egui::Color32 { Color32::TRANSPARENT }
fn feed_post_separator_stroke(&self) -> eframe::egui::Stroke { eframe::egui::Stroke::NONE }
fn feed_frame_inner_margin(&self) -> eframe::egui::Margin { eframe::egui::Margin::symmetric(10.0,5.0) }
fn feed_frame_outer_margin(&self) -> eframe::egui::Margin { eframe::egui::Margin::default() }
fn feed_frame_rounding(&self) -> eframe::egui::Rounding { eframe::egui::Rounding::same( 7.0 ) }
fn feed_frame_shadow(&self) -> eframe::epaint::Shadow { eframe::epaint::Shadow::default() }
fn feed_frame_fill(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Color32 {
fn feed_scroll_fill(&self) -> eframe::egui::Color32 {
Color32::TRANSPARENT
}
fn feed_post_separator_stroke(&self) -> eframe::egui::Stroke {
eframe::egui::Stroke::NONE
}
fn feed_frame_inner_margin(&self) -> eframe::egui::Margin {
eframe::egui::Margin::symmetric(10.0, 5.0)
}
fn feed_frame_outer_margin(&self) -> eframe::egui::Margin {
eframe::egui::Margin::default()
}
fn feed_frame_rounding(&self) -> eframe::egui::Rounding {
eframe::egui::Rounding::same(7.0)
}
fn feed_frame_shadow(&self) -> eframe::epaint::Shadow {
eframe::epaint::Shadow::default()
}
fn feed_frame_fill(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Color32 {
if is_new && !is_main_event {
if self.dark_mode {
Color32::from_rgb(45, 45, 46)
@ -389,14 +398,14 @@ impl Theme for Roundy {
}
}
}
fn feed_frame_stroke(&self, is_new: bool, is_main_event: bool ) -> eframe::egui::Stroke {
fn feed_frame_stroke(&self, is_new: bool, is_main_event: bool) -> eframe::egui::Stroke {
if is_main_event {
Stroke::new( 1.0, Color32::from_rgb(0x99, 0x66, 0x66) )
Stroke::new(1.0, Color32::from_rgb(0x99, 0x66, 0x66))
} else {
if is_new {
Stroke::new( 1.0, Color32::from_gray(0x99) )
Stroke::new(1.0, Color32::from_gray(0x99))
} else {
Stroke::new( 1.0, Color32::from_gray(0x66) )
Stroke::new(1.0, Color32::from_gray(0x66))
}
}
}