Add animation control buttons to document bar

This commit is contained in:
Keavon Chambers
2025-03-19 02:15:40 -07:00
parent 44694ff8d6
commit 08a4b69948
11 changed files with 91 additions and 17 deletions
@@ -33,6 +33,7 @@ use graphene_core::raster::image::ImageFrameTable;
use graphene_core::vector::style::ViewMode;
use graphene_std::renderer::{ClickTarget, Quad};
use graphene_std::vector::{PointId, path_bool_lib};
use std::time::Duration;
pub struct DocumentMessageData<'a> {
pub document_id: DocumentId,
@@ -1988,7 +1989,7 @@ impl DocumentMessageHandler {
}
}
pub fn update_document_widgets(&self, responses: &mut VecDeque<Message>) {
pub fn update_document_widgets(&self, responses: &mut VecDeque<Message>, animation_is_playing: bool, time: Duration) {
// Document mode (dropdown menu at the left of the bar above the viewport, before the tool options)
let document_mode_layout = WidgetLayout::new(vec![LayoutGroup::Row {
@@ -2026,6 +2027,18 @@ impl DocumentMessageHandler {
let mut snapping_state2 = self.snapping_state.clone();
let mut widgets = vec![
IconButton::new("PlaybackToStart", 24)
.tooltip("Restart Animation")
.tooltip_shortcut(action_keys!(AnimationMessageDiscriminant::RestartAnimation))
.on_update(|_| AnimationMessage::RestartAnimation.into())
.disabled(time == Duration::ZERO)
.widget_holder(),
IconButton::new(if animation_is_playing { "PlaybackPause" } else { "PlaybackPlay" }, 24)
.tooltip(if animation_is_playing { "Pause Animation" } else { "Play Animation" })
.tooltip_shortcut(action_keys!(AnimationMessageDiscriminant::ToggleLivePreview))
.on_update(|_| AnimationMessage::ToggleLivePreview.into())
.widget_holder(),
Separator::new(SeparatorType::Unrelated).widget_holder(),
CheckboxInput::new(self.overlays_visible)
.icon("Overlays")
.tooltip("Overlays")
@@ -34,6 +34,7 @@ pub struct PortfolioMessageData<'a> {
pub current_tool: &'a ToolType,
pub message_logging_verbosity: MessageLoggingVerbosity,
pub timing_information: TimingInformation,
pub animation: &'a AnimationMessageHandler,
}
#[derive(Debug, Default)]
@@ -59,6 +60,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
current_tool,
message_logging_verbosity,
timing_information,
animation,
} = data;
match message {
@@ -1108,7 +1110,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
}
PortfolioMessage::UpdateDocumentWidgets => {
if let Some(document) = self.active_document() {
document.update_document_widgets(responses);
document.update_document_widgets(responses, animation.is_playing(), timing_information.animation_time);
}
}
PortfolioMessage::UpdateOpenDocumentsList => {
@@ -1275,16 +1277,19 @@ impl PortfolioMessageHandler {
/// Get the id of the node that should be used as the target for the spreadsheet
pub fn inspect_node_id(&self) -> Option<NodeId> {
// Spreadsheet not open, skipping
if !self.spreadsheet.spreadsheet_view_open {
warn!("Spreadsheet not open, skipping…");
return None;
}
let document = self.documents.get(&self.active_document_id?)?;
let selected_nodes = document.network_interface.selected_nodes().0;
// Selected nodes != 1, skipping
if selected_nodes.len() != 1 {
warn!("selected nodes != 1, skipping…");
return None;
}
selected_nodes.first().copied()
}
}