Skip to content

Commit

Permalink
Moar progrezz.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuteler committed Sep 1, 2024
1 parent 3ed4bd5 commit 9bd279e
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 22 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy::{
};
use micronos::{
plugins::Timeline,
resources::ChronoSphere,
resources::{ChronoSphere, Fonts, Icons},
systems::{
print_chrono_sphere,
update_chrono_sphere,
Expand Down Expand Up @@ -40,6 +40,8 @@ fn main() {
// ClearColor must have 0 alpha, otherwise some color will bleed through
.insert_resource(ClearColor(Color::NONE))
.init_resource::<ChronoSphere>()
.init_resource::<Fonts>()
.init_resource::<Icons>()
.add_plugins(Timeline)
.add_systems(Startup, setup_camera)
.add_systems(Update, update_chrono_sphere)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod panel;
pub mod timeline;

pub use timeline::Timeline;
7 changes: 7 additions & 0 deletions src/plugins/panel/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// TODO
// reusable panel component with:
// ________________
// [ title, actions ]
// [ body ]
// [ footer? ]
// ________________
26 changes: 17 additions & 9 deletions src/plugins/timeline/systems/layout.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use bevy::prelude::*;

use crate::resources::ChronoSphere;
use crate::systems::get_chrono_sphere_hh;

use super::components::{Active, CurrentTimeText, Hour};
use crate::resources::{Fonts, Icons};
use super::components::CurrentTimeText;
use super::layout_bundles::{
create_app_grid_bundle,
create_empty_grid_area,
Expand All @@ -15,15 +13,14 @@ use super::layout_bundles::{
use super::topbar::spawn_topbar_contents;
use super::timeline::spawn_timeline_body_contents;

pub fn spawn_ui(mut cmd: Commands, asset_server: Res<AssetServer>) {
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
pub fn spawn_ui(mut cmd: Commands, asset_server: Res<AssetServer>, fonts: Res<Fonts>, icons: Res<Icons>) {
// App container
let all_father = cmd.spawn(create_app_grid_bundle()).id();
// Col 1 row 1
let empty_row = cmd.spawn(create_empty_grid_area()).id();
// Col 1 row 2
let topbar = cmd.spawn(create_topbar_grid_area()).id();
let topbar_contents = spawn_topbar_contents(&mut cmd, &asset_server);
let topbar_contents = spawn_topbar_contents(&mut cmd, &fonts, &icons); // todo: decouple system
cmd.entity(topbar).push_children(&[topbar_contents]);
// Col 1 row 3
let timeline_header = cmd.spawn(create_timeline_header_grid_area())
Expand All @@ -34,6 +31,7 @@ pub fn spawn_ui(mut cmd: Commands, asset_server: Res<AssetServer>) {
TextBundle::from_section(
"CurrentTime",
TextStyle {
font: fonts.bold.clone(),
font_size: 14.0,
..default()
},
Expand All @@ -44,16 +42,26 @@ pub fn spawn_ui(mut cmd: Commands, asset_server: Res<AssetServer>) {
.id();
// Col 1 row 4
let timeline_body = cmd.spawn(create_timeline_body_grid_area()).id();
let timeline_body_contents = spawn_timeline_body_contents(&mut cmd, asset_server);
let timeline_body_contents = spawn_timeline_body_contents(&mut cmd, asset_server); // todo: decouple system
cmd.entity(timeline_body).push_children(&[timeline_body_contents]);

// Col 2 row 1-4
let side_modal = cmd.spawn(create_side_panel_grid_area())
.with_children(|builder| {
spawn_nested_text_bundle(builder, font.clone(), "Side modal", 18.)
spawn_nested_text_bundle(builder, fonts.medium.clone(), "Side modal", 18.)
})
.id();

cmd.entity(all_father).push_children(&[empty_row,topbar,timeline_header,timeline_body,side_modal]);
}

fn spawn_nested_text_bundle(builder: &mut ChildBuilder, font: Handle<Font>, text: &str, font_size: f32) {
builder.spawn(TextBundle::from_section(
text,
TextStyle {
font,
font_size,
color: Color::BLACK,
},
));
}
4 changes: 2 additions & 2 deletions src/plugins/timeline/systems/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ pub fn spawn_timeline_body_contents(cmd: &mut Commands, asset_server: Res<AssetS
}

pub fn update_active_hour(
mut cmd: Commands,
// mut cmd: Commands,
hours: Query<(Entity, &Hour)>,
chronos: Res<ChronoSphere>
) {
// Current time?
let hh = get_chrono_sphere_hh(chronos);
// for hour in &hours {
for (ent, hour) in hours.iter() {
for (_ent, hour) in hours.iter() {
if hh.to_string().eq(&hour.to_string()) {
// cmd.entity(hour).insert(Active);
info!("{} is {}", hh.to_string(), "active".to_string());
Expand Down
11 changes: 4 additions & 7 deletions src/plugins/timeline/systems/topbar.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
use bevy::prelude::*;

use crate::resources::{Fonts, Icons};
use super::topbar_bundles::{
create_row_container,
create_title,
};

pub fn spawn_topbar_contents(cmd: &mut Commands, asset_server: &Res<AssetServer>) -> Entity {
pub fn spawn_topbar_contents(cmd: &mut Commands, fonts: &Res<Fonts>, icons: &Res<Icons>) -> Entity {
// Spawn a flex container to insert in the grid area, and hold the topbar elements
let flex_row_container = cmd.spawn(create_row_container()).id();

// TODO: load fonts once, centrally?
let font = asset_server.load("fonts/FiraMono-Medium.ttf");

let title = cmd.spawn(create_title("Micronos", font.clone())).id();
let title = cmd.spawn(create_title("Micronos", fonts.bold.clone())).id();

// collapse icon
let sprite_handle = asset_server.load("icons/collapse_content_24dp_000000_FILL0_wght400_GRAD0_opsz24.png"); // 580 x 140 px
let collapse_img_bundle = ImageBundle {
style: Style {
width: Val::Px(24.),
height: Val::Px(24.),
..default()
},
image: UiImage {
texture: sprite_handle.clone(),
texture: icons.collapse.clone(),
..default()
},
..default()
Expand Down
2 changes: 1 addition & 1 deletion src/resources.rs → src/resources/chronosphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ impl Default for ChronoSphere {
fn default() -> Self {
Self::new()
}
}
}
19 changes: 19 additions & 0 deletions src/resources/fonts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

use bevy::prelude::*;

#[derive(Resource)]
pub struct Fonts {
pub bold: Handle<Font>,
pub medium: Handle<Font>,
}

impl FromWorld for Fonts {
fn from_world(world: &mut World) -> Self {
let bold = world.resource::<AssetServer>().load("fonts/FiraSans-Bold.ttf");
let medium = world.resource::<AssetServer>().load("fonts/FiraMono-Medium.ttf");
Self {
bold,
medium,
}
}
}
19 changes: 19 additions & 0 deletions src/resources/icons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

use bevy::prelude::*;

#[derive(Resource)]
pub struct Icons {
pub collapse: Handle<Image>,
pub expand: Handle<Image>,
}

impl FromWorld for Icons {
fn from_world(world: &mut World) -> Self {
let collapse = world.resource::<AssetServer>().load("icons/collapse_content_24dp_000000_FILL0_wght400_GRAD0_opsz24.png");
let expand = world.resource::<AssetServer>().load("icons/expand_content_24dp_000000_FILL0_wght400_GRAD0_opsz24.png");
Self {
collapse,
expand,
}
}
}
7 changes: 7 additions & 0 deletions src/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod chronosphere;
pub mod fonts;
pub mod icons;

pub use chronosphere::ChronoSphere;
pub use fonts::Fonts;
pub use icons::Icons;
5 changes: 3 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TODO>
add icon to toggle window decorations
Reusable panel plugin.
add icon to toggle side panel visibility
HourBox adaptive render? active == bold
Pomodoros!
Features!
- Pomodoros ftw.

0 comments on commit 9bd279e

Please sign in to comment.