How to properly initialize context menus, dropdowns, and tooltips

Preferred extent

Before context menu, dropdown, and tooltip content is displayed, it is necessary to find out where it should be displayed. BrAnchoredStrategy Object subclass: #BrAnchoredStrategy instanceVariableNames: '' classVariableNames: '' package: 'Brick-Anchored - Support' objects are used as a composite BrAnchoredStrategy subclass: #BrAnchoredCompositeStrategy instanceVariableNames: 'strategies' classVariableNames: '' package: 'Brick-Anchored - Support' structure. See defined strategies:

(GtSearchInstanceSlotReferenceFilter
	forClassAndSubclasses: BrWithAnchoredAptitude
	andVariable: 'strategy')
	includeReaders: false;
	includeWriters: true
  

To evaluate the best placement (a winning strategy), a preferred (estimated) extent preferredExtent: anObject preferredExtent = anObject ifTrue: [ ^ self ]. preferredExtent := anObject. self canRelocate ifTrue: [ self canRelocate ] content size needs to be defined. If it is not set explicitly a default value preferredExtent: anObject preferredExtent = anObject ifTrue: [ ^ self ]. preferredExtent := anObject. self canRelocate ifTrue: [ self canRelocate ] is used.

Example

If the preferred extent is smaller than the content extent, it may happen that a context menu, dropdown, or tooltip is placed out of the visible area. Such issue was targeted in feenkcom/gtoolkit#3233, resulting in the following example:

You can see that two out of four placement strategies are suitable and the first one is used.

Checking existing users

You can browse all places where context menu, dropdown, and/or tooltip is implemented (ignoring examples):

allAptitudes := BrWithAnchoredAptitude allSubclasses
		inject: BrWithAnchoredAptitude gtReferences
		into: [ :filter :class | filter | class gtReferences ].
withoutExamples := allAptitudes & #gtExample gtPragmas not
  

As a good practice, it is recommened to explicitly set preferred extent. The following snippet shows users where the preferred extent is not explicitly set:

withoutExamples & #preferredExtent: gtSenders not
  

and cases where the preferred extent is explicitly initialized:

withoutExamples & #preferredExtent: gtSenders wi