diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2013-08-22 17:19:40 +0100 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2013-08-22 17:19:40 +0100 |
commit | 093e7a12524a3ddedd833df6c284025f1d0a4a8c (patch) | |
tree | 1861edb0d6e36fa34db351d5e0874d314af362a4 /tikzit | |
parent | 8684196a31707a9fb5e7091ce26ae26f2aa16082 (diff) |
Unset default "center" anchor when applying a style
Edges almost always want to be anchored to the "center" of an unstyled
(style=none) node, as otherwise edges won't join up. However, this
anchor should be discarded if a style is then set on the node, otherwise
arrowheads tend to disappear.
Diffstat (limited to 'tikzit')
-rw-r--r-- | tikzit/src/common/Edge.m | 35 | ||||
-rw-r--r-- | tikzit/src/common/Graph.m | 8 |
2 files changed, 37 insertions, 6 deletions
diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index 7b538b5..ea20d2a 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -325,6 +325,12 @@ [source removeObserver:self forKeyPath:@"style"]; + if ([s style] == nil) { + [self setSourceAnchor:@"center"]; + } else if ([sourceAnchor isEqual:@"center"]) { + [self setSourceAnchor:@""]; + } + [source release]; source = [s retain]; @@ -336,6 +342,7 @@ [source addObserver:self forKeyPath:@"style" options:NSKeyValueObservingOptionNew + | NSKeyValueObservingOptionOld context:NULL]; dirty = YES; @@ -348,6 +355,12 @@ [target removeObserver:self forKeyPath:@"style"]; + if ([t style] == nil) { + [self setTargetAnchor:@"center"]; + } else if ([targetAnchor isEqual:@"center"]) { + [self setTargetAnchor:@""]; + } + [target release]; target = [t retain]; @@ -359,6 +372,7 @@ [target addObserver:self forKeyPath:@"style" options:NSKeyValueObservingOptionNew + | NSKeyValueObservingOptionOld context:NULL]; dirty = YES; @@ -371,6 +385,27 @@ context:(void *)context { + if ([keyPath isEqual:@"style"]) { + id oldStyle = [change objectForKey:NSKeyValueChangeOldKey]; + id newStyle = [change objectForKey:NSKeyValueChangeNewKey]; + id none = [NSNull null]; + if (object == source) { + if (oldStyle != none && newStyle == none) { + [self setSourceAnchor:@"center"]; + } else if (oldStyle == none && newStyle != none && + [sourceAnchor isEqual:@"center"]) { + [self setSourceAnchor:@""]; + } + } + if (object == target) { + if (oldStyle != none && newStyle == none) { + [self setTargetAnchor:@"center"]; + } else if (oldStyle == none && newStyle != none && + [targetAnchor isEqual:@"center"]) { + [self setTargetAnchor:@""]; + } + } + } dirty = YES; } diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m index 2a01bae..33a81f6 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -736,17 +736,13 @@ NSString *srcAnchor; NSString *tgtAnchor; - if ([[e source] style] == nil) { - srcAnchor = @".center"; - } else if ([[e sourceAnchor] isEqual:@""]) { + if ([[e sourceAnchor] isEqual:@""]) { srcAnchor = @""; } else { srcAnchor = [NSString stringWithFormat:@".%@", [e sourceAnchor]]; } - if ([[e target] style] == nil) { - tgtAnchor = @".center"; - } else if ([[e targetAnchor] isEqual:@""]) { + if ([[e targetAnchor] isEqual:@""]) { tgtAnchor = @""; } else { tgtAnchor = [NSString stringWithFormat:@".%@", [e targetAnchor]]; |