introduce View and Previews traits

In this commit we refactor the preview mechanism, and switch to
responsive views by default.

To create a preview, your view now has to implement the Preview trait.
This is very similar to SwiftUI's preview mechanism.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-04-19 14:09:19 -07:00
parent a5e1fbf328
commit a71e8206fb
11 changed files with 313 additions and 284 deletions

View File

@@ -1,11 +1,17 @@
pub mod note;
pub mod preview;
pub mod username;
pub use note::Note;
pub use preview::{Preview, PreviewApp};
pub use username::Username;
use egui::Margin;
pub trait View {
fn ui(&mut self, ui: &mut egui::Ui);
}
pub fn padding<R>(
amount: impl Into<Margin>,
ui: &mut egui::Ui,
@@ -15,3 +21,9 @@ pub fn padding<R>(
.inner_margin(amount)
.show(ui, add_contents)
}
pub fn is_mobile(ctx: &egui::Context) -> bool {
//true
let screen_size = ctx.screen_rect().size();
screen_size.x < 550.0
}