iris: load application-owned fonts
This commit is contained in:
1 parent
f7e7950908
commit
bdc9c914c4
19 files changed
+189
-87
No files matched your search
@@ -0,0 +1,30 @@
|
||||
pub const OPEN: &str = "\u{F035D}";
|
||||
|
||||
pub const CLOSED: &str = "\u{F035F}";
|
||||
|
||||
pub const COLLAPSE: &str = "\u{F0360}";
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use swash::FontRef;
|
||||
|
||||
#[test]
|
||||
fn every_icon_is_in_the_application_font() {
|
||||
let font = FontRef::from_index(super::super::ICON_FONT, 0)
|
||||
.expect("the application icon font parses");
|
||||
let charmap = font.charmap();
|
||||
for (name, glyph) in [("OPEN", OPEN), ("CLOSED", CLOSED), ("COLLAPSE", COLLAPSE)] {
|
||||
let mut chars = glyph.chars();
|
||||
let ch = chars.next().expect("an icon is one character");
|
||||
assert!(chars.next().is_none(), "{name} is more than one character");
|
||||
assert_ne!(
|
||||
charmap.map(ch),
|
||||
0,
|
||||
"{name} (U+{:04X}) is not in nerd_icons.ttf -- add it to \
|
||||
build-icon-font.sh's GLYPHS and rerun the script",
|
||||
ch as u32
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ pub mod composer;
|
||||
// Keep the 1.9 MB fixture out of ordinary APKs.
|
||||
#[cfg(feature = "fixture")]
|
||||
pub mod fixture;
|
||||
mod icon;
|
||||
pub mod markdown;
|
||||
pub mod row;
|
||||
pub(crate) mod tap;
|
||||
@@ -13,6 +14,16 @@ use iris::prelude::*;
|
||||
use std::{mem, rc::Rc};
|
||||
use theme::Theme;
|
||||
|
||||
const ICON_FONT: &[u8] = include_bytes!("../../assets/fonts/nerd_icons.ttf");
|
||||
|
||||
pub(crate) fn register_fonts(ui: &mut Ui) {
|
||||
if ui.is_font_registered(&Family::Icons) {
|
||||
return;
|
||||
}
|
||||
ui.register_font(Family::Icons, ICON_FONT)
|
||||
.expect("the ai-app icon font must register before text is drawn");
|
||||
}
|
||||
|
||||
pub struct TranscriptScreen {
|
||||
/// The transcript's own `LazySpan` -- the layout *and* the scroll
|
||||
/// position, since a lazy span owns a `ScrollController` of its own
|
||||
@@ -241,6 +252,7 @@ pub fn build_tree<Rsc: HasEvents>(
|
||||
where
|
||||
Rsc::State: FocusHost + OpenUrl,
|
||||
{
|
||||
register_fonts(rsc.ui_mut());
|
||||
let theme = Rc::new(Theme::new(&mut rsc.ui_mut().paints));
|
||||
let list = LazySpan::new(Dir::DOWN, Pin::End).add(rsc);
|
||||
list.controller(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::client::text_cap::{VERBATIM_BYTES, VERBATIM_LINES, cut, show_all_label};
|
||||
use crate::client::tool_summary::{ToolInput, parse_tool_input};
|
||||
use crate::client::transcript_fold::{ToolState, TranscriptItem};
|
||||
use crate::ui::icon;
|
||||
use crate::ui::markdown::highlight_into;
|
||||
use crate::ui::tap::{hold_edge, on_tap};
|
||||
use crate::ui::theme::Theme;
|
||||
|
||||
Reference in new issue
Block a user