Skip to content

Commit

Permalink
Added font-based resizing to the splits component
Browse files Browse the repository at this point in the history
Fixed a compiler error and removed a useless line

fixed a compiler error

ran clippy

Added font-based resizing to the splits component
  • Loading branch information
Hurricane996 committed Aug 15, 2022
1 parent 623ae0a commit b34e9dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/rendering/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ pub fn width(component: &ComponentState) -> f32 {
ComponentState::Separator(_) => SEPARATOR_THICKNESS,
ComponentState::Splits(state) => {
let column_count = 2.0; // FIXME: Not always 2.
let split_width = 2.0 + column_count * splits::COLUMN_WIDTH;
let column_width = 2.75; // FIXME: Not always 2.75; difficult to calculate without a renderer.
let split_width = 2.0 + column_count * column_width;
state.splits.len() as f32 * split_width
}
ComponentState::Text(_) => 6.0,
Expand Down
16 changes: 12 additions & 4 deletions src/rendering/component/splits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ use crate::{
settings::{Gradient, ListGradient},
};

pub const COLUMN_WIDTH: f32 = 2.75;

pub struct Cache<I, L> {
icons: Vec<Option<Icon<I>>>,
splits: Vec<SplitCache<L>>,
column_labels: Vec<CachedLabel<L>>,
column_width_label: CachedLabel<L>,
}

struct SplitCache<L> {
Expand All @@ -44,6 +43,7 @@ impl<I, L> Cache<I, L> {
icons: Vec::new(),
splits: Vec::new(),
column_labels: Vec::new(),
column_width_label: CachedLabel::new(),
}
}
}
Expand All @@ -55,6 +55,9 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
component: &State,
layout_state: &LayoutState,
) {
let column_width =
context.measure_numbers("24:00:00", &mut cache.column_width_label, DEFAULT_TEXT_SIZE);

let text_color = solid(&layout_state.text_color);

let split_background = match component.background {
Expand Down Expand Up @@ -115,7 +118,12 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(

let mut right_x = width - PADDING;
for (label, cache) in column_labels.iter().zip(&mut cache.column_labels) {
let left_x = right_x - COLUMN_WIDTH;
// TODO In LiveSplit desktop, the column width varies based on whether or not the current column tracks
// delta, with delta column width being `measure_width("9:00:00")` and regular column width being
// `measure_width("24:00:00")`. Implementing this in livesplit-core requires tracking column types in
// `splits::State`, which I don't feel like doing right now.
let left_x = right_x - column_width;

context.render_text_right_align(
label,
cache,
Expand Down Expand Up @@ -189,7 +197,7 @@ pub(in crate::rendering) fn render<A: ResourceAllocator>(
solid(&column.visual_color),
);
}
right_x -= COLUMN_WIDTH;
right_x -= column_width;
}

if display_two_rows {
Expand Down

0 comments on commit b34e9dc

Please sign in to comment.