Skip to content

Commit

Permalink
add ICNentry element for numerical entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucretiomsp committed Jan 20, 2025
1 parent 0314e6f commit e610710
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 2 deletions.
156 changes: 156 additions & 0 deletions CoypuIDE/ICNentry.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
"
A widget with a pair of buttons that increment or decrement a value.
"
Class {
#name : 'ICNentry',
#superclass : 'BlElement',
#instVars : [
'plus',
'minus',
'inputValue',
'value',
'inputLabel'
],
#category : 'CoypuIDE-numericalEntry',
#package : 'CoypuIDE',
#tag : 'numericalEntry'
}

{ #category : 'visual properties' }
ICNentry >> backgroundPaint [

^ Color black
]

{ #category : 'accessing' }
ICNentry >> borderPaint [

^ Color green
]

{ #category : 'buttons' }
ICNentry >> changeValueTo: aValue [

inputValue text: ( self configuredString: aValue asString).
inputValue text fontSize: 30.
value := aValue
]

{ #category : 'evaluating' }
ICNentry >> configuredString: aString [

^ aString asRopedText attributes:
{ (BlTextForegroundAttribute paint: self borderPaint ) }
]

{ #category : 'as yet unclassified' }
ICNentry >> createRect [

| rect |
rect := BlElement new
background: Color gray;
border: (BlBorder paint: self borderPaint width: 2);
size: 50 @ 28;
layout: BlFrameLayout new;
margin: (BlInsets all: 8);
geometry: (BlRoundedRectangleGeometry cornerRadius: 180).

^ rect
]

{ #category : 'buttons' }
ICNentry >> decreaseInput [

self changeValueTo: value + 1.
]

{ #category : 'buttons' }
ICNentry >> increaseInput [

self changeValueTo: value + 1.
]

{ #category : 'initialization' }
ICNentry >> initialize [

super initialize.
self size: self inputExtent.
self background: self backgroundPaint.
self geometry: (BlRoundedRectangleGeometry cornerRadius: 10).

self border: (BlBorder paint: self borderPaint width: 4).
"self label: 'Input'."
self initializePlusButton.
self initializeMinusButton.
self initializeInputValue: 0.
self layout: BlFrameLayout new
]

{ #category : 'initialization' }
ICNentry >> initializeInputValue: aValue [

inputValue := BlTextElement new.
inputValue constraintsDo: [ :c |
c frame horizontal alignCenter.
c frame vertical alignCenter ].
inputValue transformDo: [ :t | t translateBy: 0 @ 10 ].
self changeValueTo: aValue.
self addChild: inputValue
]

{ #category : 'as yet unclassified' }
ICNentry >> initializeMinusButton [

| rect |
rect := self createRect.
rect constraintsDo: [ :c | c frame horizontal alignRight ].
rect transformDo: [ :t | t translateBy: 0 @ 34 ].

plus := BlTextElement new text: (self configuredString: '-').
plus text fontSize: 30.
plus constraintsDo: [ :c |
c frame horizontal alignCenter.
c frame vertical alignCenter ].
rect
addEventHandlerOn: BlMouseDownEvent
do: [ :e | self increaseInput ].
rect addChild: plus.
self addChild: rect
]

{ #category : 'as yet unclassified' }
ICNentry >> initializePlusButton [

| rect |
rect := self createRect.
rect constraintsDo: [ :c | c frame horizontal alignRight ].

plus := BlTextElement new text: (self configuredString: '+').
plus text fontSize: 30.
plus constraintsDo: [ :c |
c frame horizontal alignCenter.
c frame vertical alignCenter ].
rect
addEventHandlerOn: BlMouseDownEvent
do: [ :e | self increaseInput ].
rect addChild: plus.
self addChild: rect
]

{ #category : 'accessing' }
ICNentry >> inputExtent [

^ 200 @ 80
]

{ #category : 'accessing' }
ICNentry >> label: aString [

inputLabel := BlTextElement new.
inputLabel text: (self configuredString: aString).
inputLabel text fontSize: 20.
inputLabel constraintsDo: [ :c | c frame horizontal alignCenter ].
inputLabel transformDo: [ :t | t translateBy: 0 @ 10 ].

self addChild: inputLabel
]
5 changes: 3 additions & 2 deletions CoypuIDE/ICSlider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,10 @@ ICSlider >> name [
]

{ #category : 'accessing' }
ICSlider >> name: aString [
ICSlider >> name: aString [

name := aString
name := aString.
self initializeLabel.
]

{ #category : 'api - values' }
Expand Down

0 comments on commit e610710

Please sign in to comment.