Skip to content

Instantly share code, notes, and snippets.

@iriyak
Last active June 10, 2025 16:13
Show Gist options
  • Save iriyak/ebe5a1bc3df8630913791e34d4c875b4 to your computer and use it in GitHub Desktop.
Save iriyak/ebe5a1bc3df8630913791e34d4c875b4 to your computer and use it in GitHub Desktop.
Object subclass: #ItemHolder
instanceVariableNames: 'items'
classVariableNames: ''
package: 'KICodingExerciseForGToolkit'!
!ItemHolder commentStamp: '<historical>' prior: 0!
I have items slot holding an Interval and implement two custom views. gtItemsView: just forwards to self items to render with a selector #gtItemsFor:. gtItemsWithFilterView: is my result of the coding exercise to introduce a menu dropdown button to filter out the elements the items.!
!ItemHolder methodsFor: 'initialization' stamp: 'GlamorousAuthor 6/11/2025 00:22'!
initialize
items := 1 to: 30! !
!ItemHolder methodsFor: 'accessing' stamp: 'GlamorousAuthor 6/11/2025 00:22'!
items
^ items! !
!ItemHolder methodsFor: '*GToolkit-Inspector' stamp: 'GlamorousAuthor 6/11/2025 01:12'!
gtItemsWithFilterView: aView
<gtView>
| anAnnouncer itemsToDisplay buttonLabel |
anAnnouncer := Announcer new.
itemsToDisplay := self items.
buttonLabel := 'Predicate'.
^ aView explicit
title: 'Items w/filter';
priority: 51;
stencil: [ | menuItemBuilder aMenuItems contentBuilder menuDropdownButton anInspector |
menuItemBuilder := [ :id :label :pred |
BrMenuActionItem new
id: id;
label: label;
hideOnClick: true;
action: [ :anElement |
buttonLabel := 'Predicate: {1}' format: {anElement menuItem labelModel text}.
itemsToDisplay := self items select: pred.
anAnnouncer announce: Announcement new ] ].
aMenuItems := BrMenuItems new.
aMenuItems
addItem: (menuItemBuilder
value: #item1
value: '#even'
value: #even).
aMenuItems
addItem: (menuItemBuilder
value: #item2
value: '#odd'
value: #odd).
aMenuItems
addItem: (menuItemBuilder
value: #item3
value: '[ : each | each isPrime]'
value: [ :each | each isPrime ]).
menuDropdownButton := BrButton new
aptitude: BrGlamorousButtonWithLabelAptitude;
id: #menuDropdownButton;
label: buttonLabel;
constraintsDo: [ :c |
c margin: (BlInsets all: 5).
c frame horizontal alignCenter.
c frame vertical alignCenter ];
addAptitude: (BrGlamorousWithExplicitDropdownAptitude
handle: [ BrButton new
id: #'menu-dropdown-handle';
aptitude: BrGlamorousButtonWithLabelAptitude - BrGlamorousButtonExteriorAptitude;
label: 'Predicate' ]
menu: aMenuItems).
contentBuilder := [ BlElement new
layout: BlLinearLayout vertical;
constraintsDo: [ :c |
c vertical matchParent.
c horizontal matchParent ] ].
anInspector := GtInspector
forObject: itemsToDisplay
viewSelector: #gtItemsFor:.
BrVerticalPane new
vFitContent;
hMatchParent;
addChild: (contentBuilder value
addChildren: {menuDropdownButton.
anInspector}) ];
updateWhen: Announcement in: [ anAnnouncer ]! !
!ItemHolder methodsFor: '*GToolkit-Inspector' stamp: 'GlamorousAuthor 6/11/2025 01:03'!
gtItemsView: aView
<gtView>
^ aView forward
title: 'Items';
priority: 50;
object: [ self items ];
view: #gtItemsFor:! !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment