d84914ef1e5a
toolbar.rs
//! Context controls, view and mode buttons, tool shelf, icon rail and status bar
use egui::{RichText, vec2};
use egui_phosphor::regular as ic;
use serde_json::json;
use texturecraft_engine::Tool;
use crate::TextureCraftApp;
use crate::docking::Panel;
use crate::i18n::{tr, trf};
use crate::keymap::{shortcut_of, tip};
use crate::state::{Mode, ViewLayout};
use crate::theme::{GUTTER, Tokens, card};
use crate::widgets::{bar_slider, icon_button, icon_button_without_tooltip, icon_dropdown_button, icon_dropdown_button_width};
const BAR_SPACING: f32 = 10.0;
const COMPACT_BAR_SPACING: f32 = 4.0;
const BAR_SEPARATOR_WIDTH: f32 = 6.0;
/// Height of the top bar, in points
const BAR_HEIGHT: f32 = 40.0;
/// Padding inside the top bar card on its left and right, in points
const BAR_PADDING: egui::Margin = egui::Margin::symmetric(8, 0);
pub fn tool_icon(tool: Tool) -> &'static str {
match tool {
Tool::Paint => ic::PAINT_BRUSH,
Tool::Eraser => ic::ERASER,
Tool::Projection => ic::CUBE_FOCUS,
Tool::PolygonFill => ic::POLYGON,
Tool::Smudge => ic::FINGERPRINT,
Tool::Clone => ic::STAMP,
Tool::ColorPicker => ic::EYEDROPPER,
Tool::Path => ic::PEN_NIB_STRAIGHT,
Tool::GeometryMask => ic::SELECTION_SLASH,
}
}
/// Keep mode buttons visible, with painting controls scrolling as space runs out
pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let tokens = Tokens::get(ui.ctx());
egui::Panel::top("paint_bar").exact_size(BAR_HEIGHT).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| {
card(ui, &tokens, egui::Margin { bottom: GUTTER, ..Default::default() }, BAR_PADDING, |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let button_size = ui.spacing().interact_size.y;
let mode_width = 3.0 * button_size + 2.0 * BAR_SPACING;
let separator_width = BAR_SEPARATOR_WIDTH + 2.0 * BAR_SPACING;
// Leave room for both scroll arrows and at least one button of content
let minimum_strip_width = 3.0 * button_size + 2.0 * BAR_SPACING;
let scroll_views =
ui.available_width() < mode_width + view_buttons_width(button_size, BAR_SPACING) + 2.0 * separator_width + minimum_strip_width;
ui.spacing_mut().item_spacing.x = if scroll_views { COMPACT_BAR_SPACING } else { BAR_SPACING };
mode_buttons(app, ui);
if app.ui.mode != Mode::Painting {
return;
}
ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH));
if !scroll_views {
view_buttons(app, ui);
if app.session.tool_usable(app.session.tool.tool) {
ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH));
}
}
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
scrolling_tool_controls(app, ui, &tokens, scroll_views);
});
});
});
});
}
/// Width of `view_buttons`, so the bar knows when to move them into the scrolling strip
fn view_buttons_width(button_size: f32, spacing: f32) -> f32 {
// Two icons, three dropdowns, one separator and the five gaps between them
2.0 * button_size + 3.0 * icon_dropdown_button_width(button_size) + BAR_SEPARATOR_WIDTH + 5.0 * spacing
}
/// View buttons in a right-to-left layout: the layout, then the camera type, then the screenshot and UV checker
fn view_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let button_size = ui.spacing().interact_size.y;
// Only the layout works without a project: the others act on it
let project_open = app.session.project_open;
// Right-to-left: the UV checker is added first and sits rightmost
ui.add_enabled_ui(project_open, |ui| {
let checker = app.session.view == texturecraft_engine::ViewMode::UvChecker;
if icon_button(ui, ic::CHECKERBOARD, &tip(&app.ui.keymap, tr("UV checker"), "ui.uvChecker"), checker, button_size).clicked() {
let mode = if checker { "material" } else { "uvChecker" };
app.run("viewport.view", json!({"mode": mode}));
}
if icon_button(ui, ic::CAMERA, tr("Screenshot of the viewport"), false, button_size).clicked() {
app.toast(tr("Use the control channel or `texturecraft-cli render` for screenshots"), false);
}
});
ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH));
ui.add_enabled_ui(project_open, |ui| {
rotation_dropdown(app, ui);
projection_dropdown(app, ui);
});
layout_dropdown(app, ui);
}
/// The 3D/2D, 3D-only and 2D-only layouts and the swap, showing the current one's icon
fn layout_dropdown(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
const LAYOUTS: [(ViewLayout, &str, &str, &str); 3] = [
(ViewLayout::Split, ic::SQUARE_SPLIT_HORIZONTAL, "3D/2D views", "ui.layout.split"),
(ViewLayout::Only3D, ic::SPHERE, "3D view only", "ui.layout.3d"),
(ViewLayout::Only2D, ic::SQUARE, "2D view only", "ui.layout.2d"),
];
let (_, icon, label, command) = LAYOUTS.iter().find(|(layout, ..)| *layout == app.ui.layout).unwrap_or(&LAYOUTS[0]);
let tooltip = tip(&app.ui.keymap, tr(label), command);
let mut chosen = None;
icon_dropdown(ui, "view_layout", icon, &tooltip, |ui| {
for (layout, icon, label, command) in LAYOUTS {
if dropdown_row(ui, icon, tr(label), shortcut_of(&app.ui.keymap, command), app.ui.layout == layout) {
chosen = Some(command);
}
}
if dropdown_row(ui, ic::ARROWS_LEFT_RIGHT, tr("Swap 3D/2D"), shortcut_of(&app.ui.keymap, "ui.layout.swap"), false) {
chosen = Some("ui.layout.swap");
}
});
if let Some(command) = chosen {
crate::menus::invoke(app, &ui.ctx().clone(), command);
}
}
/// Perspective or orthographic projection, the same setting as the Display Settings checkbox
fn projection_dropdown(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let projections = [(false, ic::PERSPECTIVE, tr("Perspective")), (true, ic::CUBE, tr("Orthographic"))];
let ortho = app.session.camera.ortho;
let (_, icon, label) = projections.iter().find(|(choice, ..)| *choice == ortho).unwrap_or(&projections[0]);
let mut chosen = None;
icon_dropdown(ui, "view_projection", icon, label, |ui| {
for (choice, icon, label) in projections {
if dropdown_row(ui, icon, label, None, ortho == choice) {
chosen = Some(choice);
}
}
});
if let Some(choice) = chosen.filter(|choice| *choice != ortho) {
app.run("camera.set", json!({"ortho": choice}));
}
}
/// Constrained (horizon stays level) or free (trackball) camera rotation
fn rotation_dropdown(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let modes = [
(false, ic::ARROWS_HORIZONTAL, "Constrained rotation", "camera.rotation.constrained"),
(true, ic::ARROWS_CLOCKWISE, "Free rotation", "camera.rotation.free"),
];
let free = app.session.camera.free;
let (_, icon, label, _) = modes.iter().find(|(choice, ..)| *choice == free).unwrap_or(&modes[0]);
let mut chosen = None;
icon_dropdown(ui, "view_rotation", icon, tr(label), |ui| {
for (choice, icon, label, command) in modes {
if dropdown_row(ui, icon, tr(label), shortcut_of(&app.ui.keymap, command), free == choice) {
chosen = Some(command);
}
}
});
if let Some(command) = chosen {
crate::menus::invoke(app, &ui.ctx().clone(), command);
}
}
/// An icon button with a caret that opens `menu` below it, highlighted while open
fn icon_dropdown(ui: &mut egui::Ui, id_salt: &str, icon: &str, tooltip: &str, menu: impl FnOnce(&mut egui::Ui)) {
let button_size = ui.spacing().interact_size.y;
let popup_id = ui.make_persistent_id(id_salt);
let open = egui::Popup::is_id_open(ui.ctx(), popup_id);
let mut response = icon_dropdown_button(ui, icon, tooltip, open, button_size);
if !open {
response = response.on_hover_text(tooltip);
}
egui::Popup::menu(&response).id(popup_id).show(menu);
}
/// One dropdown entry: icon, label and shortcut. Returns true when clicked
fn dropdown_row(ui: &mut egui::Ui, icon: &str, label: &str, shortcut: Option<&str>, selected: bool) -> bool {
let mut button = egui::Button::new(format!("{icon} {label}")).selected(selected);
if let Some(shortcut) = shortcut {
button = button.shortcut_text(shortcut);
}
ui.add(button).clicked()
}
/// Scroll tool controls and, in narrow viewports, the view buttons
fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens, scroll_views: bool) {
let button_size = ui.spacing().interact_size.y;
let strip_width = ui.available_width();
let overflow_id = egui::Id::unique("tool_controls_overflow");
let overflowing = ui.data(|data| data.get_temp::<bool>(overflow_id)).unwrap_or(false);
// A positive delta moves the content right, revealing its start
let arrow_scroll_step = strip_width / 2.0;
let mut scroll_delta = 0.0;
if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_LEFT, "Scroll left", false, button_size).clicked() {
scroll_delta = arrow_scroll_step;
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_RIGHT, "Scroll right", false, button_size).clicked() {
scroll_delta = -arrow_scroll_step;
}
let scroll_area = egui::ScrollArea::horizontal()
.id_salt("tool_controls")
.min_scrolled_width(0.0)
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden);
let output = ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
scroll_area.show(ui, |ui| {
ui.scroll_with_delta(vec2(scroll_delta, 0.0));
ui.horizontal_centered(|ui| {
// A tool that can't act on the selection leaves the bar, as the shelf greys it
let tool_usable = app.session.tool_usable(app.session.tool.tool);
if tool_usable {
tool_controls(app, ui, tokens);
}
if scroll_views {
if tool_usable {
ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH));
}
let size = vec2(view_buttons_width(button_size, ui.spacing().item_spacing.x), ui.available_height());
ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| view_buttons(app, ui));
}
});
})
});
// The arrows take room from the strip, so measure the overflow against its full width
let overflows_now = output.inner.content_size.x > strip_width;
if overflows_now != overflowing {
ui.data_mut(|data| data.insert_temp(overflow_id, overflows_now));
ui.ctx().request_repaint();
}
});
}
/// Largest brush radius as a fraction of the mesh diagonal; size sliders show it as 100
pub(crate) const MAX_BRUSH_SIZE: f32 = 0.25;
/// Smallest brush radius as a fraction of the mesh diagonal
pub(crate) const MIN_BRUSH_SIZE: f32 = 0.0005;
/// The selected tool's icon and its settings
fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) {
const DEFAULT_LAZY_DISTANCE_PX: f32 = 20.0;
const TOOL_ICON_SIZE: f32 = 15.0;
let button_size = ui.spacing().interact_size.y;
let tool = app.session.tool.tool;
ui.label(RichText::new(tool_icon(tool)).size(TOOL_ICON_SIZE).color(tokens.text_strong)).on_hover_text(tr(tool.label()));
let brush = &mut app.session.tool.brush;
match tool {
Tool::Paint | Tool::Eraser | Tool::Projection | Tool::Smudge | Tool::Clone | Tool::Path => {
let mut size = brush.size / MAX_BRUSH_SIZE * 100.0;
if bar_slider(ui, tr("Size"), &mut size, 0.05..=100.0, 110.0).changed() {
brush.size = (size / 100.0 * MAX_BRUSH_SIZE).clamp(MIN_BRUSH_SIZE, MAX_BRUSH_SIZE);
}
let mut flow = brush.flow * 100.0;
if bar_slider(ui, tr("Flow"), &mut flow, 0.0..=100.0, 100.0).changed() {
brush.flow = flow / 100.0;
}
let mut opacity = brush.opacity * 100.0;
if bar_slider(ui, tr("Stroke opacity"), &mut opacity, 0.0..=100.0, 110.0).changed() {
brush.opacity = opacity / 100.0;
}
let mut spacing = brush.spacing * 100.0;
if bar_slider(ui, tr("Spacing"), &mut spacing, 1.0..=200.0, 100.0).changed() {
brush.spacing = spacing / 100.0;
}
ui.separator();
let lazy_on = brush.lazy > 0.0;
if icon_button(ui, ic::SCRIBBLE, tr("Lazy mouse"), lazy_on, button_size).clicked() {
brush.lazy = if lazy_on { 0.0 } else { DEFAULT_LAZY_DISTANCE_PX };
}
if lazy_on {
let mut distance = brush.lazy;
if bar_slider(ui, tr("Distance"), &mut distance, 1.0..=200.0, 90.0).changed() {
brush.lazy = distance;
}
}
ui.separator();
if icon_button(ui, ic::CLOUD_RAIN, tr("Particle brush: particles slide down the surface"), brush.particles.enabled, button_size).clicked() {
brush.particles.enabled = !brush.particles.enabled;
}
if crate::symmetry::applies_to(tool) {
crate::symmetry::toolbar_controls(app, ui);
}
if tool == Tool::Smudge {
ui.separator();
let mut strength = app.session.tool.smudge_strength * 100.0;
if bar_slider(ui, tr("Strength"), &mut strength, 0.0..=100.0, 100.0).changed() {
app.session.tool.smudge_strength = (strength / 100.0).clamp(0.0, 1.0);
}
}
if tool == Tool::Clone && app.session.tool.clone_source.is_none() {
ui.separator();
ui.label(RichText::new(tr("Hold V and click the mesh to set the clone source")).color(tokens.text_dim));
}
if tool == Tool::Path {
ui.separator();
path_controls(app, ui);
}
}
Tool::PolygonFill => {
fill_mode_buttons(app, ui);
ui.separator();
crate::symmetry::toolbar_controls(app, ui);
}
Tool::ColorPicker => {
ui.label(RichText::new(tr("Click the mesh to pick its material into the brush")).color(tokens.text_dim));
}
Tool::GeometryMask => {
ui.label(RichText::new(tr("Click a mesh part to show or hide the selected layer on it.")).color(tokens.text_dim));
}
}
}
/// Bake, Painting and Rendering mode buttons for a right-to-left layout, so Rendering is added first
fn mode_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let button_size = ui.spacing().interact_size.y;
for (mode, icon, label, command) in [
(Mode::Rendering, ic::APERTURE, tr("Rendering (path traced)"), "ui.mode.render"),
(Mode::Painting, ic::PALETTE, tr("Painting"), "ui.mode.paint"),
(Mode::Baking, ic::ATOM, tr("Bake Mesh Maps"), "ui.mode.bake"),
] {
// Greyed (Painting stays shown as the current mode) while no project is open
let on = crate::menus::enabled(app, command);
let button = ui.add_enabled_ui(on, |ui| icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, button_size)).inner;
if button.clicked() {
crate::menus::invoke(app, &ui.ctx().clone(), command);
}
}
}
/// Polygon fill's fill modes (top bar and properties)
pub fn fill_mode_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
use texturecraft_engine::FillMode;
let button_size = ui.spacing().interact_size.y;
for (fill_mode, icon, tooltip) in [
(FillMode::Triangle, ic::TRIANGLE, tr("Triangle fill")),
(FillMode::Polygon, ic::PARALLELOGRAM, tr("Polygon fill")),
(FillMode::Mesh, ic::CUBE, tr("Mesh fill")),
(FillMode::UvIsland, ic::CHECKERBOARD, tr("UV island fill")),
] {
if icon_button(ui, icon, tooltip, app.session.tool.fill_mode == fill_mode, button_size).clicked() {
app.session.tool.fill_mode = fill_mode;
}
}
}
/// Path tool options and actions (top bar and properties)
pub fn path_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let button_size = ui.spacing().interact_size.y;
let path = &app.session.tool.path;
let (closed, fill) = (path.closed, path.fill);
let selected = path.selected.is_some_and(|i| i < path.points.len());
let has_points = !path.points.is_empty();
let corner = path.selected.is_some_and(|i| path.is_corner(i));
if icon_button(ui, ic::POLYGON, tr("Closed path"), closed, button_size).clicked() {
app.session.set_path_closed(!closed);
}
let fill_tip = if closed { tr("Fill the closed path (lasso)") } else { tr("Fill the path (close it first)") };
if icon_button(ui, ic::PAINT_BUCKET, fill_tip, fill, button_size).clicked() {
app.session.set_path_fill(!fill);
}
if ui.add_enabled_ui(selected, |ui| icon_button(ui, ic::ANGLE, tr("Corner point (Shift+click places one)"), corner, button_size)).inner.clicked() {
// The command repaints an edited path and is one undo step
app.run("path.corner", json!({}));
}
if ui.add_enabled_ui(selected, |ui| icon_button(ui, ic::BACKSPACE, tr("Remove point"), false, button_size)).inner.clicked() {
app.session.remove_selected_path_point();
}
if ui.add_enabled_ui(has_points, |ui| icon_button(ui, ic::CHECK, tr("Apply"), false, button_size)).inner.clicked() {
app.run("tool.path", json!({"commit": true}));
}
}
/// Shelf order of the tools; their shortcut keys follow `Tool::ALL`
const SHELF_TOOLS: [Tool; 9] =
[Tool::Paint, Tool::Eraser, Tool::Path, Tool::Projection, Tool::PolygonFill, Tool::Smudge, Tool::Clone, Tool::ColorPicker, Tool::GeometryMask];
/// The tools Baking keeps on its shelf, greyed
const BAKING_SHELF_TOOLS: [Tool; 3] = [Tool::Paint, Tool::Eraser, Tool::PolygonFill];
/// Width of the tool shelf, in points
const SHELF_WIDTH: f32 = 40.0;
/// Size of a shelf button, in points
const SHELF_BUTTON_SIZE: f32 = 28.0;
/// Vertical gap between shelf buttons, in points
const SHELF_BUTTON_SPACING: f32 = 3.0;
/// Space on each side of the lines between shelf groups, in points
const SHELF_GROUP_GAP: f32 = 6.0;
/// Padding inside the shelf card around its buttons, in points (sides, then top and bottom)
const SHELF_PADDING: egui::Margin = egui::Margin::symmetric(3, 6);
pub fn tool_shelf(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let tokens = Tokens::get(ui.ctx());
egui::Panel::left("tool_shelf").resizable(false).exact_size(SHELF_WIDTH).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| {
// The tools start level with the panels' contents, below their tab strips
let top = GUTTER + crate::docking::TAB_HEIGHT as i8;
card(ui, &tokens, egui::Margin { left: GUTTER, right: 0, top, bottom: GUTTER }, SHELF_PADDING, |ui| {
ui.spacing_mut().item_spacing.y = SHELF_BUTTON_SPACING;
// Rendering has nothing to paint, so its shelf keeps only the buttons below the tools
let tools: &[Tool] = match app.ui.mode {
Mode::Painting => &SHELF_TOOLS,
Mode::Baking => &BAKING_SHELF_TOOLS,
Mode::Rendering => &[],
};
if !tools.is_empty() {
for &tool in tools {
let command = format!("tool.{}", tool.id());
let hint = tip(&app.ui.keymap, tr(tool.label()), &command);
let (usable, selected) = match app.ui.mode {
// In bake mode Paint is the cage or skew brush while one of them is being painted
Mode::Baking => {
let bake_brush = tool == Tool::Paint && app.ui.bake_paint_brush.on;
(bake_brush, bake_brush)
}
// A greyed tool never shows as selected, even while it stays equipped
_ => {
let usable = crate::menus::enabled(app, &command);
(usable, usable && app.session.tool.tool == tool)
}
};
let button = ui.add_enabled_ui(usable, |ui| icon_button(ui, tool_icon(tool), &hint, selected, SHELF_BUTTON_SIZE)).inner;
if button.on_disabled_hover_text(tr(tool.label())).clicked() && app.ui.mode == Mode::Painting {
app.run("tool.select", json!({"tool": tool.id()}));
}
}
ui.add_space(SHELF_GROUP_GAP);
ui.separator();
ui.add_space(SHELF_GROUP_GAP);
}
let quick_mask = &app.session.quick_mask;
for (command, icon, label, selected) in [
("viewport.quickMask", ic::SELECTION_BACKGROUND, tr("Quick mask"), quick_mask.enabled),
("viewport.quickMask.edit", ic::SELECTION, tr("Edit quick mask"), quick_mask.editing),
("viewport.quickMask.invert", ic::SELECTION_INVERSE, tr("Invert quick mask"), quick_mask.inverted),
] {
let hint = tip(&app.ui.keymap, label, command);
let button = ui.add_enabled_ui(crate::menus::enabled(app, command), |ui| icon_button(ui, icon, &hint, selected, SHELF_BUTTON_SIZE)).inner;
if button.on_disabled_hover_text(label).clicked() {
app.run(command, json!({}));
}
}
ui.add_space(SHELF_GROUP_GAP);
ui.separator();
ui.add_space(SHELF_GROUP_GAP);
let painting = app.ui.mode == Mode::Painting;
if ui.add_enabled_ui(painting, |ui| icon_button(ui, ic::SPHERE, tr("Add smart material from the shelf"), false, SHELF_BUTTON_SIZE)).inner.clicked()
{
app.ui.dock.focus(Panel::Assets);
}
});
});
}
/// Width of the icon rail beside the dock
const RAIL_WIDTH: f32 = 38.0;
/// Size of the rail's icons
const RAIL_ICON_SIZE: f32 = 26.0;
/// Gap between the rail's icons
const RAIL_ICON_GAP: f32 = 4.0;
/// Padding inside the rail's card around its icons, as the tool shelf's
const RAIL_CARD_PADDING: egui::Margin = egui::Margin::symmetric(3, 6);
/// The icon rail: the rail panels that are not in the dock (Export first), each opening its popup
pub fn rail(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let tokens = Tokens::get(ui.ctx());
egui::Panel::right("rail").resizable(false).exact_size(RAIL_WIDTH).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| {
card(ui, &tokens, egui::Margin { left: 0, right: GUTTER, top: GUTTER, bottom: GUTTER }, RAIL_CARD_PADDING, |ui| {
ui.spacing_mut().item_spacing.y = RAIL_ICON_GAP;
crate::rail_popup::begin_rail(ui.ctx(), ui.max_rect());
// A panel in the dock, docked or floating, leaves the rail until it is closed there
for (panel, icon, id) in crate::rail_popup::RAIL_PANELS {
if app.ui.dock.is_open(panel) {
continue;
}
let response = icon_button(ui, icon, &tip(&app.ui.keymap, tr(panel.name()), id), app.ui.rail_panel == Some(panel), RAIL_ICON_SIZE);
crate::rail_popup::remember_icon(ui.ctx(), panel, response.rect);
if response.clicked() {
crate::rail_popup::toggle(app, panel);
}
}
});
});
}
pub fn status_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) {
let tk = Tokens::get(ui.ctx());
egui::Panel::bottom("status_bar")
.exact_size(22.0)
.show_separator_line(false)
.frame(egui::Frame::NONE.fill(tk.chrome).inner_margin(egui::Margin::symmetric(10, 0)))
.show(ui, |ui| {
ui.horizontal_centered(|ui| {
if let Some(p) = app.bake_progress() {
ui.add(egui::ProgressBar::new(p).desired_width(160.0).desired_height(10.0).text(RichText::new(tr("Baking")).size(10.0)));
if ui.small_button(tr("Cancel")).clicked() {
app.cancel_bake();
}
} else if let Some(job) = &app.resize {
let bar = egui::ProgressBar::new(job.progress.fraction()).desired_width(160.0).desired_height(10.0);
ui.add(bar.animate(true).text(RichText::new(tr("Resizing")).size(10.0)));
} else if let Some(p) = app.gpu.as_ref().and_then(|g| g.composite_progress(&app.session)) {
ui.add(egui::ProgressBar::new(p).desired_width(160.0).desired_height(10.0).text(RichText::new(tr("Compositing")).size(10.0)));
ui.ctx().request_repaint();
} else if let Some(msg) = app.session.log.last() {
ui.label(RichText::new(msg).size(11.0).color(tk.text_dim));
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let gpu = app.gpu.as_ref().map(|g| g.adapter.as_str()).unwrap_or(tr("no GPU"));
ui.label(
RichText::new(trf("Version: {version} ({gpu})", &[("version", &texturecraft_engine::VERSION), ("gpu", &gpu)]))
.size(11.0)
.color(tk.text_dim),
);
});
});
});
}
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.