use bevy::prelude::*;
use jackdaw::prelude::*;
use jackdaw_feathers::{
button::{ButtonProps, button},
tokens::FONT_MD,
};
fn main() -> AppExit {
App::new()
.set_error_handler(bevy::ecs::error::error)
.add_plugins((
DefaultPlugins,
EditorPlugins::default()
.set(ExtensionPlugin::default().with_extension::<WindowExampleExtension>()),
))
.run()
}
#[derive(Default)]
pub struct WindowExampleExtension;
impl JackdawExtension for WindowExampleExtension {
fn id(&self) -> String {
"widget_showcase".to_string()
}
fn label(&self) -> String {
"Widget Showcase".to_string()
}
fn description(&self) -> String {
"Adds a new window chock-full of all our widgets.".to_string()
}
fn register(&self, ctx: &mut ExtensionContext) {
ctx.register_operator::<OnButtonPressOp>().register_window(
WindowDescriptor::new("widget_showcase.window")
.with_name("Widget Showcase")
.with_default_area(DefaultArea::RightSidebar)
.with_build(|window| {
window.spawn((
Text::new("Here's a label"),
TextFont::from_font_size(FONT_MD),
));
window.spawn(button(ButtonProps::from_operator::<OnButtonPressOp>()));
}),
);
}
}
#[operator(
id = "widget_showcase.button_operator",
label = "Button connected to an operator",
description = "Does nothing, but is called when the button is pressed."
)]
fn on_button_press(_: In<OperatorParameters>) -> OperatorResult {
OperatorResult::Finished
}