pub struct BookRenderer {
pub book: Book,
pub state: BookViewState,
pub theme: BookTheme,
pub ui: Option<UiRoot>,
/* private fields */
}Expand description
A book being read: what it shows, laid out for the screen it was last drawn on.
Fields§
§book: Book§state: BookViewState§theme: BookTheme§ui: Option<UiRoot>Implementations§
Source§impl BookRenderer
impl BookRenderer
pub fn new(book: Book) -> BookRenderer
Sourcepub fn set_translator(&mut self, tr: fn(&str) -> Option<String>)
pub fn set_translator(&mut self, tr: fn(&str) -> Option<String>)
The game’s translations: items’ names in recipe titles, and, for
Book::i18n books, the book’s texts — translation keys, looked up
with tr (unknown keys stay as they are) and re-looked up whenever
the language changes.
pub fn handle_event(&mut self, ev: &str)
Sourcepub fn add_recipe(&mut self, id: impl Into<String>, recipe: &Value)
pub fn add_recipe(&mut self, id: impl Into<String>, recipe: &Value)
Register a recipe (Yog’s recipe, as Yog Data) so recipe pages can render it visually. Unknown recipe types are ignored.
Sourcepub fn render(&mut self, ctx: &GfxContext, sw: f32, sh: f32)
pub fn render(&mut self, ctx: &GfxContext, sw: f32, sh: f32)
Draws the book into a sw×sh screen — all of it through draw2d
(its sprite sheets as the image sources BOOK_SHEET and
CRAFTING_SHEET); mods’ pictures (BookPage::Drawn) are left
empty — see BookRenderer::render_with.
Sourcepub fn render_with(
&mut self,
ctx: &GfxContext,
sw: f32,
sh: f32,
draw: &mut dyn FnMut(&GfxContext, &str, &Value, [f32; 4]),
)
pub fn render_with( &mut self, ctx: &GfxContext, sw: f32, sh: f32, draw: &mut dyn FnMut(&GfxContext, &str, &Value, [f32; 4]), )
Draws the book, mods’ pictures with draw(ctx, drawer, data, [x, y, w, h]) (screen pixels) — the game calls the mod that registered drawer.
Sourcepub fn animated(&self) -> bool
pub fn animated(&self) -> bool
The page shown moves by itself (an entity, a structure, an ingredient’s alternatives): the host should keep redrawing it.
Sourcepub fn click(&mut self, x: f32, y: f32) -> Option<String>
pub fn click(&mut self, x: f32, y: f32) -> Option<String>
A click at (x, y) (screen GUI pixels, as last rendered): what it
hit does its thing. The action it was ("next_page", "entry:3",
…), if any.
Sourcepub fn show(&mut self, entry: &str, page: usize) -> bool
pub fn show(&mut self, entry: &str, page: usize) -> bool
Shows entry (an entry id) at page — its page as written, not
counting the pages long text flowed onto — as a reader would have
got there; false if there’s no such entry.