help-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

automatic subviews layout?


From: Bruno Haible
Subject: automatic subviews layout?
Date: Fri, 17 Oct 2003 16:15:10 +0200
User-agent: KMail/1.5

Hi,

What is the recommended way to determine the optimal size of the subviews
of a window, and of the window containing the subviews, in a GNUstep GUI?
For the Java aware: What is the equivalent of java.awt.LayoutManager?

I'm asking because I'm writing a sample hello-world that demonstrates
the internationalization features of GNU gettext in the context of GNUstep,
and code like the one below with absolute positioning of labels doesn't
work if the translation of a string is larger/longer than the English
original: The size of the label has to adapt, and the size of the window
too.

Bruno


===============================================================================
- (void)createUI
{
  NSView *cview;

  window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0,0,400,70)
                             styleMask: (NSTitledWindowMask | 
NSClosableWindowMask | NSMiniaturizableWindowMask)
                             backing: NSBackingStoreBuffered
                             defer: NO];
  [window setDelegate: self];
  [window setTitle: @"Hello example"];
  [window setMinSize: NSMakeSize(400,70)];
  [window setReleasedWhenClosed: NO];
  cview = [window contentView];
  
  label1 = [[NSTextField alloc] initWithFrame: NSMakeRect(10,51,380,21)];
  [label1 setStringValue: _(@"Hello, world!")];
  [label1 setAlignment: NSLeftTextAlignment];
  [label1 setBordered: NO];
  [label1 setEditable: NO];
  [label1 setBezeled: NO];
  [label1 setDrawsBackground: NO];
  [cview addSubview: label1];
  AUTORELEASE (label1);

  label2 = [[NSTextField alloc] initWithFrame: NSMakeRect(10,28,380,21)];
  [label2 setStringValue: [NSString stringWithFormat: _(@"This program is 
running as process number %d."), [[NSProcessInfo processInfo] 
processIdentifier]]];
  [label2 setAlignment: NSLeftTextAlignment];
  [label2 setBordered: NO];
  [label2 setEditable: NO];
  [label2 setBezeled: NO];
  [label2 setDrawsBackground: NO];
  [cview addSubview: label2];
  AUTORELEASE (label2);

  okButton = [[NSButton alloc] initWithFrame: NSMakeRect(300,4,60,22)];
  [okButton setTitle: @"OK"];
  [okButton setTarget: self];
  [okButton setAction: @selector(done)];
  [cview addSubview: okButton];
  AUTORELEASE (okButton);
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]