Skip to content

Commit 1c9415f

Browse files
committed
Final cleanup
The text shadow support should now mostly be ready.
1 parent 86573c0 commit 1c9415f

File tree

15 files changed

+125
-164
lines changed

15 files changed

+125
-164
lines changed

capi/src/server_protocol.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub struct ServerProtocol {}
1919
impl ServerProtocol {
2020
/// Handles an incoming command and returns the response to be sent.
2121
pub async unsafe fn handleCommand(command: &str, commandSink: *const CommandSink) -> String {
22-
server_protocol::handle_command(command, &*commandSink).await
22+
// SAFETY: The caller must ensure that the pointer is valid.
23+
server_protocol::handle_command(command, unsafe { &*commandSink }).await
2324
}
2425

2526
/// Encodes an event that happened to be sent.

capi/src/web_rendering.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ impl WebRenderer {
4141
state: *const LayoutState,
4242
image_cache: *const ImageCache,
4343
) -> Option<Box<[f32]>> {
44-
self.inner.render(&*state, &*image_cache).map(Box::from)
44+
// SAFETY: The caller must ensure that the pointers are valid.
45+
unsafe {
46+
self.inner.render(&*state, &*image_cache).map(Box::from)
47+
}
4548
}
4649
}

src/layout/general_settings.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ pub struct GeneralSettings {
2222
/// The font to use for regular text. `None` means a default font should be
2323
/// used.
2424
pub text_font: Option<Font>,
25+
/// The color to use for drawn shadows.
26+
pub text_shadow: Option<Color>,
2527
/// The background to show behind the layout.
2628
pub background: LayoutBackground,
27-
/// The color to use for drawn shadows.
28-
pub shadow_color: Option<Color>,
29-
/// Draw drop shadow
30-
pub drop_shadow: bool,
3129
/// The color to use for when the runner achieved a best segment.
3230
pub best_segment_color: Color,
3331
/// The color to use for when the runner is ahead of the comparison and is
@@ -63,11 +61,10 @@ impl Default for GeneralSettings {
6361
timer_font: None,
6462
times_font: None,
6563
text_font: None,
64+
text_shadow: Some(Color::hsla(0.0, 0.0, 0.0, 0.5)),
6665
background: LayoutBackground::Gradient(Gradient::Plain(Color::hsla(
6766
0.0, 0.0, 0.06, 1.0,
6867
))),
69-
shadow_color: Some(Color::hsla(0.0, 0.0, 0.0, 0.5)),
70-
drop_shadow: false,
7168
best_segment_color: Color::hsla(50.0, 1.0, 0.5, 1.0),
7269
ahead_gaining_time_color: Color::hsla(136.0, 1.0, 0.4, 1.0),
7370
ahead_losing_time_color: Color::hsla(136.0, 0.55, 0.6, 1.0),
@@ -116,14 +113,9 @@ impl GeneralSettings {
116113
self.text_font.clone().into(),
117114
),
118115
Field::new(
119-
"Drop Shadow".into(),
120-
"Draws shadow behind timer & splits".into(),
121-
self.drop_shadow.into(),
122-
),
123-
Field::new(
124-
"Shadow".into(),
125-
"The color to use for drawn shadows.".into(),
126-
self.shadow_color.into(),
116+
"Text Shadow".into(),
117+
"Allows you to optionally specify a color for text shadows.".into(),
118+
self.text_shadow.into(),
127119
),
128120
Field::new(
129121
"Background".into(),
@@ -205,20 +197,19 @@ impl GeneralSettings {
205197
1 => self.timer_font = value.into(),
206198
2 => self.times_font = value.into(),
207199
3 => self.text_font = value.into(),
208-
4 => self.drop_shadow = value.into(),
209-
5 => self.shadow_color = value.into(),
210-
6 => self.background = LayoutBackground::from(value).from_cache(image_cache),
211-
7 => self.best_segment_color = value.into(),
212-
8 => self.ahead_gaining_time_color = value.into(),
213-
9 => self.ahead_losing_time_color = value.into(),
214-
10 => self.behind_gaining_time_color = value.into(),
215-
11 => self.behind_losing_time_color = value.into(),
216-
12 => self.not_running_color = value.into(),
217-
13 => self.personal_best_color = value.into(),
218-
14 => self.paused_color = value.into(),
219-
15 => self.thin_separators_color = value.into(),
220-
16 => self.separators_color = value.into(),
221-
17 => self.text_color = value.into(),
200+
4 => self.text_shadow = value.into(),
201+
5 => self.background = LayoutBackground::from(value).from_cache(image_cache),
202+
6 => self.best_segment_color = value.into(),
203+
7 => self.ahead_gaining_time_color = value.into(),
204+
8 => self.ahead_losing_time_color = value.into(),
205+
9 => self.behind_gaining_time_color = value.into(),
206+
10 => self.behind_losing_time_color = value.into(),
207+
11 => self.not_running_color = value.into(),
208+
12 => self.personal_best_color = value.into(),
209+
13 => self.paused_color = value.into(),
210+
14 => self.thin_separators_color = value.into(),
211+
15 => self.separators_color = value.into(),
212+
16 => self.text_color = value.into(),
222213
_ => panic!("Unsupported Setting Index"),
223214
}
224215
}

src/layout/layout_state.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub struct LayoutState {
2222
/// The font to use for regular text. `None` means a default font should be
2323
/// used.
2424
pub text_font: Option<Font>,
25+
/// An optional text shadow color.
26+
pub text_shadow: Option<Color>,
2527
/// The background to show behind the layout.
2628
pub background: LayoutBackground<ImageId>,
2729
/// The color of thin separators.
@@ -30,10 +32,6 @@ pub struct LayoutState {
3032
pub separators_color: Color,
3133
/// The text color to use for text that doesn't specify its own color.
3234
pub text_color: Color,
33-
/// Draws drop shadow
34-
pub drop_shadow: bool,
35-
/// The color to use for drawn shadows.
36-
pub shadow_color: Option<Color>,
3735
}
3836

3937
#[cfg(feature = "std")]

src/layout/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ impl Layout {
119119
state.separators_color = settings.separators_color;
120120
state.text_color = settings.text_color;
121121
state.direction = settings.direction;
122-
state.drop_shadow = settings.drop_shadow;
123-
state.shadow_color = settings.shadow_color;
122+
state.text_shadow = settings.text_shadow;
124123
}
125124

126125
/// Calculates the layout's state based on the timer provided. You can use

src/layout/parser/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ fn parse_general_settings(layout: &mut Layout, reader: &mut Reader<'_>) -> Resul
708708
let mut background_image = None;
709709
let mut image_opacity = 1.0;
710710
let mut image_blur = 0.0;
711+
let mut has_text_shadow = false;
712+
let mut text_shadow_color = Color::transparent();
711713

712714
parse_children(reader, |reader, tag, _| match tag.name() {
713715
"TextColor" => color(reader, |color| {
@@ -779,13 +781,13 @@ fn parse_general_settings(layout: &mut Layout, reader: &mut Reader<'_>) -> Resul
779781
}),
780782
"ImageOpacity" => percentage(reader, |v| image_opacity = v),
781783
"ImageBlur" => percentage(reader, |v| image_blur = v),
782-
"DropShadows" => parse_bool(reader, |b| settings.drop_shadow = b),
783-
"ShadowsColor" => color(reader, |color| {
784-
settings.shadow_color = Some(color);
785-
}),
784+
"DropShadows" => parse_bool(reader, |b| has_text_shadow = b),
785+
"ShadowsColor" => color(reader, |color| text_shadow_color = color),
786786
_ => end_tag(reader),
787787
})?;
788788

789+
settings.text_shadow = has_text_shadow.then_some(text_shadow_color);
790+
789791
settings.background = match background_builder.build() {
790792
Some(gradient) => LayoutBackground::Gradient(gradient),
791793
None => match background_image {

src/rendering/component/detailed_timer.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use crate::{
22
component::detailed_timer::State,
33
layout::LayoutState,
44
rendering::{
5+
RenderContext,
56
component::timer,
6-
consts::{vertical_padding, BOTH_PADDINGS, PADDING},
7+
consts::{BOTH_PADDINGS, PADDING, vertical_padding},
78
font::CachedLabel,
89
resource::ResourceAllocator,
910
scene::Layer,
10-
solid, RenderContext,
11+
solid,
1112
},
1213
};
1314

@@ -43,9 +44,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
4344
layout_state: &LayoutState,
4445
) {
4546
context.render_background([width, height], &component.background);
46-
47-
let shadow_offset = [0.05, 0.05];
48-
let shadow_color = solid(&layout_state.shadow_color.unwrap_or_default());
4947

5048
let vertical_padding = vertical_padding(height);
5149
let icon_size = height - 2.0 * vertical_padding;
@@ -81,8 +79,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
8179
[left_side, 0.6 * top_height],
8280
0.5 * top_height,
8381
segment_name_color,
84-
shadow_offset,
85-
shadow_color,
8682
timer_end,
8783
);
8884
}
@@ -117,8 +113,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
117113
[left_side, comparison2_y],
118114
comparison_text_scale,
119115
comparison_names_color,
120-
shadow_offset,
121-
shadow_color,
122116
segment_timer_end,
123117
)
124118
.max(name_end);
@@ -144,8 +138,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
144138
[left_side, comparison1_y],
145139
comparison_text_scale,
146140
comparison_names_color,
147-
shadow_offset,
148-
shadow_color,
149141
segment_timer_end,
150142
)
151143
.max(name_end);
@@ -174,8 +166,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
174166
[time_x, comparison2_y],
175167
comparison_text_scale,
176168
comparison_times_color,
177-
shadow_offset,
178-
shadow_color,
179169
);
180170
}
181171
if let Some(comparison) = &component.comparison1 {
@@ -186,8 +176,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
186176
[time_x, comparison1_y],
187177
comparison_text_scale,
188178
comparison_times_color,
189-
shadow_offset,
190-
shadow_color,
191179
);
192180
}
193181
}

src/rendering/component/key_value.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::{
22
component::key_value::State,
33
layout::{LayoutDirection, LayoutState},
44
rendering::{
5+
RenderContext,
56
font::{AbbreviatedLabel, CachedLabel},
67
resource::ResourceAllocator,
7-
RenderContext,
88
},
99
};
1010

@@ -31,8 +31,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
3131
) {
3232
context.render_background(dim, &component.background);
3333

34-
let shadow_offset = [0.05, 0.05];
35-
let shadow_color = layout_state.shadow_color;
3634
context.render_key_value_component(
3735
&component.key,
3836
&component.key_abbreviations,
@@ -41,9 +39,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
4139
&mut cache.value,
4240
component.updates_frequently,
4341
dim,
44-
shadow_offset,
45-
shadow_color.unwrap_or_default(),
46-
shadow_color.unwrap_or_default(),
4742
component.key_color.unwrap_or(layout_state.text_color),
4843
component.value_color.unwrap_or(layout_state.text_color),
4944
component.display_two_rows || layout_state.direction == LayoutDirection::Horizontal,

src/rendering/component/splits.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
185185
let transform = context.transform;
186186
let text_color = solid(&layout_state.text_color);
187187

188-
let shadow_offset = [0.05, 0.05];
189-
let shadow_color = solid(&layout_state.shadow_color.unwrap_or_default());
190188
if let Some(column_labels) = &component.column_labels {
191189
if layout_state.direction == LayoutDirection::Vertical {
192190
cache
@@ -206,8 +204,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
206204
[right_x, TEXT_ALIGN_TOP],
207205
DEFAULT_TEXT_SIZE,
208206
text_color,
209-
shadow_offset,
210-
shadow_color,
211207
);
212208
let label_width = right_x - left_x;
213209
if label_width > *max_width {
@@ -281,8 +277,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
281277
[right_x, split_height + TEXT_ALIGN_BOTTOM],
282278
DEFAULT_TEXT_SIZE,
283279
solid(&column.visual_color),
284-
shadow_offset,
285-
shadow_color,
286280
);
287281
}
288282
right_x -= max_width + PADDING;
@@ -298,8 +292,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
298292
[icon_right, TEXT_ALIGN_TOP],
299293
DEFAULT_TEXT_SIZE,
300294
text_color,
301-
shadow_offset,
302-
shadow_color,
303295
left_x - PADDING,
304296
);
305297
}

src/rendering/component/text.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use crate::{
22
component::text::{State, TextState},
33
layout::{LayoutDirection, LayoutState},
44
rendering::{
5+
RenderContext,
56
consts::{DEFAULT_TEXT_SIZE, PADDING, TEXT_ALIGN_TOP},
67
font::{AbbreviatedLabel, CachedLabel},
78
resource::ResourceAllocator,
8-
solid, RenderContext,
9+
solid,
910
},
1011
};
1112

@@ -31,8 +32,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
3132
layout_state: &LayoutState,
3233
) {
3334
context.render_background([width, height], &component.background);
34-
let shadow_offset = [0.05, 0.05];
35-
let shadow_color = layout_state.shadow_color;
3635

3736
match &component.text {
3837
TextState::Center(text) => context.render_text_centered(
@@ -47,8 +46,6 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
4746
.left_center_color
4847
.unwrap_or(layout_state.text_color),
4948
),
50-
shadow_offset,
51-
solid(&shadow_color.unwrap_or_default()),
5249
),
5350
TextState::Split(left, right) => context.render_key_value_component(
5451
left,
@@ -58,10 +55,9 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
5855
&mut cache.label2,
5956
false,
6057
[width, height],
61-
shadow_offset,
62-
shadow_color.unwrap_or_default(),
63-
shadow_color.unwrap_or_default(),
64-
component.left_center_color.unwrap_or(layout_state.text_color),
58+
component
59+
.left_center_color
60+
.unwrap_or(layout_state.text_color),
6561
component.right_color.unwrap_or(layout_state.text_color),
6662
component.display_two_rows || layout_state.direction == LayoutDirection::Horizontal,
6763
),

0 commit comments

Comments
 (0)