Added text color
parent
eca7e7f5e6
commit
b7839efc4b
|
@ -52,7 +52,8 @@ fn init(state) {
|
|||
-70.79, 138.0, 59.867, 10.0,
|
||||
SpriteAnchor::NorthWest,
|
||||
SpriteAnchor::Center
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
if player.is_landed() {
|
||||
title.set_text(player.landed_on().name());
|
||||
|
@ -67,7 +68,8 @@ fn init(state) {
|
|||
-178.92, -20.3, 343.0, 81.467,
|
||||
SpriteAnchor::NorthWest,
|
||||
SpriteAnchor::Center
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
if player.is_landed() {
|
||||
desc.set_text(player.landed_on().desc());
|
||||
|
|
|
@ -23,7 +23,8 @@ fn init(state) {
|
|||
122.71, 48.0, 51.0, 12.0,
|
||||
SpriteAnchor::NorthWest,
|
||||
SpriteAnchor::SouthWest
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
exit_text.set_text("Exit");
|
||||
|
||||
|
@ -68,7 +69,8 @@ fn init(state) {
|
|||
111.0, -167.27, 145.0, 10.0,
|
||||
SpriteAnchor::Center,
|
||||
SpriteAnchor::NorthWest
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
ship_name.set_text("Hyperion");
|
||||
|
||||
|
@ -79,7 +81,8 @@ fn init(state) {
|
|||
111.0, -178.0, 145.0, 8.5,
|
||||
SpriteAnchor::Center,
|
||||
SpriteAnchor::NorthWest
|
||||
)
|
||||
),
|
||||
Color(0.7, 0.7, 0.7, 1.0)
|
||||
);
|
||||
if state.player_ship().is_some() {
|
||||
ship_type.set_text(state.player_ship().name());
|
||||
|
@ -94,7 +97,8 @@ fn init(state) {
|
|||
38.526, -192.332, 144.948, 154.5,
|
||||
SpriteAnchor::NorthWest,
|
||||
SpriteAnchor::NorthWest,
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
ship_stats.set_text("Earth");
|
||||
|
||||
|
@ -127,7 +131,8 @@ fn init(state) {
|
|||
-312.0, -20.0, 200.0, 16.0,
|
||||
SpriteAnchor::NorthWest,
|
||||
SpriteAnchor::NorthEast,
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
outfit_name.set_text("Earth");
|
||||
|
||||
|
@ -138,7 +143,8 @@ fn init(state) {
|
|||
-166.0, -219.0, 260.0, 78.0,
|
||||
SpriteAnchor::Center,
|
||||
SpriteAnchor::NorthEast,
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
outfit_desc.set_text("Earth");
|
||||
|
||||
|
@ -149,7 +155,8 @@ fn init(state) {
|
|||
-295.0, -271.0, 164.0, 216.0,
|
||||
SpriteAnchor::NorthWest,
|
||||
SpriteAnchor::NorthEast,
|
||||
)
|
||||
),
|
||||
Color(1.0, 1.0, 1.0, 1.0)
|
||||
);
|
||||
outfit_stats.set_text("Earth");
|
||||
|
||||
|
|
|
@ -9,13 +9,23 @@ pub struct Color {
|
|||
impl Color {
|
||||
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
|
||||
Self {
|
||||
val: Vector4::new(r, g, b, a),
|
||||
val: Vector4::new(
|
||||
r.clamp(0.0, 1.0),
|
||||
g.clamp(0.0, 1.0),
|
||||
b.clamp(0.0, 1.0),
|
||||
a.clamp(0.0, 1.0),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_array(&self) -> [f32; 4] {
|
||||
[self.val.x, self.val.y, self.val.z, self.val.w]
|
||||
}
|
||||
|
||||
pub fn as_array_u8(&self) -> [u8; 4] {
|
||||
let val = self.val * 255.0;
|
||||
[val.x as u8, val.y as u8, val.z as u8, val.w as u8]
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomType for Color {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rhai::{CustomType, ImmutableString, TypeBuilder};
|
||||
|
||||
use super::{Rect, TextBoxFont, TextBoxJustify};
|
||||
use super::{Color, Rect, TextBoxFont, TextBoxJustify};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TextBoxBuilder {
|
||||
|
@ -11,6 +11,7 @@ pub struct TextBoxBuilder {
|
|||
pub justify: TextBoxJustify,
|
||||
pub rect: Rect,
|
||||
pub text: ImmutableString,
|
||||
pub color: Color,
|
||||
}
|
||||
|
||||
impl TextBoxBuilder {
|
||||
|
@ -21,8 +22,10 @@ impl TextBoxBuilder {
|
|||
font: TextBoxFont,
|
||||
justify: TextBoxJustify,
|
||||
rect: Rect,
|
||||
color: Color,
|
||||
) -> Self {
|
||||
Self {
|
||||
color,
|
||||
name,
|
||||
font_size,
|
||||
line_height,
|
||||
|
|
|
@ -169,6 +169,7 @@ impl UiManager {
|
|||
t.font,
|
||||
t.justify,
|
||||
t.rect,
|
||||
t.color,
|
||||
);
|
||||
b.set_text(state, &t.text);
|
||||
self.elements.push(UiElement::new_text(b));
|
||||
|
|
|
@ -7,10 +7,10 @@ use crate::{ui::api::Color, vertexbuffer::types::RadialBarInstance, RenderInput,
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct RadialBar {
|
||||
pub name: String,
|
||||
pub rect: Rect,
|
||||
pub stroke: f32,
|
||||
pub color: Color,
|
||||
pub progress: f32,
|
||||
rect: Rect,
|
||||
stroke: f32,
|
||||
color: Color,
|
||||
progress: f32,
|
||||
}
|
||||
|
||||
impl RadialBar {
|
||||
|
|
|
@ -7,17 +7,18 @@ use crate::{ui::event::Event, vertexbuffer::types::UiInstance, RenderInput, Rend
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
pub name: String,
|
||||
|
||||
/// If this is none, this was constructed with an invalid sprite
|
||||
pub anim: Option<SpriteAutomaton>,
|
||||
|
||||
rect: Rect,
|
||||
mask: Option<SpriteHandle>,
|
||||
pub name: String,
|
||||
|
||||
has_mouse: bool,
|
||||
has_click: bool,
|
||||
/// If true, ignore mouse events until click is released
|
||||
waiting_for_release: bool,
|
||||
has_mouse: bool,
|
||||
has_click: bool,
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
|
|
|
@ -2,15 +2,16 @@ use glyphon::{cosmic_text::Align, Attrs, Buffer, Color, Metrics, Shaping, TextAr
|
|||
use nalgebra::Vector2;
|
||||
|
||||
use super::super::api::{Rect, TextBoxFont, TextBoxJustify};
|
||||
use crate::{RenderInput, RenderState};
|
||||
use crate::{ui::api, RenderInput, RenderState};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TextBox {
|
||||
pub name: String,
|
||||
pub font: TextBoxFont,
|
||||
pub justify: TextBoxJustify,
|
||||
pub rect: Rect,
|
||||
pub buffer: Buffer,
|
||||
font: TextBoxFont,
|
||||
justify: TextBoxJustify,
|
||||
rect: Rect,
|
||||
buffer: Buffer,
|
||||
color: api::Color,
|
||||
}
|
||||
|
||||
impl TextBox {
|
||||
|
@ -22,6 +23,7 @@ impl TextBox {
|
|||
font: TextBoxFont,
|
||||
justify: TextBoxJustify,
|
||||
rect: Rect,
|
||||
color: api::Color,
|
||||
) -> Self {
|
||||
let mut buffer = Buffer::new(
|
||||
&mut state.text_font_system,
|
||||
|
@ -37,6 +39,7 @@ impl TextBox {
|
|||
justify,
|
||||
rect,
|
||||
buffer,
|
||||
color,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +76,7 @@ impl<'a, 'b: 'a> TextBox {
|
|||
state.window_size.height as f32 / 2.0 - (rect.pos.y * fac + rect.dim.y / 2.0),
|
||||
);
|
||||
let corner_sw = corner_ne + rect.dim * fac;
|
||||
let c = self.color.as_array_u8();
|
||||
|
||||
TextArea {
|
||||
buffer: &self.buffer,
|
||||
|
@ -85,7 +89,7 @@ impl<'a, 'b: 'a> TextBox {
|
|||
left: (corner_ne.x) as i32,
|
||||
right: (corner_sw.x) as i32,
|
||||
},
|
||||
default_color: Color::rgb(255, 255, 255),
|
||||
default_color: Color::rgba(c[0], c[1], c[2], c[3]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue