mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 10:47:56 +01:00
Merge branch 'port/deckcraft/red/app-2' into port/deckcraft/area/app
This commit is contained in:
commit
cdedef1429
4 files changed
+47
-11
No files matched your search
@@ -100,10 +100,11 @@ pub fn endpoints(x: &Xfrm) -> (Point, Point) {
|
||||
/// Move the ends of connectors glued to shapes on the edited slide to the current site positions.
|
||||
/// Connections to shapes that no longer exist are dropped.
|
||||
pub fn reroute(doc: &mut Presentation, sel: &Selection) {
|
||||
let Some(list) = crate::shapes_mut(doc, sel) else { return };
|
||||
if !list.iter().any(|s| matches!(s.kind, ShapeKind::Connector { start: Some(_), .. } | ShapeKind::Connector { end: Some(_), .. })) {
|
||||
// Read first: taking the list mutably would unshare the edited slide even when no connector is glued.
|
||||
if !crate::shapes_of(doc, sel).iter().any(|s| matches!(s.kind, ShapeKind::Connector { start: Some(_), .. } | ShapeKind::Connector { end: Some(_), .. })) {
|
||||
return;
|
||||
}
|
||||
let Some(list) = crate::shapes_mut(doc, sel) else { return };
|
||||
let snapshot: Vec<Shape> = list.clone();
|
||||
let view = doc.clone();
|
||||
let site = |id: ShapeId, idx: u32| -> Option<Point> {
|
||||
|
||||
@@ -288,14 +288,7 @@ impl DocState {
|
||||
}
|
||||
/// Shapes of the edited tree (current slide, or the master/layout in Slide Master view).
|
||||
pub fn shapes(&self) -> &[Shape] {
|
||||
match self.selection.target {
|
||||
Target::Slides => self.current_slide().map(|s| s.shapes.as_slice()).unwrap_or(&[]),
|
||||
Target::Master { master } => self.doc.masters.get(master).map(|m| m.shapes.as_slice()).unwrap_or(&[]),
|
||||
Target::Handout | Target::NotesMaster => page_master(&self.doc, self.selection.target).map(|m| m.shapes.as_slice()).unwrap_or(&[]),
|
||||
Target::Layout { master, layout } => {
|
||||
self.doc.masters.get(master).and_then(|m| m.layouts.get(layout)).map(|l| l.shapes.as_slice()).unwrap_or(&[])
|
||||
}
|
||||
}
|
||||
shapes_of(&self.doc, &self.selection)
|
||||
}
|
||||
pub fn shape(&self, id: ShapeId) -> Option<&Shape> {
|
||||
deckcraft_model::find_shape(self.shapes(), id)
|
||||
@@ -321,6 +314,16 @@ pub fn master_page(doc: &Presentation, t: Target) -> Option<Presentation> {
|
||||
Some(p)
|
||||
}
|
||||
|
||||
/// The edited shape tree of a presentation, read without unsharing its slide or master.
|
||||
pub fn shapes_of<'a>(doc: &'a Presentation, sel: &Selection) -> &'a [Shape] {
|
||||
match sel.target {
|
||||
Target::Slides => doc.slides.get(sel.slide).map(|s| s.shapes.as_slice()).unwrap_or(&[]),
|
||||
Target::Master { master } => doc.masters.get(master).map(|m| m.shapes.as_slice()).unwrap_or(&[]),
|
||||
Target::Handout | Target::NotesMaster => page_master(doc, sel.target).map(|m| m.shapes.as_slice()).unwrap_or(&[]),
|
||||
Target::Layout { master, layout } => doc.masters.get(master).and_then(|m| m.layouts.get(layout)).map(|l| l.shapes.as_slice()).unwrap_or(&[]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Mutable access to the edited shape tree of a presentation.
|
||||
pub fn shapes_mut<'a>(doc: &'a mut Presentation, sel: &Selection) -> Option<&'a mut Vec<Shape>> {
|
||||
match sel.target {
|
||||
|
||||
@@ -974,4 +974,36 @@ mod tests {
|
||||
assert!(harness.state().show.is_none(), "an invalid start never launches a show");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A request from a client's own thread is answered by the UI thread's frame: the connection thread only
|
||||
/// forwards it and asks for a repaint, so it never touches a running pass's state.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_request_over_the_socket_is_answered_in_the_frame() -> Result<(), Box<dyn Error>> {
|
||||
use craft::automation::{client::ControlClient, server};
|
||||
|
||||
let mut harness = harness_with(
|
||||
deckcraft_engine::Session::with_new(),
|
||||
crate::Services::default(),
|
||||
egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0),
|
||||
|_| {},
|
||||
);
|
||||
let listener = std::net::TcpListener::bind(("127.0.0.1", 0))?;
|
||||
let (receiver, listening) = server::serve(listener, "token".into(), WindowHost::of(&harness.ctx))?;
|
||||
harness.state_mut().control = Some(ControlChannel::new(receiver));
|
||||
let addr = listening.addr;
|
||||
let notice = "A notice sent over the socket";
|
||||
let client = std::thread::spawn(move || ControlClient::connect(addr, "token").map_err(|e| format!("{e:?}"))?.call("ui.notify", json!({"text": notice})));
|
||||
let mut frames = 0;
|
||||
while !client.is_finished() && frames < 600 {
|
||||
harness.run_steps(1);
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
frames += 1;
|
||||
}
|
||||
assert!(client.is_finished(), "the frame answered the request");
|
||||
client.join().map_err(|_| "the client thread panicked")??;
|
||||
harness.run_steps(2);
|
||||
assert!(harness.query_by_label(notice).is_some(), "the request ran in the frame");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ pub(crate) fn shape_format(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
|
||||
Menu::new("Shape Effects").opened_by(&response.response, Trigger::Click).show(ui, |ui, cx| effects_menu(app, ui, cx));
|
||||
});
|
||||
});
|
||||
row.group(RibbonGroup::new("shapeFormat.wordArt", "WordArt Styles", Icon::TextEffects.id().into()), |ui| {
|
||||
row.group(RibbonGroup::new("shapeFormat.wordArt", "Decorative Text Styles", Icon::TextEffects.id().into()), |ui| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let response = Button::new("Text Fill")
|
||||
.icon(Icon::TextFill.id())
|
||||
|
||||
Reference in new issue
Block a user