Problem using NSView's scrollRect:by:

2017-01-25 Thread Tae Won Ha
Hi guys.

I'm trying to implement a view that has scroll functionality by itself,
since I cannot use an NSScrollView. I think that NSView's scrollRect:by:
is probably the way to go, but how can I use it? I tried the following
(in a freshly created Xcode project):

AppDelegate.swift:

--- >8 ---
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

  @IBOutlet weak var window: NSWindow!

  fileprivate let testView = TestView(frame: CGRect(x: 0, y: 0, width:
400, height: 400))

  // This is invoked by a menu item created and linked in the xib file.
  @IBAction func triggerScroll(_: Any) {
self.testView.scroll(CGRect(x: 0, y: 0, width: 50, height: 50), by:
CGSize(width: 100, height: 100))
  }

  func applicationDidFinishLaunching(_: Notification) {
self.window.contentView?.addSubview(self.testView)
  }
}

class TestView: NSView {

  override func draw(_ dirtyRect: NSRect) {
NSColor.red.set()
NSRectFill(CGRect(x: 0, y: 0, width: 50, height: 50))
  }
}
--- 8< ---

What I expected was that the red box at the bottom left corner gets
'copied' to the point (100, 100) when I invoke the triggerScroll action.
However nothing happens. What am I doing wrong?

Thanks in advance and best,
Tae

PS. Other possible solution seems to be to use a CGBitmapContext to draw
stuff into it and, when scrolling, to draw a clipped version of it at
the right location, but it seems to be a quite overkill (if the above
would work...)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Flush two NSViews with one fixed width using Cocoa Auto Layout

2014-05-03 Thread Tae Won Ha
Hi, guys.

I have a problem using Auto Layout in Cocoa. What I want achieve is
simple: I have two custom views, say, Left and Right. I want Left to be
always 100 wide and Right to be flexible, ie resize with the Window:
+--+---+
|  |   |
|   Left   |  Right|
| 100 wide | flexible  |
|  |   |
+--+---+

I tried H:|[left(100)][right(=100)]| as follows:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  NSView *contentView = self.window.contentView;

  DummyView *left = [[DummyView alloc] initWithFrame:CGRectZero];
  left.translatesAutoresizingMaskIntoConstraints = NO;
  left.backgroundColor = [NSColor yellowColor];
  [contentView addSubview:left];

  DummyView *right = [[DummyView alloc] initWithFrame:CGRectZero];
  right.translatesAutoresizingMaskIntoConstraints = NO;
  right.backgroundColor = [NSColor greenColor];
  [contentView addSubview:right];

  NSDictionary *views = @{
  @left : left,
  @right : right,
  };

  // what am I doing wrong?
  [contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@H:|[left(100)][right(=100)]| options:0
metrics:nil views:views]];
  [contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@V:|[left]| options:0 metrics:nil
views:views]];
  [contentView addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@V:|[right]| options:0 metrics:nil
views:views]];
}

The DummyView:

@interface DummyView : NSView
@property (copy) NSColor *backgroundColor;
@end

@implementation DummyView
- (void)drawRect:(NSRect)dirtyRect {
  [_backgroundColor set];
  NSRectFill(self.frame);
}
@end

The resulting window looks as follows:
http://taewon.de/left-right-screenshot.png or
+--+--+-+
|  |  | |
|   Left   |   empty  |   Right |
| 100 wide |   space  |  flexible   |
|  |  | |
+--+--+-+

Why is there an empty space (100 wide) between Left and Right? I also
tried to set the width constraint of Left using
+constraintsWithVisualFormat:options:metrics:views:, but I get the same
result. Am I missing something here?

The project can be also downloaded: https://github.com/qvacua/sandbox

Thanks in advance and best,
Tae

-- 
@hataewon
http://taewon.de

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Question about adding NSTextView into a zoomed parent view (10.9)

2013-12-22 Thread Tae Won Ha
Hi, guys.

I have got a problem with adding NSTextView into a zoomed parent view.
I've got the following situation:

- A custom NSView in an NSScrollView, let's denote this NSView by viewA.
- viewA is zoomed by -scaleUnitSquareToSize:
- I create an instance of NSTextView with an NSScrollView (and all the
other required classes of Cocoa text system) and add the scroll view
into viewA.
- I scroll the scroll view of viewA such that the newly added text view
is visible by -scrollRectToVisible:
- The app crashes after showing the zoomed NSTextView

Odd points so far:
- When viewA is not zoomed, then the app does not crash.
- I first add the text view into unzoomed viewA, then remove it by
-removeFromSuperview. Then zoom viewA and add the (used) textView again,
then the app does not crash, however, the text view does not have the
same magnification as viewA.
- The code worked on 10.8, but now on 10.9 it crashes as described.

If my description is too vague or not precise enough, you can also look
at the source code:
- https://github.com/qvacua/qmind/blob/issue-20/Qmind/QMMindmapView.m :
This is the (zoomable) parent view.
- https://github.com/qvacua/qmind/blob/issue-20/Qmind/QMCellEditor.m :
In this class I add/remove the text view.

To reproduce (on 10.9), you create a new mindmap, zoom in (by pinching
for example), select the root node (New Mindmap), then enter the
Return-key to edit the node.

I don't see what I'm doing wrong... Any help would be greatly appreciated.

Best,
Tae

-- 
@hataewon
http://qvacua.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Adding a child view to a zoomed parent view

2013-02-28 Thread Tae Won Ha

Hi, guys.

I have the following situation and need help:

* I have a parent view 'pv' which has a unit scale {x, x} where x != 1, say x = 
1.1. I used the -scaleUnitSquareToSize: method for this.
* I instantiate a child view 'cv' using -initWithFrame: with a rect, say {100, 
100, 100, 100}.
* I add cv to pv using -addSubview:

As far as I understand, the frame I used to instantiate cv is interpreted in 
the parent view's coordinate system. Thus, after -addSubview:, cv should have 
the frame {100, 100, 100, 100} in pv's coordinate system, right? In my 
situation, before cv's -drawRect: is called, -setFrame: of cv is called with 
{90.91, 90.91, 90.91, 90.91}, ie the child view is displaced and is drawn 
smaller than intended.

It's about the following file, from line 700:
https://github.com/qvacua/qmind/blob/issue/QM-7/Qmind/QMMindmapView.m

To reproduce the problem, just run the app with DEBUG=1 and click the zoom in 
button in the toolbar (or pinch) and click anywhere. In the log, you will see 
that -setFrame: of the child view gets invoked with weird rect. In the above 
file, I use {1000, 500, 100, 100} for the initial frame of the child view and 
get {909.09, 454.55, 90.91, 90.91} after adding it to the parent view with unit 
scale {1.1, 1.1}.

When I use a dummy project where both the parent and child view are dummies, it 
works as intended, ie no -setFrame: call to the child view. Thus, the child 
view is not displaced and has the right size.

Am I missing something or doing something wrong?

Thanks in advance and best,
Tae

--
http://qvacua.com
https://github.com/qvacua/
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


-mouseDragged: invoked when it should not (and without mouseDown)

2013-02-03 Thread Tae Won Ha
Hi, guys. I need some help in event handling. I have a custom view 
embedded in a scroll view which is embedded in a split view. The window 
has got a toolbar. When I move the window down by dragging the toolbar, 
very often the -mouseDragged: of my custom view gets invoked. Curiously 
enough, it does not seem to happen when I drag the window up. My questions:


- Why?
- When I NSLog() things, I see that -mouseDown: of the custom view is 
not invoked. What's going on?


It's the following file

https://github.com/qvacua/qmind/blob/master/Qmind/QMMindmapView.m

from line 706.

I created a dummy project which has got a dummy -mouseDragged: 
implementation inside a window with a toolbar. In the dummy project it 
does not happen at all.


I'm clueless. Am I missing something quite simple here? Anybody had 
similar problems?


Thanks in advance.

Best,
Tae

--
http://qvacua.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com