-
Finn Bear authoredd6e9024a
s1_title.rs 2.84 KiB
use crate::component::image::Image;
use crate::egui::{Align2, Context};
use crate::fade_in::fade_in;
use crate::slide::Slide;
use crate::{ctx_img, Margin};
use eframe::egui::{Frame, TextureHandle, Ui, Vec2, Window};
/// The first slide in the cartoon.
#[derive(Default)]
pub struct Title {
examples: Vec<TextureHandle>,
state: TitleState,
}
#[derive(Default)]
enum TitleState {
#[default]
Initial,
Title {
// When we started fading in the title.
fade_start: f64,
},
}
impl Slide for Title {
fn transition(&mut self, ctx: &Context) -> bool {
match &self.state {
TitleState::Initial => {
self.state = TitleState::Title {
fade_start: ctx.input().time,
}
}
TitleState::Title { .. } => return true,
}
false
}
fn show(&mut self, ui: &mut Ui) {
if self.examples.is_empty() {
// For now, these images are somewhat like placeholders.
self.examples = vec![
ctx_img!(ui.ctx(), "abstract0.png"),
ctx_img!(ui.ctx(), "atom0.png"),
ctx_img!(ui.ctx(), "raymarching0.png"),
ctx_img!(ui.ctx(), "fluid0.png"),
ctx_img!(ui.ctx(), "raymarching1.png"),
ctx_img!(ui.ctx(), "atom2.png"),
ctx_img!(ui.ctx(), "raytracing0.png"),
ctx_img!(ui.ctx(), "slime0.png"),
ctx_img!(ui.ctx(), "atom1.png"),
ctx_img!(ui.ctx(), "abstract1.png"),
ctx_img!(ui.ctx(), "slime1.png"),
];
}
for example in &self.examples {
Image::default().height(ui.available_height() * 0.295).show(ui, example);
}
if let &TitleState::Title { fade_start } = &self.state {
fade_in(ui, fade_start, |ui| {
ui.scope(|ui| {
// Extra large margins for title window.
ui.style_mut().spacing.window_margin = Margin::same(20.0);
Window::new("title")
.title_bar(false)
.resizable(false)
.anchor(Align2::CENTER_CENTER, Vec2::ZERO)
.default_width(400.0)
.frame(Frame::window(ui.style()))
.show(ui.ctx(), |ui| {
// Nested fade since fade doesn't propagate through window.
fade_in(ui, fade_start, |ui| {
ui.vertical_centered(|ui| {
ui.heading("Generative Art");
ui.label("By: Finn, Matthew, Nathan, Owen");
});
});
});
});
});
}
}
}