From a47e790c101064999f52239b072a0d0012a9f4be Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Thu, 8 Dec 2022 04:46:37 +0000
Subject: [PATCH] Remove dead code from UI widgets

---
 game_core/src/ui/components/button.rs       | 14 ++++++------
 game_core/src/ui/components/image_button.rs | 24 ++-------------------
 game_core/src/ui/mod.rs                     |  3 ---
 game_core/src/ui/widgets/encounter_panel.rs |  5 +----
 game_core/src/ui/widgets/stats_panel.rs     | 15 +------------
 game_core/src/ui/widgets/town_menu.rs       | 18 ----------------
 6 files changed, 10 insertions(+), 69 deletions(-)

diff --git a/game_core/src/ui/components/button.rs b/game_core/src/ui/components/button.rs
index 89d6d06..8d4947e 100644
--- a/game_core/src/ui/components/button.rs
+++ b/game_core/src/ui/components/button.rs
@@ -134,6 +134,9 @@ pub fn render_button_widget(
 				},
 			);
 
+			// Setting the root width to "Units::Auto" will not take into account text width, but we don't
+			// want to have to guess at a correct width to manually set whenever we create a button. Do
+			// some text measurements so we can set an exact button size based on content & font size
 			let font_data = fonts.get(&assets.kayak_font("equipment_pro")).unwrap();
 			let content_measurement = font_data.measure(
 				props.text.as_str(),
@@ -151,6 +154,9 @@ pub fn render_button_widget(
 			let button_height = text_height + (edge_padding * 2.0); // + 8.0;
 			let mut button_width = text_width + (edge_padding * 2.0) + 8.0;
 
+			// Icons use "props.font_size" for their width / height, have a 4px padding on either side
+			// and are laid out by their parent with a column gap of 15 - combine to get additional
+			// width required for each icon
 			if !props.left_icon.is_none() {
 				button_width += props.font_size + 23.0;
 			}
@@ -232,16 +238,12 @@ pub fn render_button_widget(
 				KStyle {
 					top: px(6.0),
 					bottom: px(16.0),
-					// right: px(4.0),
-					// left: px(4.0),
 					..Default::default()
 				}
 			} else {
 				KStyle {
 					top: px(3.0),
 					bottom: px(19.0),
-					// right: px(4.0),
-					// left: px(4.0),
 					..Default::default()
 				}
 			});
@@ -253,16 +255,12 @@ pub fn render_button_widget(
 				KStyle {
 					padding_top: px(11.0),
 					padding_bottom: px(11.0),
-					// padding_right: px(4.0),
-					// padding_left: px(4.0),
 					..Default::default()
 				}
 			} else {
 				KStyle {
 					padding_top: px(8.0),
 					padding_bottom: px(14.0),
-					// padding_right: px(4.0),
-					// padding_left: px(4.0),
 					..Default::default()
 				}
 			});
diff --git a/game_core/src/ui/components/image_button.rs b/game_core/src/ui/components/image_button.rs
index fc6626a..84d1e35 100644
--- a/game_core/src/ui/components/image_button.rs
+++ b/game_core/src/ui/components/image_button.rs
@@ -1,14 +1,12 @@
 use bevy::prelude::*;
 use kayak_ui::prelude::*;
 use kayak_ui::widgets::{
-	KImage, KImageBundle, NinePatch, NinePatchBundle, TextProps, TextWidgetBundle,
-	TextureAtlasBundle, TextureAtlasProps,
+	KImage, KImageBundle, NinePatch, NinePatchBundle, TextureAtlasBundle, TextureAtlasProps,
 };
-use kayak_ui::DEFAULT_FONT;
 
 use crate::assets::AssetHandles;
 use crate::parent_widget;
-use crate::ui::prelude::{edge_px, px, stretch, value};
+use crate::ui::prelude::{px, stretch, value};
 
 #[derive(Component, Clone, Eq, PartialEq, Default)]
 pub enum ImageButtonContent {
@@ -163,20 +161,6 @@ pub fn render_image_button_widget(
 				))
 			};
 
-			// let styles = KStyle {
-			// 	padding,
-			// 	..Default::default()
-			// }
-			// .with_style(style)
-			// .with_style(KStyle {
-			// 	width: stretch(1.0),
-			// 	height: px(48.0),
-			// 	bottom: px(20.0),
-			// 	min_height: px(32.0),
-			// 	min_width: px(48.0),
-			// 	..Default::default()
-			// });
-
 			*computed = KStyle {
 				render_command: value(RenderCommand::Layout),
 				min_height: px(32.0),
@@ -196,10 +180,6 @@ pub fn render_image_button_widget(
 				background_color: Color::RED.into(),
 				width: stretch(1.0),
 				height: stretch(1.0),
-				// padding_left: px(12.0),
-				// padding_right: px(12.0),
-				// padding_top: px(20.0),
-				// padding_bottom: px(20.0),
 				..Default::default()
 			};
 
diff --git a/game_core/src/ui/mod.rs b/game_core/src/ui/mod.rs
index 50ed8ea..c9ea135 100644
--- a/game_core/src/ui/mod.rs
+++ b/game_core/src/ui/mod.rs
@@ -2,7 +2,6 @@ use bevy::app::{PluginGroup, PluginGroupBuilder};
 use kayak_ui::prelude::KayakContextPlugin;
 use kayak_ui::widgets::KayakWidgets;
 
-// pub mod clrs;
 pub mod components;
 pub mod screens;
 pub mod sync;
@@ -68,9 +67,7 @@ mod _config {
 
 	use crate::assets::AssetHandles;
 	use crate::system::flow::AppState;
-	use crate::ui::components::cursor_animation_system;
 	use crate::ui::utilities::StateUIRoot;
-	// use crate::ui::utilities::App;
 
 	pub fn configure_kayak_ui(
 		mut commands: Commands,
diff --git a/game_core/src/ui/widgets/encounter_panel.rs b/game_core/src/ui/widgets/encounter_panel.rs
index 39fa308..c0583bf 100644
--- a/game_core/src/ui/widgets/encounter_panel.rs
+++ b/game_core/src/ui/widgets/encounter_panel.rs
@@ -5,13 +5,10 @@ use kayak_ui::widgets::{
 	TextProps, TextWidgetBundle,
 };
 
-use crate::assets::AssetHandles;
-use crate::states::Player;
 use crate::ui::components::*;
 use crate::ui::prelude::*;
-use crate::ui::sync::UITravelInfo;
 use crate::ui::widgets::*;
-use crate::world::{CurrentResidence, EncounterState, MapQuery, TownPaths};
+use crate::world::EncounterState;
 use crate::{basic_widget, empty_props, on_button_click};
 
 empty_props!(EncounterPanelProps);
diff --git a/game_core/src/ui/widgets/stats_panel.rs b/game_core/src/ui/widgets/stats_panel.rs
index c1c7432..65f5660 100644
--- a/game_core/src/ui/widgets/stats_panel.rs
+++ b/game_core/src/ui/widgets/stats_panel.rs
@@ -16,20 +16,7 @@ pub fn render_stats_panel(
 	ui_data: Res<UIStatsData>,
 ) -> bool {
 	let parent_id = Some(entity);
-	// let root_style = KStyle {
-	// 	position_type: value(KPositionType::SelfDirected),
-	// 	top: stretch(1.0),
-	// 	left: stretch(1.0),
-	// 	right: stretch(1.0),
-	// 	bottom: px(50.0),
-	// 	height: px(50.0),
-	// 	width: stretch(0.6),
-	// 	max_width: px(200.0),
-	// 	layout_type: value(LayoutType::Row),
-	// 	padding: value(Edge::all(Units::Stretch(1.0))),
-	// 	..Default::default()
-	// };
-	//
+
 	let root_style = KStyle {
 		position_type: value(KPositionType::SelfDirected),
 		top: px(15.0),
diff --git a/game_core/src/ui/widgets/town_menu.rs b/game_core/src/ui/widgets/town_menu.rs
index 8eedbe1..95e5024 100644
--- a/game_core/src/ui/widgets/town_menu.rs
+++ b/game_core/src/ui/widgets/town_menu.rs
@@ -125,12 +125,6 @@ pub fn render_town_menu_panel(
 					..Default::default()
 				}}>
 					<ButtonWidget
-						styles={KStyle {
-							// width: px(225.0),
-							// padding_left: px(30.0),
-							// padding_right: px(20.0),
-							..Default::default()
-						}}
 						props={ButtonWidgetProps {
 							left_icon: IconContent::Atlas(String::from("icons"), 4),
 							..ButtonWidgetProps::text("Travel", 28.0)
@@ -138,12 +132,6 @@ pub fn render_town_menu_panel(
 						on_event={click_tab_travel}
 					/>
 					<ButtonWidget
-						styles={KStyle {
-							// width: px(260.0),
-							// padding_left: px(30.0),
-							// padding_right: px(20.0),
-							..Default::default()
-						}}
 						props={ButtonWidgetProps {
 							left_icon: IconContent::Atlas(String::from("icons"), 9),
 							..ButtonWidgetProps::text("Merchant", 28.0)
@@ -151,12 +139,6 @@ pub fn render_town_menu_panel(
 						on_event={click_tab_merchant}
 					/>
 					<ButtonWidget
-						styles={KStyle {
-							// width: px(225.0),
-							// padding_left: px(30.0),
-							// padding_right: px(20.0),
-							..Default::default()
-						}}
 						props={ButtonWidgetProps {
 							left_icon: IconContent::Atlas(String::from("icons"), 11),
 							..ButtonWidgetProps::text("Tavern", 28.0)
-- 
GitLab