Skip to content

Commit

Permalink
Move non-theme things from theme to config
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 10, 2023
1 parent d6db882 commit 490b92e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 126 deletions.
88 changes: 27 additions & 61 deletions assets/config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -43,134 +43,100 @@
),

editor_screen: EditorScreenConfig(
scene_view_background_color: Rgba(red: 0.671, green: 0.710, blue: 0.722, alpha: 1.000),
info_bar_height: Px(60.0),
info_bar_font_size: Px(32.0),

outline_panel_width: Px(280.0),
outline_panel_font_size: Px(16.0),
outline_panel_header_font_size: Px(24.0),

scene_view_background_color: Rgba(red: 0.500, green: 0.500, blue: 0.500, alpha: 1.000),

code_panel_height: Px(200.0),
code_panel_font_size: Px(16.0),
code_panel_lines_max: 10,

upgrade_panel_width: Px(280.0),
upgrade_panel_header_font_size: Px(24.0),

upgrade_button_height: Px(56.0),
upgrade_button_font_size: Px(16.0),

separator_width: Px(4.0),

submit_button_height: Px(76.0),
submit_button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
submit_button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
submit_button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
submit_button_text_color: Rgba(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000),
submit_button_font_size: Px(32.0),

light_theme: EditorScreenTheme(
info_bar_height: Px(60.0),
info_bar_background_color: Rgba(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.000),
info_bar_text_color: Rgba(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.000),
info_bar_font_size: Px(32.0),

outline_panel_width: Px(280.0),
outline_panel_background_color: Rgba(red: 0.8, green: 0.8, blue: 0.8, alpha: 1.000),
outline_panel_highlight_color: Rgba(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.000),
outline_panel_text_color: Rgba(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.000),
outline_panel_font_size: Px(16.0),
outline_panel_header_font_size: Px(24.0),

code_panel_height: Px(200.0),
code_panel_background_color: Rgba(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.000),
code_panel_text_color: Rgba(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.000),
code_panel_font_size: Px(16.0),
code_panel_lines_max: 10,

upgrade_panel_width: Px(280.0),
upgrade_panel_background_color: Rgba(red: 0.8, green: 0.8, blue: 0.8, alpha: 1.000),
upgrade_panel_text_color: Rgba(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.000),
upgrade_panel_header_font_size: Px(24.0),

upgrade_button_height: Px(56.0),
upgrade_button_normal_color: Rgba(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.000),
upgrade_button_hovered_color: Rgba(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.000),
upgrade_button_pressed_color: Rgba(red: 0.55, green: 0.55, blue: 0.55, alpha: 1.000),
upgrade_button_disabled_color: Rgba(red: 0.086, green: 0.082, blue: 0.133, alpha: 1.000),
upgrade_button_text_color: Rgba(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.000),
upgrade_button_font_size: Px(16.0),

submit_button_height: Px(76.0),
submit_button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
submit_button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
submit_button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
submit_button_text_color: Rgba(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000),
submit_button_font_size: Px(32.0),

separator_width: Px(4.0),
separator_color: Rgba(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.000),
),

dracula_theme: EditorScreenTheme(
info_bar_height: Px(60.0),
info_bar_background_color: Rgba(red: 0.086, green: 0.082, blue: 0.133, alpha: 1.000),
info_bar_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
info_bar_font_size: Px(32.0),

outline_panel_width: Px(280.0),
outline_panel_background_color: Rgba(red: 0.184, green: 0.188, blue: 0.239, alpha: 1.000),
outline_panel_highlight_color: Rgba(red: 0.263, green: 0.275, blue: 0.318, alpha: 1.000),
outline_panel_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
outline_panel_font_size: Px(16.0),
outline_panel_header_font_size: Px(24.0),

code_panel_height: Px(200.0),
code_panel_background_color: Rgba(red: 0.086, green: 0.082, blue: 0.133, alpha: 1.000),
code_panel_text_color: Rgba(red: 0.300, green: 0.900, blue: 0.000, alpha: 1.000),
code_panel_font_size: Px(16.0),
code_panel_lines_max: 10,

upgrade_panel_width: Px(280.0),
upgrade_panel_background_color: Rgba(red: 0.184, green: 0.188, blue: 0.239, alpha: 1.000),
upgrade_panel_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
upgrade_panel_header_font_size: Px(24.0),

upgrade_button_height: Px(56.0),
upgrade_button_normal_color: Rgba(red: 0.353, green: 0.373, blue: 0.416, alpha: 1.000),
upgrade_button_hovered_color: Rgba(red: 0.471, green: 0.506, blue: 0.529, alpha: 1.000),
upgrade_button_pressed_color: Rgba(red: 0.086, green: 0.082, blue: 0.133, alpha: 1.000),
upgrade_button_disabled_color: Rgba(red: 0.086, green: 0.082, blue: 0.133, alpha: 1.000),
upgrade_button_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
upgrade_button_font_size: Px(16.0),

submit_button_height: Px(76.0),
submit_button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
submit_button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
submit_button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
submit_button_text_color: Rgba(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000),
submit_button_font_size: Px(32.0),

separator_width: Px(2.0),
separator_color: Rgba(red: 0.353, green: 0.373, blue: 0.416, alpha: 1.000),
),

bamboo_theme: EditorScreenTheme(
info_bar_height: Px(60.0),
info_bar_background_color: Rgba(red: 0.10, green: 0.11, blue: 0.12, alpha: 1.000),
info_bar_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
info_bar_font_size: Px(32.0),

outline_panel_width: Px(280.0),
outline_panel_background_color: Rgba(red: 0.165, green: 0.18, blue: 0.184, alpha: 1.000),
outline_panel_highlight_color: Rgba(red: 0.265, green: 0.28, blue: 0.284, alpha: 1.000),
outline_panel_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
outline_panel_font_size: Px(16.0),
outline_panel_header_font_size: Px(24.0),

code_panel_height: Px(200.0),
code_panel_background_color: Rgba(red: 0.10, green: 0.11, blue: 0.12, alpha: 1.000),
code_panel_text_color: Rgba(red: 0.300, green: 0.900, blue: 0.000, alpha: 1.000),
code_panel_font_size: Px(16.0),
code_panel_lines_max: 10,

upgrade_panel_width: Px(280.0),
upgrade_panel_background_color: Rgba(red: 0.165, green: 0.18, blue: 0.184, alpha: 1.000),
upgrade_panel_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
upgrade_panel_header_font_size: Px(24.0),

upgrade_button_height: Px(56.0),
upgrade_button_normal_color: Rgba(red: 0.265, green: 0.28, blue: 0.284, alpha: 1.000),
upgrade_button_hovered_color: Rgba(red: 0.365, green: 0.38, blue: 0.384, alpha: 1.000),
upgrade_button_pressed_color: Rgba(red: 0.165, green: 0.18, blue: 0.184, alpha: 1.000),
upgrade_button_disabled_color: Rgba(red: 0.065, green: 0.08, blue: 0.084, alpha: 1.000),
upgrade_button_text_color: Rgba(red: 0.800, green: 0.800, blue: 0.800, alpha: 1.000),
upgrade_button_font_size: Px(16.0),

submit_button_height: Px(76.0),
submit_button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
submit_button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
submit_button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
submit_button_text_color: Rgba(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000),
submit_button_font_size: Px(32.0),

separator_width: Px(2.0),
separator_color: Rgba(red: 0.265, green: 0.28, blue: 0.284, alpha: 1.000),
),
),
Expand Down
61 changes: 34 additions & 27 deletions src/state/editor_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,58 @@ impl Plugin for EditorScreenStatePlugin {

#[derive(Default, Reflect, Serialize, Deserialize, Clone)]
pub struct EditorScreenTheme {
info_bar_height: Val,
info_bar_background_color: Color,
info_bar_text_color: Color,
info_bar_font_size: Val,

outline_panel_width: Val,
outline_panel_background_color: Color,
outline_panel_highlight_color: Color,
outline_panel_text_color: Color,
outline_panel_font_size: Val,
outline_panel_header_font_size: Val,

code_panel_height: Val,
code_panel_background_color: Color,
code_panel_text_color: Color,
code_panel_font_size: Val,
code_panel_lines_max: usize,

upgrade_panel_width: Val,
upgrade_panel_background_color: Color,
upgrade_panel_text_color: Color,
upgrade_panel_header_font_size: Val,

upgrade_button_height: Val,
upgrade_button_normal_color: Color,
upgrade_button_hovered_color: Color,
upgrade_button_pressed_color: Color,
upgrade_button_disabled_color: Color,
upgrade_button_text_color: Color,

separator_color: Color,
}

#[derive(Default, Reflect, Serialize, Deserialize)]
pub struct EditorScreenConfig {
scene_view_background_color: Color,

info_bar_height: Val,
info_bar_font_size: Val,

outline_panel_width: Val,
outline_panel_font_size: Val,
outline_panel_header_font_size: Val,

code_panel_height: Val,
code_panel_font_size: Val,
code_panel_lines_max: usize,

upgrade_panel_width: Val,
upgrade_panel_header_font_size: Val,

upgrade_button_height: Val,
upgrade_button_font_size: Val,

separator_width: Val,

submit_button_height: Val,
submit_button_normal_color: Color,
submit_button_hovered_color: Color,
submit_button_pressed_color: Color,
submit_button_text_color: Color,
submit_button_font_size: Val,

separator_width: Val,
separator_color: Color,
}

#[derive(Default, Reflect, Serialize, Deserialize)]
pub struct EditorScreenConfig {
scene_view_background_color: Color,

pub light_theme: EditorScreenTheme,
pub dracula_theme: EditorScreenTheme,
pub bamboo_theme: EditorScreenTheme,
Expand Down Expand Up @@ -119,13 +125,14 @@ fn enter_editor_screen(
commands.insert_resource(ClearColor(config.scene_view_background_color));
commands.insert_resource(EditorScreenStartTime(time.elapsed_seconds_f64()));

let screen = spawn_editor_screen(&mut commands, config.light_theme.clone(), true);
let screen = spawn_editor_screen(&mut commands, &config, &config.light_theme, true);
commands.entity(screen).set_parent(root.ui);
}

pub fn spawn_editor_screen(
commands: &mut Commands,
theme: EditorScreenTheme,
config: &EditorScreenConfig,
theme: &EditorScreenTheme,
light_mode: bool,
) -> Entity {
let editor_screen = commands
Expand All @@ -143,7 +150,7 @@ pub fn spawn_editor_screen(
))
.id();

let info_bar = spawn_info_bar(commands, &theme);
let info_bar = spawn_info_bar(commands, config, theme);
commands.entity(info_bar).set_parent(editor_screen);

let hbox = commands
Expand All @@ -161,7 +168,7 @@ pub fn spawn_editor_screen(
.set_parent(editor_screen)
.id();

let outline_panel = spawn_outline_panel(commands, &theme);
let outline_panel = spawn_outline_panel(commands, config, theme);
commands.entity(outline_panel).set_parent(hbox);

let vbox = commands
Expand All @@ -184,16 +191,16 @@ pub fn spawn_editor_screen(
commands.entity(scene_view).set_parent(vbox);

let code_panel = if light_mode {
spawn_light_code_panel(commands, &theme)
spawn_light_code_panel(commands, config, theme)
} else {
spawn_code_panel(commands, &theme)
spawn_code_panel(commands, config, theme)
};
commands.entity(code_panel).set_parent(vbox);

let upgrade_panel = spawn_upgrade_panel(commands, &theme);
let upgrade_panel = spawn_upgrade_panel(commands, config, theme);
commands.entity(upgrade_panel).set_parent(hbox);

commands.insert_resource(ActiveEditorTheme(theme));
commands.insert_resource(ActiveEditorTheme(theme.clone()));

editor_screen
}
Expand Down
23 changes: 16 additions & 7 deletions src/state/editor_screen/code_panel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::prelude::*;
use bevy::ui::Val::*;

use super::EditorScreenConfig;
use crate::state::editor_screen::EditorScreenTheme;
use crate::ui::CodeTyper;
use crate::ui::FontSize;
Expand All @@ -15,14 +16,18 @@ I need to install a dark theme from the panel on the right.
The installed upgrades will appear on the left panel.";

/// Spawns the fake code panel with light theme.
pub fn spawn_light_code_panel(commands: &mut Commands, theme: &EditorScreenTheme) -> Entity {
pub fn spawn_light_code_panel(
commands: &mut Commands,
config: &EditorScreenConfig,
theme: &EditorScreenTheme,
) -> Entity {
let code_panel = commands
.spawn((
Name::new("CodePanel"),
NodeBundle {
style: Style {
width: Percent(100.0),
min_height: theme.code_panel_height,
min_height: config.code_panel_height,
padding: UiRect::all(VMin(2.0)),
..default()
},
Expand All @@ -43,21 +48,25 @@ pub fn spawn_light_code_panel(commands: &mut Commands, theme: &EditorScreenTheme
..default()
},
),
FontSize::new(theme.code_panel_font_size),
FontSize::new(config.code_panel_font_size),
))
.set_parent(code_panel);

code_panel
}

pub fn spawn_code_panel(commands: &mut Commands, theme: &EditorScreenTheme) -> Entity {
pub fn spawn_code_panel(
commands: &mut Commands,
config: &EditorScreenConfig,
theme: &EditorScreenTheme,
) -> Entity {
let code_panel = commands
.spawn((
Name::new("CodePanel"),
NodeBundle {
style: Style {
width: Percent(100.0),
min_height: theme.code_panel_height,
min_height: config.code_panel_height,
padding: UiRect::all(VMin(2.0)),
..default()
},
Expand All @@ -79,10 +88,10 @@ pub fn spawn_code_panel(commands: &mut Commands, theme: &EditorScreenTheme) -> E
},
)
.with_no_wrap(),
FontSize::new(theme.code_panel_font_size),
FontSize::new(config.code_panel_font_size),
CodeTyper {
lines_count: 1,
lines_max: theme.code_panel_lines_max,
lines_max: config.code_panel_lines_max,
..default()
},
))
Expand Down
Loading

0 comments on commit 490b92e

Please sign in to comment.