Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Fixed new autocomplete constraints issue when loggin out and back in …
Browse files Browse the repository at this point in the history
…(mac)
  • Loading branch information
IndrekV committed May 29, 2018
1 parent 6855c94 commit b1fa34e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/ui/osx/TogglDesktop/test2/AutoCompleteInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
@property int maxVisibleItems;
@property int itemHeight;
@property NSLayoutConstraint *heightConstraint;
@property NSLayoutConstraint *leftConstraint;
@property NSLayoutConstraint *rightConstraint;
@property NSLayoutConstraint *topConstraint;
@property BOOL constraintsActive;
- (void)toggleTableView:(int)itemCount;
- (void)setPos:(int)posy;
- (void)hide;
Expand Down
25 changes: 20 additions & 5 deletions src/ui/osx/TogglDesktop/test2/AutoCompleteInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ - (id)initWithCoder:(NSCoder *)coder
self.posY = 0;
self.itemHeight = 25;
self.maxVisibleItems = 6;
self.constraintsActive = NO;
[self createAutocomplete];
}
return self;
Expand All @@ -51,15 +52,13 @@ - (void)createAutocomplete
- (void)setupAutocompleteConstraints
{
// Set constraints to input field so autocomplete size is always connected to input
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
self.leftConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0];

NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:0];
self.rightConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:0];

NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:1];
self.topConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:1];

self.heightConstraint = [NSLayoutConstraint constraintWithItem:self.autocompleteTableContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:self.itemHeight];

[NSLayoutConstraint activateConstraints:[NSArray arrayWithObjects:leftConstraint, rightConstraint, self.heightConstraint, topConstraint, nil]];
}

- (void)setPos:(int)posy
Expand Down Expand Up @@ -148,6 +147,22 @@ - (void)resetTable

- (void)showAutoComplete:(BOOL)show
{
if (show)
{
if (!self.constraintsActive)
{
[NSLayoutConstraint activateConstraints:[NSArray arrayWithObjects:self.leftConstraint, self.rightConstraint, self.heightConstraint, self.topConstraint, nil]];
self.constraintsActive = YES;
}
}
else
{
if (self.constraintsActive)
{
[NSLayoutConstraint deactivateConstraints:[NSArray arrayWithObjects:self.leftConstraint, self.rightConstraint, self.heightConstraint, self.topConstraint, nil]];
self.constraintsActive = NO;
}
}
[self.autocompleteTableContainer setHidden:!show];
[self.autocompleteTableView setHidden:!show];
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/osx/TogglDesktop/test2/AutoCompleteTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ - (instancetype)initWithFrame:(NSRect)frame
{
self.lastSelected = -1;
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"column"];
column.minWidth = 100;
[self addTableColumn:column];
[self setHeaderView:nil];
[self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
Expand Down

0 comments on commit b1fa34e

Please sign in to comment.