move conrod font out of common

Former-commit-id: 1e7cbce00eddff6c765326671d04d9494639773e
This commit is contained in:
Imbris 2019-05-07 02:25:26 -04:00
parent d13430d51e
commit 81c5a070c5
6 changed files with 20 additions and 28 deletions

1
Cargo.lock generated
View File

@ -2284,7 +2284,6 @@ name = "veloren-common"
version = "0.2.0"
dependencies = [
"bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"conrod_core 0.63.0 (git+https://gitlab.com/veloren/conrod.git)",
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -9,7 +9,6 @@ sphynx = { git = "https://gitlab.com/veloren/sphynx.git", features = ["serde1"]
specs = { version = "0.14", features = ["serde", "nightly"] }
vek = { version = "0.9", features = ["serde"] }
conrod_core = { git = "https://gitlab.com/veloren/conrod.git" }
dot_vox = "4.0"
image = "0.21"
threadpool = "1.7"

View File

@ -1,4 +1,3 @@
use conrod_core::text::Font;
use dot_vox::DotVoxData;
use image::DynamicImage;
use lazy_static::lazy_static;
@ -85,12 +84,6 @@ impl Asset for DotVoxData {
}
}
impl Asset for Font {
fn load(specifier: &str) -> Result<Self, Error> {
Ok(Font::from_bytes(load_from_path(specifier)?).unwrap())
}
}
// TODO: System to load file from specifiers (eg "core.ui.backgrounds.city")
fn try_open_with_path(name: &str) -> Option<File> {
debug!("Trying to access \"{}\"", name);

View File

@ -361,12 +361,7 @@ impl CharSelectionUi {
// Load fonts
let load_font = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/font", filename].concat();
ui.new_font(Arc::new(
conrod_core::text::Font::from_bytes(
assets::load_from_path(fullpath.as_str()).expect("Error loading file"),
)
.unwrap(),
))
ui.new_font(assets::load(fullpath.as_str()).expect("Error loading file"))
};
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);

View File

@ -125,12 +125,7 @@ impl MainMenuUi {
// Load fonts
let load_font = |filename, ui: &mut Ui| {
let fullpath: String = ["/voxygen/font", filename].concat();
ui.new_font(Arc::new(
conrod_core::text::Font::from_bytes(
assets::load_from_path(fullpath.as_str()).expect("Error loading file"),
)
.unwrap(),
))
ui.new_font(assets::load(fullpath.as_str()).expect("Error loading file"))
};
let font_opensans = load_font("/OpenSans-Regular.ttf", &mut ui);
let font_metamorph = load_font("/Metamorphous-Regular.ttf", &mut ui);

View File

@ -6,6 +6,11 @@ mod img_ids;
#[macro_use]
mod font_ids;
pub use graphic::Graphic;
pub use img_ids::{BlankGraphic, GraphicCreator, ImageGraphic, VoxelGraphic};
pub(self) use util::{linear_to_srgb, srgb_to_linear};
pub use widgets::toggle_button::ToggleButton;
use crate::{
render::{
create_ui_quad, create_ui_tri, Mesh, Model, RenderError, Renderer, Texture, UiMode,
@ -14,23 +19,20 @@ use crate::{
window::Window,
Error,
};
use common::assets;
use conrod_core::{
event::Input,
graph::Graph,
image::{Id as ImgId, Map},
input::{touch::Touch, Button, Motion, Widget},
render::Primitive,
text::{font::Id as FontId, Font, GlyphCache},
text::{self, GlyphCache},
widget::{id::Generator, Id as WidgId},
Ui as CrUi, UiBuilder, UiCell,
};
pub use graphic::Graphic;
use graphic::{GraphicCache, Id as GraphicId};
pub use img_ids::{BlankGraphic, GraphicCreator, ImageGraphic, VoxelGraphic};
use std::sync::Arc;
pub(self) use util::{linear_to_srgb, srgb_to_linear};
use vek::*;
pub use widgets::toggle_button::ToggleButton;
#[derive(Debug)]
pub enum UiError {
@ -218,6 +220,15 @@ impl Scale {
}
}
pub struct Font(text::Font);
impl assets::Asset for Font {
fn load(specifier: &str) -> Result<Self, assets::Error> {
Ok(Font(
text::Font::from_bytes(assets::load_from_path(specifier)?).unwrap(),
))
}
}
pub struct Ui {
ui: CrUi,
image_map: Map<GraphicId>,
@ -257,8 +268,8 @@ impl Ui {
self.image_map.insert(self.cache.add_graphic(graphic))
}
pub fn new_font(&mut self, mut font: Arc<Font>) -> FontId {
self.ui.fonts.insert(Arc::make_mut(&mut font).clone())
pub fn new_font(&mut self, mut font: Arc<Font>) -> text::font::Id {
self.ui.fonts.insert(font.as_ref().0.clone())
}
pub fn id_generator(&mut self) -> Generator {