Skip to content

Commit

Permalink
feat!: use slider for increasing font sizes instead of adaptive zooming
Browse files Browse the repository at this point in the history
  • Loading branch information
carrascomj committed Jan 16, 2025
1 parent f1e6796 commit cfee4fe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 40 deletions.
6 changes: 5 additions & 1 deletion src/escher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::funcplot::draw_arrow;
use crate::geom::{GeomHist, HistTag, Side, Xaxis};
use crate::info::Info;
use crate::scale::DefaultFontSize;
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy_prototype_lyon::prelude::*;
Expand Down Expand Up @@ -359,6 +358,11 @@ pub struct MapDimensions {
pub y: f32,
}

#[derive(Component)]
pub struct DefaultFontSize {
pub size: f32,
}

/// Load escher map once the asset is available.
/// The colors correspond to the default escher colors.
pub fn load_map(
Expand Down
23 changes: 20 additions & 3 deletions src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Gui (windows and panels) to upload data and hover.
use crate::data::{Data, ReactionState};
use crate::escher::DefaultFontSize;
use crate::escher::{EscherMap, MapState};
use crate::geom::{AnyTag, Xaxis};
use crate::info::Info;
Expand All @@ -25,7 +26,8 @@ impl Plugin for GuiPlugin {
.insert_resource(ActiveData::default())
.add_event::<SaveEvent>()
.add_systems(Update, ui_settings)
.add_systems(Update, scale_ui);
.add_systems(Update, scale_ui)
.add_systems(Update, update_text_sizes);

// file drop and file system does not work in WASM
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -85,8 +87,7 @@ pub struct UiState {
pub data_path: String,
pub screen_path: String,
pub hide: bool,
// since this type and field are private, Self has to be initialized
// with Default::default(), ensuring that the fallbacks for colors (empty string) are set.
pub font_scale: f32,
_init: Init,
}

Expand All @@ -107,6 +108,7 @@ impl Default for UiState {
max_left: 100.,
max_right: 100.,
max_top: 100.,
font_scale: 1.0,
color_left: {
let mut color = HashMap::new();
color.insert(
Expand Down Expand Up @@ -224,6 +226,11 @@ pub fn ui_settings(
}
egui::Window::new("Settings").show(egui_context.ctx_mut(), |ui| {
ui.visuals_mut().override_text_color = Some(egui::Color32::WHITE);

ui.label("Text Scale");
ui.add(egui::Slider::new(&mut state.font_scale, 0.5..=2.0).text("Scale"));
ui.separator();

for (geom, ext) in ["Reaction", "Metabolite"]
.into_iter()
.cartesian_product(["min", "max"])
Expand Down Expand Up @@ -371,6 +378,16 @@ fn scale_ui(
}
}

/// Update all text components when the font scale changes in UI settings
fn update_text_sizes(
state: Res<UiState>,
mut text_query: Query<(&mut TextFont, &DefaultFontSize)>,
) {
for (mut text_font, default_size) in text_query.iter_mut() {
text_font.font_size = default_size.size * state.font_scale;
}
}

/// Save map to arbitrary place, including (non-hover) hist transforms.
fn save_file(
mut assets: ResMut<Assets<EscherMap>>,
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod gui;
mod info;
mod legend;
mod picking;
mod scale;
mod screenshot;
#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -48,7 +47,6 @@ fn main() {
.add_plugins(data::DataPlugin)
.add_systems(Startup, setup_system)
.add_plugins(aesthetics::AesPlugin)
.add_plugins(scale::ZoomPlugin)
.add_plugins(legend::LegendPlugin)
.run();
}
Expand Down
34 changes: 0 additions & 34 deletions src/scale.rs

This file was deleted.

0 comments on commit cfee4fe

Please sign in to comment.