Use current_exe for default window title (#18553)
# Objective - We currently default to "App" for the window title, it would be nice if examples had more descriptive names ## Solution - Use `std::env::current_exe` to try to figure out a default title. If it's not present. Use "App". ## Testing - I tested that examples that set a custom title still use the custom title and that examples without a custom title use the example name --- ### Showcase Here's the 3d_scene example:  ### Notes Here's a previous attempt at this from a few years ago https://github.com/bevyengine/bevy/pull/3404 There's some relevant discussion in there, but cart's decision was to default to "App" when no name was found. --------- Co-authored-by: Zachary Harrold <zac@harrold.com.au>
This commit is contained in:
parent
a02cdaa017
commit
f0503930df
@ -1,4 +1,4 @@
|
||||
use alloc::{borrow::ToOwned, string::String};
|
||||
use alloc::{borrow::ToOwned, format, string::String};
|
||||
use core::num::NonZero;
|
||||
|
||||
use bevy_ecs::{
|
||||
@ -6,6 +6,7 @@ use bevy_ecs::{
|
||||
prelude::Component,
|
||||
};
|
||||
use bevy_math::{CompassOctant, DVec2, IVec2, UVec2, Vec2};
|
||||
use bevy_platform_support::sync::LazyLock;
|
||||
use log::warn;
|
||||
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
@ -19,6 +20,24 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||
|
||||
use crate::VideoMode;
|
||||
|
||||
/// Default string used for the window title.
|
||||
///
|
||||
/// It will try to use the name of the current exe if possible, otherwise it defaults to "App"
|
||||
static DEFAULT_WINDOW_TITLE: LazyLock<String> = LazyLock::new(|| {
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|current_exe| Some(format!("{}", current_exe.file_stem()?.to_string_lossy())))
|
||||
.unwrap_or_else(|| "App".to_owned())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
{
|
||||
"App".to_owned()
|
||||
}
|
||||
});
|
||||
|
||||
/// Marker [`Component`] for the window considered the primary window.
|
||||
///
|
||||
/// Currently this is assumed to only exist on 1 entity at a time.
|
||||
@ -429,7 +448,7 @@ pub struct Window {
|
||||
impl Default for Window {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: "App".to_owned(),
|
||||
title: DEFAULT_WINDOW_TITLE.to_owned(),
|
||||
name: None,
|
||||
cursor_options: Default::default(),
|
||||
present_mode: Default::default(),
|
||||
|
Loading…
Reference in New Issue
Block a user