javascript - Cappuccino - CPSplitView 固定 subview 的大小

标签 javascript objective-c user-interface cappuccino objective-j

我有一个类 GridNode 继承自 CPSplitView,用于包装 GridELement 类型的对象。 GridNode 的每次连续拆分都会将其分成两个新的 GridNode(包含随父元素调整大小的 GridElements)。

另一个类 - GridToolbar 继承自 GridElement。它基本上应该与 GridElement 具有相同的行为,尽管大小不应自动更改(随着容器的大小调整),但只有在用户拖动拆分器后才会更改。

问题是,即使我将 AutoresizingMask 设置为特定方向(因为工具栏可以是垂直或水平的),它仍然会在两个方向上调整大小。

有什么建议可以防止这种情况发生吗?

GridNode.j 的来源:

@implementation GridNode : CPSplitView
{
}

- (id)initWithFrame:(CGRect)aFrame
{
  self = [super initWithFrame:aFrame];

  if(self)
  {
    [self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
    [self setBackgroundColor:[CPColor colorWithHexString:"EEEEEE"]]
  }

  return self;
}

- (void)split:(id)sender
{
  var parent = [sender superview];

  var gridNode = [
    [GridNode alloc]
    initWithFrame:CGRectMake(
      0, 0,
      CGRectGetWidth([parent bounds]),
      CGRectGetHeight([parent bounds])
    )
  ];
  [gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]

  var element = [
    [GridElement alloc]
    initWithFrame:CGRectMake(
      0, 0,
      CGRectGetWidth([parent bounds]),
      CGRectGetHeight([parent bounds])
    )
  ];

  [self replaceSubview:parent with:gridNode];

  [parent setBtnTarget:gridNode];
  [element setBtnTarget:gridNode];

  [gridNode addSubview:parent];
  [gridNode addSubview:element];
}

- (void)addBar:(id)sender
{
  var parent = [sender superview];

  var gridNode = [
    [GridNode alloc]
    initWithFrame:CGRectMake(
      0, 0,
      CGRectGetWidth([parent bounds]),
      CGRectGetHeight([parent bounds])
    )
  ];
  [gridNode setVertical:(CGRectGetWidth([gridNode bounds]) >= CGRectGetHeight([gridNode bounds]) ? YES : NO)]

  var isVertical = [gridNode isVertical];
  var toolbar = [
    [GridToolbar alloc]
    initWithFrame:CGRectMake(
      0, 0,
      CGRectGetWidth([parent bounds]),
      CGRectGetHeight([parent bounds])
    )
    vertical: isVertical
  ];

  [parent setBounds:CGRectMake(
    isVertical ? 32 : 0, isVertical ? 0 : 32,
    CGRectGetWidth([gridNode bounds]) - (isVertical ? 32 : 0),
    CGRectGetHeight([parent bounds]) - (isVertical ? 0 : 32)
  )];

  [self replaceSubview:parent with:gridNode];

  [parent setBtnTarget:gridNode];
  [toolbar setBtnTarget:gridNode];

  [gridNode addSubview:toolbar];
  [gridNode addSubview:parent];
}

@end

GridElement.j 的来源:

@implementation GridElement : CPView
{
  CPButton btnSPlit;
  CPButton btnToolbar;
}

- (id)initWithFrame:(CGRect)aFrame
{
  self = [super initWithFrame:aFrame]

  if (self)
  {
    [self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable ];
    [self setBackgroundColor:[CPColor colorWithCalibratedRed:Math.random() green:Math.random() blue:Math.random() alpha:1.0]];

    btnSPlit = [
        [CPButton alloc]
        initWithFrame:CGRectMake(0,0,128,24)
    ];

    [btnSPlit setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [btnSPlit setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnSPlit frame])) / 2.0,
                        (CGRectGetHeight([self bounds]) - CGRectGetHeight([btnSPlit frame])) / 2.0 - 15)];
    [btnSPlit setTitle:"split me!"];

    [btnSPlit setAction:@selector(split:)];

    [self addSubview:btnSPlit]

    btnToolbar = [
        [CPButton alloc]
        initWithFrame:CGRectMake(0,0,128,24)
    ];

    [btnToolbar setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [btnToolbar setFrameOrigin:CGPointMake((CGRectGetWidth([self bounds]) - CGRectGetWidth([btnToolbar frame])) / 2.0,
                        (CGRectGetHeight([self bounds]) - CGRectGetHeight([btnToolbar frame])) / 2.0 + 15)];
    [btnToolbar setTitle:"split me!"];

    [btnToolbar setAction:@selector(addBar:)];

    [self addSubview:btnToolbar]
  }

  return self;
}

- (void)setBtnTarget:(id)aTarget
{
  [btnSPlit setTarget:aTarget];
  [btnSPlit setTitle:"split "+aTarget._UID]
  [btnToolbar setTarget:aTarget];
  [btnToolbar setTitle:"toolbar "+aTarget._UID]
}

@end

GridToolbar.j 的来源:

@implementation GridToolbar : GridElement
{
  CPButtonBar btnBar;
}

- (id)initWithFrame:(CGRect)aFrame vertical:(BOOL)isVertical
{
  self = [super initWithFrame:CGRectMake(
    0,0,
    isVertical == NO ? aFrame.size.width : 32,
    isVertical == YES ? aFrame.size.height : 32
  )]

  if(self)
  {
    isVertical == YES ? [self setAutoresizingMask:CPViewWidthSizable] : [self setAutoresizingMask:CPViewHeightSizable];
    [self setBackgroundColor:[CPColor blackColor]];

    btnBar = [
      [CPButtonBar alloc]
      initWithFrame:CGRectMake(
        0,0,
        CGRectGetWidth([self bounds]),
        CGRectGetHeight([self bounds])
      )
    ];
  }

  return self;
}

@end

最佳答案

我收到了一条有用的建议 here .创建我自己的委托(delegate),根据固定值集处理 GridNode 的 subview 的自动调整大小,同时拖动分隔线是我所要做的。

关于javascript - Cappuccino - CPSplitView 固定 subview 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16879038/

相关文章:

objective-c - 为协议(protocol)方法键入编码字符串

ios - AVPlayer播放ts文件

java - 我应该如何继续制作具有拖动功能和图形箭头的交互式程序

java - 为什么如果旋转我的 android 手机,我的应用程序 gui 设置会下降?

javascript - typescript 提取字符串的一部分以进一步处理

javascript - D3 选择具有特定类别或类别组合的所有元素

objective-c - 不断更新 NSImageView

python - tkinter 选项菜单 - 即时更新选项

javascript - 获取所有样式属性颜色

javascript - image.onload 在 IE7 中不触发两次