fonts: implement roberto's typography for notedeck
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
44
src/app.rs
44
src/app.rs
@@ -1,6 +1,6 @@
|
|||||||
use crate::abbrev;
|
use crate::abbrev;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::fonts::setup_gossip_fonts;
|
use crate::fonts::{setup_gossip_fonts, NamedFontFamily};
|
||||||
use crate::frame_history::FrameHistory;
|
use crate::frame_history::FrameHistory;
|
||||||
use crate::images::fetch_img;
|
use crate::images::fetch_img;
|
||||||
use crate::notecache::NoteCache;
|
use crate::notecache::NoteCache;
|
||||||
@@ -12,6 +12,7 @@ use egui::containers::scroll_area::ScrollBarVisibility;
|
|||||||
use egui::widgets::Spinner;
|
use egui::widgets::Spinner;
|
||||||
use egui::{
|
use egui::{
|
||||||
Color32, Context, Frame, Hyperlink, Image, Label, Margin, RichText, Style, TextureHandle,
|
Color32, Context, Frame, Hyperlink, Image, Label, Margin, RichText, Style, TextureHandle,
|
||||||
|
Visuals,
|
||||||
};
|
};
|
||||||
|
|
||||||
use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage};
|
use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage};
|
||||||
@@ -30,6 +31,7 @@ use tracing::{debug, error, info, warn};
|
|||||||
use enostr::RelayPool;
|
use enostr::RelayPool;
|
||||||
|
|
||||||
const PURPLE: Color32 = Color32::from_rgb(0xCC, 0x43, 0xC5);
|
const PURPLE: Color32 = Color32::from_rgb(0xCC, 0x43, 0xC5);
|
||||||
|
const DARK_BG: Color32 = egui::Color32::from_rgb(40, 44, 52);
|
||||||
|
|
||||||
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
|
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
|
||||||
enum UrlKey<'a> {
|
enum UrlKey<'a> {
|
||||||
@@ -329,7 +331,6 @@ fn update_damus(damus: &mut Damus, ctx: &egui::Context) {
|
|||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
setup_profiling();
|
setup_profiling();
|
||||||
|
|
||||||
setup_gossip_fonts(ctx);
|
|
||||||
damus.pool = RelayPool::new();
|
damus.pool = RelayPool::new();
|
||||||
relay_setup(&mut damus.pool, ctx);
|
relay_setup(&mut damus.pool, ctx);
|
||||||
damus.state = DamusState::Initialized;
|
damus.state = DamusState::Initialized;
|
||||||
@@ -407,6 +408,10 @@ fn process_message(damus: &mut Damus, relay: &str, msg: &RelayMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_damus(damus: &mut Damus, ctx: &Context) {
|
fn render_damus(damus: &mut Damus, ctx: &Context) {
|
||||||
|
ctx.style_mut(|style| {
|
||||||
|
set_app_style(&mut style.visuals);
|
||||||
|
});
|
||||||
|
|
||||||
if is_mobile(ctx) {
|
if is_mobile(ctx) {
|
||||||
render_damus_mobile(ctx, damus);
|
render_damus_mobile(ctx, damus);
|
||||||
} else {
|
} else {
|
||||||
@@ -436,6 +441,8 @@ impl Damus {
|
|||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
|
|
||||||
|
setup_gossip_fonts(&cc.egui_ctx);
|
||||||
|
|
||||||
cc.egui_ctx
|
cc.egui_ctx
|
||||||
.set_pixels_per_point(cc.egui_ctx.pixels_per_point() + 0.2);
|
.set_pixels_per_point(cc.egui_ctx.pixels_per_point() + 0.2);
|
||||||
|
|
||||||
@@ -531,7 +538,9 @@ fn ui_abbreviate_name(ui: &mut egui::Ui, name: &str, len: usize) {
|
|||||||
ui.strong(&name[..closest]);
|
ui.strong(&name[..closest]);
|
||||||
ui.strong("...");
|
ui.strong("...");
|
||||||
} else {
|
} else {
|
||||||
ui.strong(name);
|
ui.add(Label::new(
|
||||||
|
RichText::new(name).family(NamedFontFamily::Medium.as_family()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,7 +692,7 @@ fn render_note_contents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
BlockType::Text => {
|
BlockType::Text => {
|
||||||
ui.weak(block.as_str());
|
ui.label(block.as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
@@ -708,15 +717,12 @@ fn render_reltime(ui: &mut egui::Ui, note_cache: &mut NoteCache) {
|
|||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|
||||||
ui.add(Label::new(
|
let color = Color32::from_rgb(0x8A, 0x8A, 0x8A);
|
||||||
RichText::new("⋅")
|
ui.add(Label::new(RichText::new("⋅").size(10.0).color(color)));
|
||||||
.size(10.0)
|
|
||||||
.color(ui.visuals().weak_text_color()),
|
|
||||||
));
|
|
||||||
ui.add(Label::new(
|
ui.add(Label::new(
|
||||||
RichText::new(note_cache.reltime_str())
|
RichText::new(note_cache.reltime_str())
|
||||||
.size(10.0)
|
.size(10.0)
|
||||||
.color(ui.visuals().weak_text_color()),
|
.color(color),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,8 +820,6 @@ fn top_panel(ctx: &egui::Context) -> egui::TopBottomPanel {
|
|||||||
|
|
||||||
fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize) {
|
fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize) {
|
||||||
top_panel(ctx).show(ctx, |ui| {
|
top_panel(ctx).show(ctx, |ui| {
|
||||||
set_app_style(ui);
|
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||||
ui.visuals_mut().button_frame = false;
|
ui.visuals_mut().button_frame = false;
|
||||||
egui::widgets::global_dark_light_mode_switch(ui);
|
egui::widgets::global_dark_light_mode_switch(ui);
|
||||||
@@ -854,13 +858,15 @@ fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_app_style(ui: &mut egui::Ui) {
|
fn set_app_style(visuals: &mut Visuals) {
|
||||||
ui.visuals_mut().hyperlink_color = PURPLE;
|
visuals.hyperlink_color = PURPLE;
|
||||||
if ui.visuals().dark_mode {
|
if visuals.dark_mode {
|
||||||
ui.visuals_mut().override_text_color = Some(egui::Color32::from_rgb(250, 250, 250));
|
visuals.override_text_color = Some(egui::Color32::from_rgb(250, 250, 250));
|
||||||
ui.visuals_mut().panel_fill = egui::Color32::from_rgb(30, 30, 30);
|
visuals.panel_fill = egui::Color32::from_rgb(31, 31, 31);
|
||||||
|
//visuals.override_text_color = Some(egui::Color32::from_rgb(170, 177, 190));
|
||||||
|
//visuals.panel_fill = egui::Color32::from_rgb(40, 44, 52);
|
||||||
} else {
|
} else {
|
||||||
ui.visuals_mut().override_text_color = Some(egui::Color32::BLACK);
|
visuals.override_text_color = Some(egui::Color32::BLACK);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,7 +911,6 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
if app.n_panels == 1 {
|
if app.n_panels == 1 {
|
||||||
let panel_width = ctx.screen_rect().width();
|
let panel_width = ctx.screen_rect().width();
|
||||||
main_panel(&ctx.style()).show(ctx, |ui| {
|
main_panel(&ctx.style()).show(ctx, |ui| {
|
||||||
set_app_style(ui);
|
|
||||||
timeline_panel(ui, panel_width, 0, |ui| {
|
timeline_panel(ui, panel_width, 0, |ui| {
|
||||||
//postbox(ui, app);
|
//postbox(ui, app);
|
||||||
timeline_view(ui, app, 0);
|
timeline_view(ui, app, 0);
|
||||||
@@ -916,7 +921,6 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main_panel(&ctx.style()).show(ctx, |ui| {
|
main_panel(&ctx.style()).show(ctx, |ui| {
|
||||||
set_app_style(ui);
|
|
||||||
egui::ScrollArea::horizontal()
|
egui::ScrollArea::horizontal()
|
||||||
.auto_shrink([false; 2])
|
.auto_shrink([false; 2])
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
|
|||||||
91
src/fonts.rs
91
src/fonts.rs
@@ -1,5 +1,23 @@
|
|||||||
use egui::{FontData, FontDefinitions, FontFamily, FontTweak};
|
use egui::{FontData, FontDefinitions, FontTweak};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
|
pub enum NamedFontFamily {
|
||||||
|
Medium,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NamedFontFamily {
|
||||||
|
pub fn as_str(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
//Self::Bold => "bold",
|
||||||
|
Self::Medium => "medium",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_family(self) -> egui::FontFamily {
|
||||||
|
egui::FontFamily::Name(self.as_str().into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setup_fonts(ctx: &egui::Context) {
|
pub fn setup_fonts(ctx: &egui::Context) {
|
||||||
let mut fonts = FontDefinitions::default();
|
let mut fonts = FontDefinitions::default();
|
||||||
@@ -18,7 +36,7 @@ pub fn setup_fonts(ctx: &egui::Context) {
|
|||||||
// Put my font first (highest priority):
|
// Put my font first (highest priority):
|
||||||
fonts
|
fonts
|
||||||
.families
|
.families
|
||||||
.get_mut(&FontFamily::Proportional)
|
.get_mut(&egui::FontFamily::Proportional)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert(0, our_font);
|
.insert(0, our_font);
|
||||||
|
|
||||||
@@ -35,6 +53,39 @@ pub fn setup_gossip_fonts(ctx: &egui::Context) {
|
|||||||
let mut font_data: BTreeMap<String, FontData> = BTreeMap::new();
|
let mut font_data: BTreeMap<String, FontData> = BTreeMap::new();
|
||||||
let mut families = BTreeMap::new();
|
let mut families = BTreeMap::new();
|
||||||
|
|
||||||
|
font_data.insert(
|
||||||
|
"Onest".to_owned(),
|
||||||
|
FontData::from_static(include_bytes!(
|
||||||
|
"../assets/fonts/onest/OnestRegular1602-hint.ttf"
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
font_data.insert(
|
||||||
|
"OnestMedium".to_owned(),
|
||||||
|
FontData::from_static(include_bytes!(
|
||||||
|
"../assets/fonts/onest/OnestMedium1602-hint.ttf"
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
font_data.insert(
|
||||||
|
"DejaVuSans".to_owned(),
|
||||||
|
FontData::from_static(include_bytes!("../assets/fonts/DejaVuSansSansEmoji.ttf")),
|
||||||
|
);
|
||||||
|
/*
|
||||||
|
font_data.insert(
|
||||||
|
"OnestBold".to_owned(),
|
||||||
|
FontData::from_static(include_bytes!(
|
||||||
|
"../assets/fonts/onest/OnestBold1602-hint.ttf"
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
font_data.insert(
|
||||||
|
"DejaVuSansBold".to_owned(),
|
||||||
|
FontData::from_static(include_bytes!(
|
||||||
|
"../assets/fonts/DejaVuSans-Bold-SansEmoji.ttf"
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
font_data.insert(
|
font_data.insert(
|
||||||
"DejaVuSans".to_owned(),
|
"DejaVuSans".to_owned(),
|
||||||
FontData::from_static(include_bytes!("../assets/fonts/DejaVuSansSansEmoji.ttf")),
|
FontData::from_static(include_bytes!("../assets/fonts/DejaVuSansSansEmoji.ttf")),
|
||||||
@@ -45,11 +96,7 @@ pub fn setup_gossip_fonts(ctx: &egui::Context) {
|
|||||||
"../assets/fonts/DejaVuSans-Bold-SansEmoji.ttf"
|
"../assets/fonts/DejaVuSans-Bold-SansEmoji.ttf"
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
font_data.insert(
|
|
||||||
"NotoSansCJK".to_owned(),
|
|
||||||
FontData::from_static(include_bytes!("../assets/fonts/NotoSansCJK-Regular.ttc")),
|
|
||||||
);
|
|
||||||
|
|
||||||
font_data.insert(
|
font_data.insert(
|
||||||
"Inconsolata".to_owned(),
|
"Inconsolata".to_owned(),
|
||||||
@@ -63,9 +110,14 @@ pub fn setup_gossip_fonts(ctx: &egui::Context) {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
font_data.insert(
|
||||||
|
"NotoSansCJK".to_owned(),
|
||||||
|
FontData::from_static(include_bytes!("../assets/fonts/NotoSansCJK-Regular.ttc")),
|
||||||
|
);
|
||||||
|
|
||||||
// Some good looking emojis. Use as first priority:
|
// Some good looking emojis. Use as first priority:
|
||||||
font_data.insert(
|
font_data.insert(
|
||||||
"NotoEmoji-Regular".to_owned(),
|
"NotoEmoji".to_owned(),
|
||||||
FontData::from_static(include_bytes!("../assets/fonts/NotoEmoji-Regular.ttf")).tweak(
|
FontData::from_static(include_bytes!("../assets/fonts/NotoEmoji-Regular.ttf")).tweak(
|
||||||
FontTweak {
|
FontTweak {
|
||||||
scale: 1.1, // make them a touch larger
|
scale: 1.1, // make them a touch larger
|
||||||
@@ -76,23 +128,28 @@ pub fn setup_gossip_fonts(ctx: &egui::Context) {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut proportional = vec!["DejaVuSans".to_owned(), "NotoEmoji-Regular".to_owned()];
|
let mut proportional = vec![
|
||||||
//if cfg!(feature = "lang-cjk") {
|
"Onest".to_owned(),
|
||||||
proportional.push("NotoSansCJK".to_owned());
|
"DejaVuSans".to_owned(),
|
||||||
//}
|
"NotoEmoji".to_owned(),
|
||||||
|
"NotoSansCJK".to_owned(),
|
||||||
|
];
|
||||||
|
|
||||||
families.insert(FontFamily::Proportional, proportional);
|
families.insert(egui::FontFamily::Proportional, proportional);
|
||||||
|
|
||||||
families.insert(
|
families.insert(
|
||||||
FontFamily::Monospace,
|
egui::FontFamily::Monospace,
|
||||||
vec!["Inconsolata".to_owned(), "NotoEmoji-Regular".to_owned()],
|
vec!["Inconsolata".to_owned(), "NotoEmoji".to_owned()],
|
||||||
);
|
);
|
||||||
|
|
||||||
families.insert(
|
families.insert(
|
||||||
FontFamily::Name("Bold".into()),
|
egui::FontFamily::Name(NamedFontFamily::Medium.as_str().into()),
|
||||||
vec!["DejaVuSansBold".to_owned()],
|
//egui::FontFamily::Name("bold".into()),
|
||||||
|
vec!["OnestMedium".to_owned(), "NotoEmoji".to_owned()],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
debug!("fonts: {:?}", families);
|
||||||
|
|
||||||
let defs = FontDefinitions {
|
let defs = FontDefinitions {
|
||||||
font_data,
|
font_data,
|
||||||
families,
|
families,
|
||||||
|
|||||||
Reference in New Issue
Block a user