136 lines
4.3 KiB
Rust
136 lines
4.3 KiB
Rust
//! Native offline layer positioning workspace.
|
||
use eframe::egui::{self, Align2, Color32, FontId, Pos2, Rect, Stroke, StrokeKind, Vec2};
|
||
|
||
const BG: Color32 = Color32::from_rgb(17, 23, 32);
|
||
const PANEL: Color32 = Color32::from_rgb(27, 35, 48);
|
||
const FIELD: Color32 = Color32::from_rgb(18, 26, 37);
|
||
const LINE: Color32 = Color32::from_rgb(53, 68, 88);
|
||
const TEXT: Color32 = Color32::from_rgb(237, 243, 252);
|
||
const MUTED: Color32 = Color32::from_rgb(165, 181, 201);
|
||
const CYAN: Color32 = Color32::from_rgb(102, 219, 239);
|
||
const AMBER: Color32 = Color32::from_rgb(246, 197, 119);
|
||
const PURPLE: Color32 = Color32::from_rgb(102, 85, 217);
|
||
|
||
fn main() -> eframe::Result {
|
||
eframe::run_native(
|
||
"Midra Layout",
|
||
eframe::NativeOptions {
|
||
viewport: egui::ViewportBuilder::default()
|
||
.with_inner_size([1440.0, 940.0])
|
||
.with_min_inner_size([1000.0, 720.0]),
|
||
..Default::default()
|
||
},
|
||
Box::new(|cc| {
|
||
let mut style = (*cc.egui_ctx.style()).clone();
|
||
style.visuals = egui::Visuals::dark();
|
||
style.visuals.extreme_bg_color = FIELD;
|
||
style.visuals.selection.bg_fill = PURPLE;
|
||
style.visuals.widgets.inactive.bg_fill = FIELD;
|
||
style.visuals.widgets.inactive.bg_stroke = Stroke::new(1.0_f32, LINE);
|
||
style.spacing.item_spacing = Vec2::new(12.0, 10.0);
|
||
cc.egui_ctx.set_style(style);
|
||
Ok(Box::new(gui::Editor::default()))
|
||
}),
|
||
)
|
||
}
|
||
|
||
mod gui;
|
||
mod reference;
|
||
|
||
/// Draw in local logical points; viewport artwork alone uses a fitted scale.
|
||
struct Ink {
|
||
painter: egui::Painter,
|
||
origin: Pos2,
|
||
scale: f32,
|
||
}
|
||
|
||
impl Ink {
|
||
fn new(ui: &egui::Ui, rect: Rect) -> Self {
|
||
Self {
|
||
painter: ui.painter_at(rect),
|
||
origin: rect.min,
|
||
scale: 1.0,
|
||
}
|
||
}
|
||
|
||
fn point(&self, x: f32, y: f32) -> Pos2 {
|
||
self.origin + Vec2::new(x, y) * self.scale
|
||
}
|
||
|
||
fn rect(&self, x: f32, y: f32, w: f32, h: f32, fill: Color32) {
|
||
self.painter.rect_filled(
|
||
Rect::from_min_size(self.point(x, y), Vec2::new(w, h) * self.scale),
|
||
0.0,
|
||
fill,
|
||
);
|
||
}
|
||
|
||
fn card(&self, x: f32, y: f32, w: f32, h: f32, fill: Color32, border: Color32) {
|
||
self.painter.rect(
|
||
Rect::from_min_size(self.point(x, y), Vec2::new(w, h) * self.scale),
|
||
5.0,
|
||
fill,
|
||
Stroke::new(1.0_f32, border),
|
||
StrokeKind::Inside,
|
||
);
|
||
}
|
||
|
||
fn text(&self, x: f32, y: f32, text: &str, size: f32, color: Color32) {
|
||
self.painter.text(
|
||
self.point(x, y),
|
||
Align2::LEFT_TOP,
|
||
text,
|
||
FontId::proportional(size * self.scale),
|
||
color,
|
||
);
|
||
}
|
||
|
||
fn line(&self, from: [f32; 2], to: [f32; 2], color: Color32) {
|
||
self.painter.line_segment(
|
||
[self.point(from[0], from[1]), self.point(to[0], to[1])],
|
||
Stroke::new(1.0_f32, color),
|
||
);
|
||
}
|
||
|
||
fn button(&self, x: f32, y: f32, w: f32, label: &str, primary: bool) {
|
||
self.card(x, y, w, 34.0, if primary { PURPLE } else { FIELD }, LINE);
|
||
self.text(x + 12.0, y + 9.0, label, 13.0, TEXT);
|
||
}
|
||
|
||
fn field(&self, x: f32, y: f32, w: f32, label: &str, value: &str) {
|
||
self.text(x, y, label, 12.0, MUTED);
|
||
self.card(x, y + 23.0, w, 42.0, FIELD, LINE);
|
||
self.text(x + 12.0, y + 34.0, value, 18.0, TEXT);
|
||
}
|
||
}
|
||
|
||
fn screen_artwork(ink: &Ink) {
|
||
ink.text(0.0, -24.0, "SCREEN 1", 12.0, MUTED);
|
||
ink.text(790.0, -24.0, "1920 × 1080 px", 13.0, MUTED);
|
||
ink.rect(0.0, 0.0, 960.0, 540.0, Color32::from_rgb(20, 45, 64));
|
||
ink.rect(0.0, 0.0, 960.0, 36.0, Color32::from_rgb(38, 69, 86));
|
||
ink.text(24.0, 10.0, "ANNUAL FORUM / MAIN STAGE", 13.0, MUTED);
|
||
for x in (0..=1920).step_by(240) {
|
||
ink.line(
|
||
[x as f32 / 2.0, 36.0],
|
||
[x as f32 / 2.0, 540.0],
|
||
Color32::from_rgb(39, 71, 90),
|
||
);
|
||
}
|
||
for y in (180..=1080).step_by(180) {
|
||
ink.line(
|
||
[0.0, y as f32 / 2.0],
|
||
[960.0, y as f32 / 2.0],
|
||
Color32::from_rgb(39, 71, 90),
|
||
);
|
||
}
|
||
ink.text(24.0, 462.0, "Ideas worth sharing.", 27.0, MUTED);
|
||
ink.text(
|
||
24.0,
|
||
503.0,
|
||
"Illustrative reference artwork · opacity 65%",
|
||
12.0,
|
||
MUTED,
|
||
);
|
||
}
|