feat: add basis of login section to startup view

Former-commit-id: 871f14b95f00e607fc41d3f72d20e384fd9952e6
This commit is contained in:
Muhammad Nauman Raza 2023-11-28 14:18:26 +00:00
parent 7f8b09ee9f
commit dbf4ae5c10
Signed by: devraza
GPG key ID: 91EAD6081011574B
2 changed files with 81 additions and 36 deletions

16
Cargo.lock generated
View file

@ -136,6 +136,14 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "ambition"
version = "0.1.0"
dependencies = [
"bevy",
"lazy_static",
]
[[package]] [[package]]
name = "android-activity" name = "android-activity"
version = "0.4.3" version = "0.4.3"
@ -205,14 +213,6 @@ dependencies = [
"libloading 0.7.4", "libloading 0.7.4",
] ]
[[package]]
name = "aspiration"
version = "0.1.0"
dependencies = [
"bevy",
"lazy_static",
]
[[package]] [[package]]
name = "async-broadcast" name = "async-broadcast"
version = "0.5.1" version = "0.5.1"

View file

@ -2,11 +2,16 @@ use bevy::{
core_pipeline::{ core_pipeline::{
tonemapping::Tonemapping, tonemapping::Tonemapping,
}, },
window::*,
prelude::*, prelude::*,
winit::WinitSettings,
}; };
use std::collections::HashMap; use std::collections::HashMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
const VERSION: &str = env!("CARGO_PKG_VERSION");
const PKGNAME: &str = env!("CARGO_PKG_NAME");
// Create a map of the Hypernova colorscheme // Create a map of the Hypernova colorscheme
lazy_static!{ lazy_static!{
static ref HYPERNOVA: HashMap<&'static str, Color> = vec![ static ref HYPERNOVA: HashMap<&'static str, Color> = vec![
@ -15,7 +20,7 @@ lazy_static!{
("GRAY", Color::hex("27272b").unwrap()), ("GRAY", Color::hex("27272b").unwrap()),
("LIGHT_GRAY", Color::hex("454449").unwrap()), ("LIGHT_GRAY", Color::hex("454449").unwrap()),
("SUBTEXT", Color::hex("d9d0d7").unwrap()), ("SUBTEXT", Color::hex("d9d0d7").unwrap()),
("WHITE", Color::hex("fefefa").unwrap()), ("WHITE", Color::hex("ece5ea").unwrap()),
("RED", Color::hex("f06969").unwrap()), ("RED", Color::hex("f06969").unwrap()),
("MAGENTA", Color::hex("e887bb").unwrap()), ("MAGENTA", Color::hex("e887bb").unwrap()),
("PURPLE", Color::hex("a292e8").unwrap()), ("PURPLE", Color::hex("a292e8").unwrap()),
@ -26,12 +31,31 @@ lazy_static!{
].iter().copied().collect(); ].iter().copied().collect();
} }
fn titlecase(s: &str) -> String {
let mut c = s.chars();
match c.next() {
None => String::new(),
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
}
}
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) // Only run the app when there is user input, significantly reducing CPU/GPU usage
.insert_resource(WinitSettings::desktop_app())
.add_plugins(
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: format!("{} {}", titlecase(PKGNAME), VERSION).into(),
mode: WindowMode::Fullscreen,
..default()
}),
..default()
})
)
.add_systems( .add_systems(
Startup, Startup,
(setup, render_ui) (setup, setup_ui)
) )
.run(); .run();
} }
@ -49,56 +73,77 @@ fn setup(mut commands: Commands) {
); );
} }
fn render_ui( fn setup_ui(
server: Res<AssetServer>, server: Res<AssetServer>,
mut commands: Commands mut commands: Commands
) { ) {
let bold_font: Handle<Font> = server.load("fonts/VictorMono-Bold.otf"); let bold_font: Handle<Font> = server.load("fonts/VictorMono-Bold.otf");
let regular_font: Handle<Font> = server.load("fonts/VictorMono-Regular.otf"); let regular_font: Handle<Font> = server.load("fonts/VictorMono-Regular.otf");
let text_style = TextStyle { let title_style = TextStyle {
font: bold_font.clone(), font: bold_font.clone(),
font_size: 80.0, font_size: 70.,
color: Color::WHITE, color: HYPERNOVA.get("WHITE").copied().unwrap(),
}; };
let login_style = TextStyle {
font: bold_font.clone(),
font_size: 30.,
color: HYPERNOVA.get("PURPLE").copied().unwrap(),
};
commands commands
.spawn(NodeBundle { .spawn(NodeBundle {
style: Style { style: Style {
width: Val::Percent(100.), width: Val::Percent(100.),
height: Val::Percent(100.0), height: Val::Percent(100.0),
justify_content: JustifyContent::SpaceBetween, flex_direction: FlexDirection::Column,
..Default::default() align_items: AlignItems::Center,
..default()
}, },
background_color: BackgroundColor(HYPERNOVA.get("DARK_GRAY").copied().unwrap()), background_color: BackgroundColor(HYPERNOVA.get("DARK_GRAY").copied().unwrap()),
..Default::default() ..default()
}) })
.with_children(|parent| { .with_children(|parent| {
parent
.spawn(TextBundle::from_section("Ambition", title_style.clone())
.with_text_alignment(TextAlignment::Center)
.with_style(Style {
position_type: PositionType::Absolute,
margin: UiRect {
top: Val::Vh(10.),
..default()
},
..default()
})
);
parent parent
.spawn(NodeBundle { .spawn(NodeBundle {
style: Style { style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
align_items: AlignItems::Center, align_items: AlignItems::Center,
..Default::default() width: Val::Percent(50.),
height: Val::Percent(40.),
margin: UiRect {
top: Val::Vh(30.),
..default()
},
padding: UiRect {
top: Val::Percent(2.),
..default()
},
..default()
}, },
background_color: BackgroundColor(HYPERNOVA.get("DARK_GRAY").copied().unwrap()), background_color: BackgroundColor(HYPERNOVA.get("GRAY").copied().unwrap()),
..Default::default() ..default()
}) })
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn(TextBundle::from_section("Ambition", text_style.clone()) .spawn(TextBundle::from_section("Login", login_style.clone())
.with_text_alignment(TextAlignment::Center) .with_text_alignment(TextAlignment::Center)
.with_style(Style { .with_style(Style {
position_type: PositionType::Absolute, position_type: PositionType::Absolute,
margin: UiRect { ..default()
top: Val::Percent(10.), }));
..default()
},
..default()
})
);
}); });
} });
);
} }