Added text attributes
parent
b7839efc4b
commit
62b8a4f2d3
4
TODO.md
4
TODO.md
|
@ -4,13 +4,9 @@
|
||||||
- outfitter
|
- outfitter
|
||||||
- Clean up scripting & errors
|
- Clean up scripting & errors
|
||||||
- Clean up sprite content (and content in general)
|
- Clean up sprite content (and content in general)
|
||||||
- Arbitrary scene names
|
|
||||||
- Text style, color, formatting
|
|
||||||
- Flying UI
|
- Flying UI
|
||||||
- Mouse colliders
|
- Mouse colliders
|
||||||
- Clean renderscene/UI scene/change scene on land
|
|
||||||
- UI captures input?
|
- UI captures input?
|
||||||
- Scriptable renderscene: script decides which parts to show
|
|
||||||
- No UI zoom scroll
|
- No UI zoom scroll
|
||||||
- Preserve aspect for icons
|
- Preserve aspect for icons
|
||||||
- Check game version in config
|
- Check game version in config
|
||||||
|
|
|
@ -46,8 +46,7 @@ fn init(state) {
|
||||||
);
|
);
|
||||||
|
|
||||||
let title = TextBoxBuilder(
|
let title = TextBoxBuilder(
|
||||||
"title",
|
"title", 10.0, 10.0,
|
||||||
10.0, 10.0, TextBoxFont::Serif, TextBoxJustify::Center,
|
|
||||||
Rect(
|
Rect(
|
||||||
-70.79, 138.0, 59.867, 10.0,
|
-70.79, 138.0, 59.867, 10.0,
|
||||||
SpriteAnchor::NorthWest,
|
SpriteAnchor::NorthWest,
|
||||||
|
@ -60,10 +59,12 @@ fn init(state) {
|
||||||
} else {
|
} else {
|
||||||
title.set_text("");
|
title.set_text("");
|
||||||
}
|
}
|
||||||
|
title.align_center();
|
||||||
|
title.font_serif();
|
||||||
|
title.weight_bold();
|
||||||
|
|
||||||
let desc = TextBoxBuilder(
|
let desc = TextBoxBuilder(
|
||||||
"desc",
|
"desc", 7.5, 8.0,
|
||||||
7.5, 8.0, TextBoxFont::SansSerif, TextBoxJustify::Left,
|
|
||||||
Rect(
|
Rect(
|
||||||
-178.92, -20.3, 343.0, 81.467,
|
-178.92, -20.3, 343.0, 81.467,
|
||||||
SpriteAnchor::NorthWest,
|
SpriteAnchor::NorthWest,
|
||||||
|
@ -76,6 +77,7 @@ fn init(state) {
|
||||||
} else {
|
} else {
|
||||||
desc.set_text("");
|
desc.set_text("");
|
||||||
}
|
}
|
||||||
|
desc.font_sansserif();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
button,
|
button,
|
||||||
|
|
|
@ -17,8 +17,7 @@ fn init(state) {
|
||||||
);
|
);
|
||||||
|
|
||||||
let exit_text = TextBoxBuilder(
|
let exit_text = TextBoxBuilder(
|
||||||
"exit_text",
|
"exit_text", 10.0, 10.0,
|
||||||
10.0, 10.0, TextBoxFont::Serif, TextBoxJustify::Center,
|
|
||||||
Rect(
|
Rect(
|
||||||
122.71, 48.0, 51.0, 12.0,
|
122.71, 48.0, 51.0, 12.0,
|
||||||
SpriteAnchor::NorthWest,
|
SpriteAnchor::NorthWest,
|
||||||
|
@ -27,6 +26,8 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
exit_text.set_text("Exit");
|
exit_text.set_text("Exit");
|
||||||
|
exit_text.font_serif();
|
||||||
|
exit_text.align_center();
|
||||||
|
|
||||||
let exit_button = SpriteBuilder(
|
let exit_button = SpriteBuilder(
|
||||||
"exit_button",
|
"exit_button",
|
||||||
|
@ -63,8 +64,7 @@ fn init(state) {
|
||||||
);
|
);
|
||||||
|
|
||||||
let ship_name = TextBoxBuilder(
|
let ship_name = TextBoxBuilder(
|
||||||
"ship_name",
|
"ship_name", 10.0, 10.0,
|
||||||
10.0, 10.0, TextBoxFont::Serif, TextBoxJustify::Center,
|
|
||||||
Rect(
|
Rect(
|
||||||
111.0, -167.27, 145.0, 10.0,
|
111.0, -167.27, 145.0, 10.0,
|
||||||
SpriteAnchor::Center,
|
SpriteAnchor::Center,
|
||||||
|
@ -73,10 +73,11 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
ship_name.set_text("Hyperion");
|
ship_name.set_text("Hyperion");
|
||||||
|
ship_name.font_serif();
|
||||||
|
ship_name.align_center();
|
||||||
|
|
||||||
let ship_type = TextBoxBuilder(
|
let ship_type = TextBoxBuilder(
|
||||||
"ship_type",
|
"ship_type", 7.0, 8.5,
|
||||||
7.0, 8.5, TextBoxFont::SansSerif, TextBoxJustify::Center,
|
|
||||||
Rect(
|
Rect(
|
||||||
111.0, -178.0, 145.0, 8.5,
|
111.0, -178.0, 145.0, 8.5,
|
||||||
SpriteAnchor::Center,
|
SpriteAnchor::Center,
|
||||||
|
@ -89,10 +90,11 @@ fn init(state) {
|
||||||
} else {
|
} else {
|
||||||
ship_type.set_text("ERR: SHIP IS NONE");
|
ship_type.set_text("ERR: SHIP IS NONE");
|
||||||
}
|
}
|
||||||
|
ship_type.font_sansserif();
|
||||||
|
ship_type.align_center();
|
||||||
|
|
||||||
let ship_stats = TextBoxBuilder(
|
let ship_stats = TextBoxBuilder(
|
||||||
"ship_stats",
|
"ship_stats", 7.0, 8.5,
|
||||||
7.0, 8.5, TextBoxFont::Monospace, TextBoxJustify::Left,
|
|
||||||
Rect(
|
Rect(
|
||||||
38.526, -192.332, 144.948, 154.5,
|
38.526, -192.332, 144.948, 154.5,
|
||||||
SpriteAnchor::NorthWest,
|
SpriteAnchor::NorthWest,
|
||||||
|
@ -101,7 +103,7 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
ship_stats.set_text("Earth");
|
ship_stats.set_text("Earth");
|
||||||
|
ship_stats.font_monospace();
|
||||||
|
|
||||||
|
|
||||||
let outfit_bg = SpriteBuilder(
|
let outfit_bg = SpriteBuilder(
|
||||||
|
@ -125,8 +127,7 @@ fn init(state) {
|
||||||
);
|
);
|
||||||
|
|
||||||
let outfit_name = TextBoxBuilder(
|
let outfit_name = TextBoxBuilder(
|
||||||
"outfit_name",
|
"outfit_name", 16.0, 16.0,
|
||||||
16.0, 16.0, TextBoxFont::Serif, TextBoxJustify::Left,
|
|
||||||
Rect(
|
Rect(
|
||||||
-312.0, -20.0, 200.0, 16.0,
|
-312.0, -20.0, 200.0, 16.0,
|
||||||
SpriteAnchor::NorthWest,
|
SpriteAnchor::NorthWest,
|
||||||
|
@ -135,10 +136,11 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
outfit_name.set_text("Earth");
|
outfit_name.set_text("Earth");
|
||||||
|
outfit_name.font_serif();
|
||||||
|
outfit_name.weight_bold();
|
||||||
|
|
||||||
let outfit_desc = TextBoxBuilder(
|
let outfit_desc = TextBoxBuilder(
|
||||||
"outfit_desc",
|
"outfit_desc", 7.0, 8.5,
|
||||||
7.0, 8.5, TextBoxFont::SansSerif, TextBoxJustify::Left,
|
|
||||||
Rect(
|
Rect(
|
||||||
-166.0, -219.0, 260.0, 78.0,
|
-166.0, -219.0, 260.0, 78.0,
|
||||||
SpriteAnchor::Center,
|
SpriteAnchor::Center,
|
||||||
|
@ -147,10 +149,10 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
outfit_desc.set_text("Earth");
|
outfit_desc.set_text("Earth");
|
||||||
|
outfit_desc.font_serif();
|
||||||
|
|
||||||
let outfit_stats = TextBoxBuilder(
|
let outfit_stats = TextBoxBuilder(
|
||||||
"outfit_stats",
|
"outfit_stats", 7.0, 8.5,
|
||||||
7.0, 8.5, TextBoxFont::Monospace, TextBoxJustify::Left,
|
|
||||||
Rect(
|
Rect(
|
||||||
-295.0, -271.0, 164.0, 216.0,
|
-295.0, -271.0, 164.0, 216.0,
|
||||||
SpriteAnchor::NorthWest,
|
SpriteAnchor::NorthWest,
|
||||||
|
@ -159,7 +161,8 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
outfit_stats.set_text("Earth");
|
outfit_stats.set_text("Earth");
|
||||||
|
ship_stats.font_monospace();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
ship_bg,
|
ship_bg,
|
||||||
ship_thumb,
|
ship_thumb,
|
||||||
|
|
|
@ -46,16 +46,6 @@ pub fn register_into_engine(engine: &mut Engine) {
|
||||||
// Larger modules
|
// Larger modules
|
||||||
.register_type_with_name::<SpriteAnchor>("SpriteAnchor")
|
.register_type_with_name::<SpriteAnchor>("SpriteAnchor")
|
||||||
.register_static_module("SpriteAnchor", exported_module!(spriteanchor_mod).into())
|
.register_static_module("SpriteAnchor", exported_module!(spriteanchor_mod).into())
|
||||||
.register_type_with_name::<TextBoxFont>("TextBoxFont")
|
|
||||||
.register_static_module(
|
|
||||||
"TextBoxFont",
|
|
||||||
exported_module!(util::textboxfont_mod).into(),
|
|
||||||
)
|
|
||||||
.register_type_with_name::<TextBoxJustify>("TextBoxJustify")
|
|
||||||
.register_static_module(
|
|
||||||
"TextBoxJustify",
|
|
||||||
exported_module!(textboxjustify_mod).into(),
|
|
||||||
)
|
|
||||||
.register_type_with_name::<SceneAction>("SceneAction")
|
.register_type_with_name::<SceneAction>("SceneAction")
|
||||||
.register_static_module("SceneAction", exported_module!(sceneaction_mod).into());
|
.register_static_module("SceneAction", exported_module!(sceneaction_mod).into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
|
use glyphon::{cosmic_text::Align, Attrs, AttrsOwned, FamilyOwned, Style, Weight};
|
||||||
use rhai::{CustomType, ImmutableString, TypeBuilder};
|
use rhai::{CustomType, ImmutableString, TypeBuilder};
|
||||||
|
|
||||||
use super::{Color, Rect, TextBoxFont, TextBoxJustify};
|
use super::{Color, Rect};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TextBoxBuilder {
|
pub struct TextBoxBuilder {
|
||||||
pub name: ImmutableString,
|
pub name: ImmutableString,
|
||||||
pub font_size: f32,
|
pub font_size: f32,
|
||||||
pub line_height: f32,
|
pub line_height: f32,
|
||||||
pub font: TextBoxFont,
|
|
||||||
pub justify: TextBoxJustify,
|
|
||||||
pub rect: Rect,
|
pub rect: Rect,
|
||||||
pub text: ImmutableString,
|
pub text: ImmutableString,
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
|
||||||
|
pub attrs: AttrsOwned,
|
||||||
|
pub justify: Align,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextBoxBuilder {
|
impl TextBoxBuilder {
|
||||||
|
@ -19,8 +21,6 @@ impl TextBoxBuilder {
|
||||||
name: ImmutableString,
|
name: ImmutableString,
|
||||||
font_size: f32,
|
font_size: f32,
|
||||||
line_height: f32,
|
line_height: f32,
|
||||||
font: TextBoxFont,
|
|
||||||
justify: TextBoxJustify,
|
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
color: Color,
|
color: Color,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -29,10 +29,10 @@ impl TextBoxBuilder {
|
||||||
name,
|
name,
|
||||||
font_size,
|
font_size,
|
||||||
line_height,
|
line_height,
|
||||||
font,
|
|
||||||
justify,
|
|
||||||
rect,
|
rect,
|
||||||
text: ImmutableString::new(),
|
text: ImmutableString::new(),
|
||||||
|
attrs: AttrsOwned::new(Attrs::new()),
|
||||||
|
justify: Align::Left,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,25 @@ impl CustomType for TextBoxBuilder {
|
||||||
builder
|
builder
|
||||||
.with_name("TextBoxBuilder")
|
.with_name("TextBoxBuilder")
|
||||||
.with_fn("TextBoxBuilder", Self::new)
|
.with_fn("TextBoxBuilder", Self::new)
|
||||||
.with_fn("set_text", Self::set_text);
|
.with_fn("set_text", Self::set_text)
|
||||||
|
.with_fn("align_left", |s: &mut Self| s.justify = Align::Left)
|
||||||
|
.with_fn("align_right", |s: &mut Self| s.justify = Align::Right)
|
||||||
|
.with_fn("align_justify", |s: &mut Self| s.justify = Align::Justified)
|
||||||
|
.with_fn("align_center", |s: &mut Self| s.justify = Align::Center)
|
||||||
|
.with_fn("weight_bold", |s: &mut Self| s.attrs.weight = Weight::BOLD)
|
||||||
|
.with_fn("weight_normal", |s: &mut Self| {
|
||||||
|
s.attrs.weight = Weight::NORMAL
|
||||||
|
})
|
||||||
|
.with_fn("font_serif", |s: &mut Self| {
|
||||||
|
s.attrs.family_owned = FamilyOwned::Serif
|
||||||
|
})
|
||||||
|
.with_fn("font_sansserif", |s: &mut Self| {
|
||||||
|
s.attrs.family_owned = FamilyOwned::SansSerif
|
||||||
|
})
|
||||||
|
.with_fn("font_monospace", |s: &mut Self| {
|
||||||
|
s.attrs.family_owned = FamilyOwned::Monospace
|
||||||
|
})
|
||||||
|
.with_fn("style_normal", |s: &mut Self| s.attrs.style = Style::Normal)
|
||||||
|
.with_fn("style_italic", |s: &mut Self| s.attrs.style = Style::Italic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,37 +26,3 @@ pub mod spriteanchor_mod {
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
pub const SouthEast: SpriteAnchor = SpriteAnchor::SouthEast;
|
pub const SouthEast: SpriteAnchor = SpriteAnchor::SouthEast;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
||||||
pub enum TextBoxFont {
|
|
||||||
Serif,
|
|
||||||
SansSerif,
|
|
||||||
Monospace,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[export_module]
|
|
||||||
pub mod textboxfont_mod {
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const Serif: TextBoxFont = TextBoxFont::Serif;
|
|
||||||
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const SansSerif: TextBoxFont = TextBoxFont::SansSerif;
|
|
||||||
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const Monospace: TextBoxFont = TextBoxFont::Monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
||||||
pub enum TextBoxJustify {
|
|
||||||
Center,
|
|
||||||
Left,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[export_module]
|
|
||||||
pub mod textboxjustify_mod {
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const Center: TextBoxJustify = TextBoxJustify::Center;
|
|
||||||
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const Left: TextBoxJustify = TextBoxJustify::Left;
|
|
||||||
}
|
|
||||||
|
|
|
@ -166,8 +166,8 @@ impl UiManager {
|
||||||
t.name.to_string(),
|
t.name.to_string(),
|
||||||
t.font_size,
|
t.font_size,
|
||||||
t.line_height,
|
t.line_height,
|
||||||
t.font,
|
|
||||||
t.justify,
|
t.justify,
|
||||||
|
t.attrs,
|
||||||
t.rect,
|
t.rect,
|
||||||
t.color,
|
t.color,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
use glyphon::{cosmic_text::Align, Attrs, Buffer, Color, Metrics, Shaping, TextArea, TextBounds};
|
use glyphon::{
|
||||||
|
cosmic_text::Align, AttrsOwned, Buffer, Color, Metrics, Shaping, TextArea, TextBounds,
|
||||||
|
};
|
||||||
use nalgebra::Vector2;
|
use nalgebra::Vector2;
|
||||||
|
|
||||||
use super::super::api::{Rect, TextBoxFont, TextBoxJustify};
|
use super::super::api::Rect;
|
||||||
use crate::{ui::api, RenderInput, RenderState};
|
use crate::{ui::api, RenderInput, RenderState};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TextBox {
|
pub struct TextBox {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
font: TextBoxFont,
|
justify: Align,
|
||||||
justify: TextBoxJustify,
|
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
color: api::Color,
|
color: api::Color,
|
||||||
|
attrs: AttrsOwned,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextBox {
|
impl TextBox {
|
||||||
|
@ -20,8 +22,8 @@ impl TextBox {
|
||||||
name: String,
|
name: String,
|
||||||
font_size: f32,
|
font_size: f32,
|
||||||
line_height: f32,
|
line_height: f32,
|
||||||
font: TextBoxFont,
|
justify: Align,
|
||||||
justify: TextBoxJustify,
|
attrs: AttrsOwned,
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
color: api::Color,
|
color: api::Color,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -35,30 +37,24 @@ impl TextBox {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
font,
|
|
||||||
justify,
|
justify,
|
||||||
rect,
|
rect,
|
||||||
buffer,
|
buffer,
|
||||||
color,
|
color,
|
||||||
|
attrs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_text(&mut self, state: &mut RenderState, text: &str) {
|
pub fn set_text(&mut self, state: &mut RenderState, text: &str) {
|
||||||
let mut attrs = Attrs::new();
|
self.buffer.set_text(
|
||||||
attrs = match self.font {
|
&mut state.text_font_system,
|
||||||
TextBoxFont::Monospace => attrs.family(glyphon::Family::Monospace),
|
text,
|
||||||
TextBoxFont::SansSerif => attrs.family(glyphon::Family::SansSerif),
|
self.attrs.as_attrs(),
|
||||||
TextBoxFont::Serif => attrs.family(glyphon::Family::Serif),
|
Shaping::Advanced,
|
||||||
};
|
);
|
||||||
|
|
||||||
self.buffer
|
|
||||||
.set_text(&mut state.text_font_system, text, attrs, Shaping::Advanced);
|
|
||||||
|
|
||||||
for l in &mut self.buffer.lines {
|
for l in &mut self.buffer.lines {
|
||||||
l.set_align(Some(match self.justify {
|
l.set_align(Some(self.justify));
|
||||||
TextBoxJustify::Center => Align::Center,
|
|
||||||
TextBoxJustify::Left => Align::Left,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.buffer.shape_until_scroll(&mut state.text_font_system);
|
self.buffer.shape_until_scroll(&mut state.text_font_system);
|
||||||
|
|
Loading…
Reference in New Issue