mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:40:47 +00:00
Toolbar resizing: If there are flexible items and flexible space the items will be expanded
first. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30381 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d8a5434efb
commit
85253f4282
2 changed files with 65 additions and 76 deletions
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
* Source/NSToolbarItem.m (-_isFlexibleSpace): Simplify this method.
|
* Source/NSToolbarItem.m (-_isFlexibleSpace): Simplify this method.
|
||||||
* Source/GSToolbarView.m: Clean up toolbar item resizing, this now
|
* Source/GSToolbarView.m: Clean up toolbar item resizing, this now
|
||||||
allows for resizable item other than flexible space.
|
allows for resizable item other than flexible space. If there are
|
||||||
|
flexible items and flexible space the items will be expanded first.
|
||||||
|
|
||||||
2010-05-13 Wolfgang Lux <wolfgang.lux@gmail.com>
|
2010-05-13 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
|
|
|
@ -652,25 +652,33 @@ static void initSystemExtensionsColors(void)
|
||||||
|
|
||||||
- (void) _takeInAccountFlexibleSpaces
|
- (void) _takeInAccountFlexibleSpaces
|
||||||
{
|
{
|
||||||
|
// Borrow this from NSToolbarItem.m
|
||||||
|
static const int InsetItemViewX = 10;
|
||||||
|
|
||||||
NSArray *items = [_toolbar items];
|
NSArray *items = [_toolbar items];
|
||||||
NSEnumerator *e = [items objectEnumerator];
|
NSEnumerator *e;
|
||||||
NSToolbarItem *item;
|
NSToolbarItem *item;
|
||||||
NSRect lastBackViewFrame;
|
|
||||||
float lengthAvailable;
|
float lengthAvailable;
|
||||||
unsigned int flexibleSpaceItemsNumber = 0;
|
unsigned int flexibleSpaceItemsNumber = 0;
|
||||||
BOOL mustAdjustNext = NO;
|
BOOL mustAdjustNext = NO;
|
||||||
CGFloat x = 0.0;
|
CGFloat x = 0.0;
|
||||||
CGFloat maxX = 0.0;
|
CGFloat maxX = 0.0;
|
||||||
|
CGFloat currX;
|
||||||
|
// resizement of a flexible item
|
||||||
|
CGFloat rel = 1.0;
|
||||||
|
// Width of a flexible space
|
||||||
|
CGFloat flexWidth = 0.0;
|
||||||
|
|
||||||
if ([items count] == 0)
|
if ([items count] == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lastBackViewFrame = [[[items lastObject] _backView] frame];
|
currX = NSMaxX([[[items lastObject] _backView] frame]);
|
||||||
lengthAvailable = [self frame].size.width - NSMaxX(lastBackViewFrame);
|
lengthAvailable = NSWidth([self frame]) - currX;
|
||||||
|
|
||||||
if (lengthAvailable < 1)
|
if (lengthAvailable < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
e = [items objectEnumerator];
|
||||||
while ((item = [e nextObject]) != nil)
|
while ((item = [e nextObject]) != nil)
|
||||||
{
|
{
|
||||||
if ([item _isFlexibleSpace])
|
if ([item _isFlexibleSpace])
|
||||||
|
@ -681,88 +689,68 @@ static void initSystemExtensionsColors(void)
|
||||||
// Currently only item with a view are resizable
|
// Currently only item with a view are resizable
|
||||||
if ([item view] != nil)
|
if ([item view] != nil)
|
||||||
{
|
{
|
||||||
maxX += [item maxSize].width;
|
maxX += [item maxSize].width + 2 * InsetItemViewX;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
maxX += NSWidth([[item _backView] frame]);
|
maxX += NSWidth([[item _backView] frame]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Could the items fill more space?
|
||||||
|
if (maxX >= currX)
|
||||||
|
{
|
||||||
|
rel = lengthAvailable / (maxX - currX);
|
||||||
|
|
||||||
|
if (rel > 1.0)
|
||||||
|
rel = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are there any flexible spaces to fill the rest?
|
||||||
if (flexibleSpaceItemsNumber > 0)
|
if (flexibleSpaceItemsNumber > 0)
|
||||||
{
|
{
|
||||||
if (lengthAvailable < flexibleSpaceItemsNumber)
|
flexWidth = (NSWidth([self frame]) - maxX) / flexibleSpaceItemsNumber;
|
||||||
return;
|
if (flexWidth < 0.0)
|
||||||
|
flexWidth = 0.0;
|
||||||
e = [items objectEnumerator];
|
|
||||||
while ((item = [e nextObject]) != nil)
|
|
||||||
{
|
|
||||||
NSView *backView = [item _backView];
|
|
||||||
if ([item _isFlexibleSpace])
|
|
||||||
{
|
|
||||||
NSRect backViewFrame = [backView frame];
|
|
||||||
|
|
||||||
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
|
||||||
lengthAvailable / flexibleSpaceItemsNumber,
|
|
||||||
backViewFrame.size.height)];
|
|
||||||
mustAdjustNext = YES;
|
|
||||||
}
|
|
||||||
else if (mustAdjustNext)
|
|
||||||
{
|
|
||||||
NSRect backViewFrame = [backView frame];
|
|
||||||
|
|
||||||
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
|
||||||
backViewFrame.size.width, backViewFrame.size.height)];
|
|
||||||
}
|
|
||||||
x += [backView frame].size.width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
e = [items objectEnumerator];
|
||||||
|
while ((item = [e nextObject]) != nil)
|
||||||
{
|
{
|
||||||
// No flexible space
|
NSView *view = [item view];
|
||||||
// Could the items fill more space?
|
NSView *backView = [item _backView];
|
||||||
if (maxX >= NSMaxX(lastBackViewFrame))
|
CGFloat diff = [item maxSize].width - [item minSize].width;
|
||||||
|
|
||||||
|
if ([item _isFlexibleSpace])
|
||||||
{
|
{
|
||||||
CGFloat rel = lengthAvailable / (maxX - NSMaxX(lastBackViewFrame));
|
NSRect backViewFrame = [backView frame];
|
||||||
|
|
||||||
if (rel > 1.0)
|
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
||||||
rel = 1.0;
|
flexWidth, backViewFrame.size.height)];
|
||||||
|
mustAdjustNext = YES;
|
||||||
e = [items objectEnumerator];
|
|
||||||
while ((item = [e nextObject]) != nil)
|
|
||||||
{
|
|
||||||
NSView *view = [item view];
|
|
||||||
NSView *backView = [item _backView];
|
|
||||||
|
|
||||||
if (view != nil)
|
|
||||||
{
|
|
||||||
CGFloat diff = [item maxSize].width - [item minSize].width;
|
|
||||||
|
|
||||||
if (diff > 0)
|
|
||||||
{
|
|
||||||
NSRect backViewFrame = [backView frame];
|
|
||||||
NSRect viewFrame = [view frame];
|
|
||||||
|
|
||||||
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
|
||||||
(rel * diff) + [item minSize].width,
|
|
||||||
backViewFrame.size.height)];
|
|
||||||
// Subtract InsetItemViewX
|
|
||||||
viewFrame.size.width = (rel * diff) + [item minSize].width
|
|
||||||
- 2 * 10;
|
|
||||||
[view setFrame: viewFrame];
|
|
||||||
mustAdjustNext = YES;
|
|
||||||
}
|
|
||||||
else if (mustAdjustNext)
|
|
||||||
{
|
|
||||||
NSRect backViewFrame = [backView frame];
|
|
||||||
|
|
||||||
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
|
||||||
backViewFrame.size.width, backViewFrame.size.height)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
x += NSWidth([backView frame]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ((view != nil) && (diff > 0))
|
||||||
|
{
|
||||||
|
NSRect backViewFrame = [backView frame];
|
||||||
|
NSRect viewFrame = [view frame];
|
||||||
|
|
||||||
|
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
||||||
|
(rel * diff) + [item minSize].width,
|
||||||
|
backViewFrame.size.height)];
|
||||||
|
// Subtract InsetItemViewX
|
||||||
|
viewFrame.size.width = (rel * diff) + [item minSize].width
|
||||||
|
- 2 * InsetItemViewX;
|
||||||
|
[view setFrame: viewFrame];
|
||||||
|
mustAdjustNext = YES;
|
||||||
|
}
|
||||||
|
else if (mustAdjustNext)
|
||||||
|
{
|
||||||
|
NSRect backViewFrame = [backView frame];
|
||||||
|
|
||||||
|
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
||||||
|
backViewFrame.size.width, backViewFrame.size.height)];
|
||||||
|
}
|
||||||
|
x += NSWidth([backView frame]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue