1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-27 03:48:21 +01:00

WIP: widgets implementation

This commit is contained in:
Dany LE 2022-03-21 22:39:52 +01:00
parent 91cfa95ef7
commit e99500acca
6 changed files with 131 additions and 32 deletions

View File

@ -103,9 +103,9 @@ Diya2DNode >> updateTF [
"scale" "scale"
scale = (1@1) ifFalse:[ scale = (1@1) ifFalse:[
tf := tf +* (Array2D scaleMatrix2D: scale)]. tf := tf +* (Array2D scaleMatrix2D: scale)].
self parent ifNil: [ ^self ].
self parent isRoot ifFalse: [tf := self parent tf +* tf ]. self parent isRoot ifFalse: [tf := self parent tf +* tf ].
children ifNotNil: [ children ifNotNil: [children do:[:c| c updateTF ]].
children do:[:c| c updateTF ]].
] ]

View File

@ -8,8 +8,8 @@ Class {
'fontSize', 'fontSize',
'fontFamilly', 'fontFamilly',
'borderColor', 'borderColor',
'width', 'bgcolor2',
'height' 'fontStyle'
], ],
#category : #'Diya-Graphics' #category : #'Diya-Graphics'
} }
@ -19,6 +19,16 @@ Diya2DNodeStyle >> bgcolor [
^ bgcolor ^ bgcolor
] ]
{ #category : #accessing }
Diya2DNodeStyle >> bgcolor2 [
^ bgcolor2
]
{ #category : #accessing }
Diya2DNodeStyle >> bgcolor2: anObject [
bgcolor2 := anObject
]
{ #category : #accessing } { #category : #accessing }
Diya2DNodeStyle >> bgcolor: anObject [ Diya2DNodeStyle >> bgcolor: anObject [
bgcolor := anObject bgcolor := anObject
@ -75,21 +85,11 @@ Diya2DNodeStyle >> fontSize: anObject [
] ]
{ #category : #accessing } { #category : #accessing }
Diya2DNodeStyle >> height [ Diya2DNodeStyle >> fontStyle [
^ height ^ fontStyle
] ]
{ #category : #accessing } { #category : #accessing }
Diya2DNodeStyle >> height: anObject [ Diya2DNodeStyle >> fontStyle: anObject [
height := anObject fontStyle := anObject
]
{ #category : #accessing }
Diya2DNodeStyle >> width [
^ width
]
{ #category : #accessing }
Diya2DNodeStyle >> width: anObject [
width := anObject
] ]

View File

@ -0,0 +1,18 @@
Class {
#name : #DiyaDefaultStyle,
#superclass : #Diya2DNodeStyle,
#category : #'Diya-Graphics'
}
{ #category : #initialization }
DiyaDefaultStyle >> initialize [
super initialize.
bgcolor := (Color r: 0.2118 g: 0.2118 b: 0.2118).
color := Color white.
border := 1.
fontSize := 18.
fontFamilly := DiyaFontManager uniqueInstance defaultFamily.
fontStyle := DiyaFontManager uniqueInstance defaultStyle.
borderColor := (Color r: 0.051 g: 0.051 b: 0.051).
bgcolor2 := (Color r: 0.1529 g: 0.1529 b: 0.1529)
]

View File

@ -33,16 +33,6 @@ DiyaExampleApp >> setup [
node borderWidth: 3.0. node borderWidth: 3.0.
node extent:200@200. node extent:200@200.
"style := DiyaFontManager uniqueInstance style: 'Regular' from:'Ubuntu'.
tex1 := (style textureOf: 18).
style := DiyaFontManager uniqueInstance style: 'Regular' from: 'bootstrap-icons'.
node := root addNode: (DiyaRectangle size: tex1 extent) at: 250 @ 300.
node color: (Color orange).
node texture: tex1.
node borderColor: Color red.
node borderWidth: 3.0."
node := root addNode: (DiyaText data: String loremIpsum) at: 10@400. node := root addNode: (DiyaText data: String loremIpsum) at: 10@400.
node extent: 240@320. node extent: 240@320.
node wordWrap: true. node wordWrap: true.
@ -51,7 +41,6 @@ DiyaExampleApp >> setup [
node color: (Color red). node color: (Color red).
node borderWidth: 2.0. node borderWidth: 2.0.
ell := root addNode: (DiyaEllipse rx:150 ry: 100) at: 320@300. ell := root addNode: (DiyaEllipse rx:150 ry: 100) at: 320@300.
ell borderColor: Color red. ell borderColor: Color red.
ell color: Color white. ell color: Color white.
@ -62,7 +51,6 @@ DiyaExampleApp >> setup [
ell on: #(mousebuttondown fingerdown) do:[:e| ell on: #(mousebuttondown fingerdown) do:[:e|
txtNode data: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString]. txtNode data: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString].
node := root addNode: (DiyaConvexPolygon points:{250@100. 400@250. 450@80. 350@60}). node := root addNode: (DiyaConvexPolygon points:{250@100. 400@250. 450@80. 350@60}).
node color: Color green. node color: Color green.
node borderColor: Color red. node borderColor: Color red.

View File

@ -1,5 +1,55 @@
Class { Class {
#name : #DiyaLabel, #name : #DiyaLabel,
#superclass : #DiyaWidget, #superclass : #DiyaWidget,
#instVars : [
'txt',
'icon'
],
#category : #'Diya-Widgets' #category : #'Diya-Widgets'
} }
{ #category : #accessing }
DiyaLabel >> applyStyle [
txt color: style color.
txt fontName: style fontFamily style: style fontStyle size: style fontSize.
txt wordWrap: true.
icon ifNotNil: [
icon color: style color.
icon fontSize: style fontSize
].
"update extent"
]
{ #category : #accessing }
DiyaLabel >> icon [
^ icon
]
{ #category : #accessing }
DiyaLabel >> icon: anObject [
icon := nil.
anObject isNumber ifTrue: [ icon := root addNode: (DiyaFontIcon data: anObject) ].
anObject isString ifTrue: [ icon := root addNode: (DiyaImageView from: anObject)].
icon ifNil: [ ^ DiyaCoreAPIError signal: 'Invalid icon identification'].
dirty := true.
]
{ #category : #initialization }
DiyaLabel >> initialize [
super initialize.
txt := root addNode:(DiyaText new).
icon := nil.
self extent: 0@0.
]
{ #category : #accessing }
DiyaLabel >> txt [
^ txt
]
{ #category : #accessing }
DiyaLabel >> txt: anObject [
txt data: anObject.
dirty := true
]

View File

@ -1,5 +1,48 @@
Class { Class {
#name : #DiyaWidget, #name : #DiyaWidget,
#superclass : #Diya2DNode, #superclass : #Diya2DNode,
#instVars : [
'style',
'extent'
],
#category : #'Diya-Widgets' #category : #'Diya-Widgets'
} }
{ #category : #'instance creation' }
DiyaWidget class >> fromStyle: aStyle [
^self new style: aStyle; yourself
]
{ #category : #accessing }
DiyaWidget >> applyStyle [
self subclassResponsibility
]
{ #category : #geometry }
DiyaWidget >> extent: size [
extent := size.
dirty := true.
]
{ #category : #initialization }
DiyaWidget >> initialize [
super initialize.
self style: DiyaDefaultStyle new.
]
{ #category : #accessing }
DiyaWidget >> style [
^ style
]
{ #category : #accessing }
DiyaWidget >> style: anObject [
style := anObject.
self applyStyle.
]
{ #category : #accessing }
DiyaWidget >> update [
self applyStyle.
^ true
]