summaryrefslogtreecommitdiffstats
path: root/src/ui.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-05-03 17:31:47 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-05-03 17:31:47 -0400
commit759d5d27c7773c7fe8b165ce08b57204db990b74 (patch)
treeb9fd06e7b76490ba15dd3a87d83253a7b0bd68cf /src/ui.rs
parentb14dd1c1f3e198137fa8b9e0c4f5e56949b11cd0 (diff)
downloadsystemic4x-759d5d27c7773c7fe8b165ce08b57204db990b74.tar.gz
systemic4x-759d5d27c7773c7fe8b165ce08b57204db990b74.tar.bz2
systemic4x-759d5d27c7773c7fe8b165ce08b57204db990b74.zip
move topbar ui rendering into it's own module
Diffstat (limited to 'src/ui.rs')
-rw-r--r--src/ui.rs91
1 files changed, 8 insertions, 83 deletions
diff --git a/src/ui.rs b/src/ui.rs
index 42e5fa8..ab75001 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -1,10 +1,11 @@
+pub mod topbar;
pub mod camera_info;
use std::cell::RefCell;
use cgmath::Vector3;
-use crate::{GameState, eguictx::EguiCtx, solar_system, timeman::{self, Second, TimeMan}, ui::camera_info::CameraWindowState};
+use crate::{GameState, eguictx::EguiCtx, solar_system, timeman::{self, Second, TimeMan}, ui::{camera_info::CameraWindowState, topbar::TopBarState}};
mod ui {
pub use super::camera_info;
@@ -13,10 +14,7 @@ mod ui {
#[derive(Default, Clone)]
pub struct State
{
- pub current_system: Option<solar_system::SystemId>,
- pub auto_time: Option<Second>,
- pub do_auto_tick: bool,
-
+ pub topbar_sate: TopBarState,
pub camera_info: CameraWindowState
}
@@ -27,87 +25,14 @@ impl State
game_state: &RefCell<GameState>,
eguictx: &EguiCtx)
{
- State::render_topbar(self, game_state, eguictx);
-
+ TopBarState::render(
+ &mut self.topbar_sate,
+ game_state,
+ eguictx);
+
CameraWindowState::render(
self,
game_state,
eguictx);
}
-
- fn render_topbar(
- state: &mut State,
- game_state: &RefCell<GameState>,
- eguictx: &EguiCtx)
- {
- let mut game_state = game_state.borrow_mut();
-
- egui::TopBottomPanel::top("topbar").show(
- eguictx.context(),
- |ui| {
-
- ui.horizontal(|ui| {
- let solar_systems = game_state.solar_systems();
- let selected_system_label = match state.current_system {
- Some(id) => solar_systems[id].name(),
- None => ""
- };
-
- egui::ComboBox::from_label("Current System")
- .selected_text(selected_system_label)
- .show_ui(ui, |ui| {
-
- for (i, system) in solar_systems.iter().enumerate() {
- ui.selectable_value(
- &mut state.current_system,
- Some(i),
- system.name()
- );
- }
- });
- });
-
- ui.horizontal(|ui| {
- let time_str = TimeMan::format_duration(game_state.timeman().seconds());
- ui.label(
- egui::RichText::new(format!("Time: {: >16}", time_str))
- .font(egui::FontId::monospace(12.0))
- );
-
- let button_seconds = [
- 1,
- 5,
- 30,
- timeman::MINUTE,
- timeman::MINUTE * 5,
- timeman::MINUTE * 30,
- timeman::HOUR,
- timeman::DAY,
- timeman::DAY * 5,
- timeman::YEAR
- ];
- let selected_button = state.auto_time;
-
- button_seconds.iter().for_each(|&seconds| {
- ui.vertical(|ui| {
- let auto_selected = match selected_button {
- Some(o) => o == seconds,
- None => false
- };
- let label = TimeMan::format_duration(seconds);
-
- if ui.button(label.clone()).clicked() {
- game_state.timeman_mut().advance(seconds);
- }
-
- if ui.add(egui::Button::new(label.clone()).selected(auto_selected)).clicked() {
- state.auto_time = Some(seconds);
- }
- });
- });
-
- ui.checkbox(&mut state.do_auto_tick, "Auto");
- });
- });
- }
}