95 lines
2.8 KiB
Rust
95 lines
2.8 KiB
Rust
use super::*;
|
|
|
|
pub(super) fn fit_width(ui: &egui::Ui, min: f32, max: f32) -> f32 {
|
|
let available = ui.available_width().max(1.0);
|
|
available.min(max).max(min.min(available))
|
|
}
|
|
|
|
pub(super) fn icon_text(icon: Icon, size: f32) -> egui::RichText {
|
|
egui::RichText::new(icon.as_str()).font(egui::FontId::new(
|
|
size,
|
|
egui::FontFamily::Name(PHOSPHOR.into()),
|
|
))
|
|
}
|
|
|
|
pub(super) fn exact_region<R>(
|
|
ui: &mut egui::Ui,
|
|
size: egui::Vec2,
|
|
layout: egui::Layout,
|
|
add_contents: impl FnOnce(&mut egui::Ui) -> R,
|
|
) -> R {
|
|
let (rect, _response) = ui.allocate_exact_size(size, egui::Sense::hover());
|
|
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(layout));
|
|
child.set_clip_rect(rect.intersect(ui.clip_rect()));
|
|
add_contents(&mut child)
|
|
}
|
|
|
|
pub(super) fn exact_region_with_pointer<R>(
|
|
ui: &mut egui::Ui,
|
|
size: egui::Vec2,
|
|
layout: egui::Layout,
|
|
add_contents: impl FnOnce(&mut egui::Ui, bool) -> R,
|
|
) -> (R, egui::Response) {
|
|
let (rect, _response) = ui.allocate_exact_size(size, egui::Sense::hover());
|
|
let contains_pointer = ui
|
|
.ctx()
|
|
.pointer_hover_pos()
|
|
.is_some_and(|position| rect.contains(position));
|
|
let mut child = ui.new_child(
|
|
egui::UiBuilder::new()
|
|
.max_rect(rect)
|
|
.layout(layout)
|
|
.sense(egui::Sense::click()),
|
|
);
|
|
child.set_clip_rect(rect.intersect(ui.clip_rect()));
|
|
let result = add_contents(&mut child, contains_pointer);
|
|
let response = child.response();
|
|
(result, response)
|
|
}
|
|
|
|
pub(super) fn details_width_for_layout(
|
|
available_width: f32,
|
|
tree_width: f32,
|
|
requested: f32,
|
|
) -> f32 {
|
|
let max_width = (available_width - tree_width - MIN_CONTENT_WIDTH).max(DETAILS_MIN_WIDTH);
|
|
requested.clamp(DETAILS_MIN_WIDTH, max_width)
|
|
}
|
|
|
|
pub(super) fn content_width_for_layout(
|
|
available_width: f32,
|
|
tree_width: f32,
|
|
details_width: f32,
|
|
) -> f32 {
|
|
(available_width - tree_width - details_width).max(MIN_CONTENT_WIDTH.min(available_width))
|
|
}
|
|
|
|
pub(super) fn details_resize_handle(
|
|
ui: &mut egui::Ui,
|
|
boundary: egui::Pos2,
|
|
height: f32,
|
|
) -> egui::Response {
|
|
let rect = egui::Rect::from_min_size(
|
|
egui::pos2(boundary.x - DETAILS_RESIZE_HANDLE_WIDTH * 0.5, boundary.y),
|
|
egui::vec2(DETAILS_RESIZE_HANDLE_WIDTH, height),
|
|
);
|
|
let response = ui.interact(
|
|
rect,
|
|
egui::Id::new("asset_details_resize_handle"),
|
|
egui::Sense::drag(),
|
|
);
|
|
let stroke_color = if response.hovered() || response.dragged() {
|
|
ACCENT
|
|
} else {
|
|
BORDER
|
|
};
|
|
ui.painter().vline(
|
|
boundary.x,
|
|
rect.y_range().shrink(4.0),
|
|
egui::Stroke::new(2.0_f32, stroke_color),
|
|
);
|
|
response
|
|
.on_hover_cursor(egui::CursorIcon::ResizeHorizontal)
|
|
.on_hover_text("Drag to resize asset details; double-click to reset")
|
|
}
|