diff --git a/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.h b/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.h index f9582dd395..4bf3b9beb5 100644 --- a/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.h +++ b/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.h @@ -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; diff --git a/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.m b/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.m index a740984d00..bd6c882202 100644 --- a/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.m +++ b/src/ui/osx/TogglDesktop/test2/AutoCompleteInput.m @@ -25,6 +25,7 @@ - (id)initWithCoder:(NSCoder *)coder self.posY = 0; self.itemHeight = 25; self.maxVisibleItems = 6; + self.constraintsActive = NO; [self createAutocomplete]; } return self; @@ -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 @@ -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]; } diff --git a/src/ui/osx/TogglDesktop/test2/AutoCompleteTable.m b/src/ui/osx/TogglDesktop/test2/AutoCompleteTable.m index 1514acadb1..817836349d 100644 --- a/src/ui/osx/TogglDesktop/test2/AutoCompleteTable.m +++ b/src/ui/osx/TogglDesktop/test2/AutoCompleteTable.m @@ -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];