From e99500accaec9d1581ac222d4fab419f83b3d4c0 Mon Sep 17 00:00:00 2001 From: Dany LE Date: Mon, 21 Mar 2022 22:39:52 +0100 Subject: [PATCH] WIP: widgets implementation --- Diya/Diya2DNode.class.st | 6 ++-- Diya/Diya2DNodeStyle.class.st | 32 +++++++++++----------- Diya/DiyaDefaultStyle.class.st | 18 ++++++++++++ Diya/DiyaExampleApp.class.st | 14 +--------- Diya/DiyaLabel.class.st | 50 ++++++++++++++++++++++++++++++++++ Diya/DiyaWidget.class.st | 43 +++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+), 32 deletions(-) create mode 100644 Diya/DiyaDefaultStyle.class.st diff --git a/Diya/Diya2DNode.class.st b/Diya/Diya2DNode.class.st index 2049b00..b9e888a 100644 --- a/Diya/Diya2DNode.class.st +++ b/Diya/Diya2DNode.class.st @@ -103,9 +103,9 @@ Diya2DNode >> updateTF [ "scale" scale = (1@1) ifFalse:[ tf := tf +* (Array2D scaleMatrix2D: scale)]. - self parent isRoot ifFalse: [ tf := self parent tf +* tf ]. - children ifNotNil: [ - children do:[:c| c updateTF ]]. + self parent ifNil: [ ^self ]. + self parent isRoot ifFalse: [tf := self parent tf +* tf ]. + children ifNotNil: [children do:[:c| c updateTF ]]. ] diff --git a/Diya/Diya2DNodeStyle.class.st b/Diya/Diya2DNodeStyle.class.st index 98f8b4e..c60bf50 100644 --- a/Diya/Diya2DNodeStyle.class.st +++ b/Diya/Diya2DNodeStyle.class.st @@ -8,8 +8,8 @@ Class { 'fontSize', 'fontFamilly', 'borderColor', - 'width', - 'height' + 'bgcolor2', + 'fontStyle' ], #category : #'Diya-Graphics' } @@ -19,6 +19,16 @@ Diya2DNodeStyle >> bgcolor [ ^ bgcolor ] +{ #category : #accessing } +Diya2DNodeStyle >> bgcolor2 [ + ^ bgcolor2 +] + +{ #category : #accessing } +Diya2DNodeStyle >> bgcolor2: anObject [ + bgcolor2 := anObject +] + { #category : #accessing } Diya2DNodeStyle >> bgcolor: anObject [ bgcolor := anObject @@ -75,21 +85,11 @@ Diya2DNodeStyle >> fontSize: anObject [ ] { #category : #accessing } -Diya2DNodeStyle >> height [ - ^ height +Diya2DNodeStyle >> fontStyle [ + ^ fontStyle ] { #category : #accessing } -Diya2DNodeStyle >> height: anObject [ - height := anObject -] - -{ #category : #accessing } -Diya2DNodeStyle >> width [ - ^ width -] - -{ #category : #accessing } -Diya2DNodeStyle >> width: anObject [ - width := anObject +Diya2DNodeStyle >> fontStyle: anObject [ + fontStyle := anObject ] diff --git a/Diya/DiyaDefaultStyle.class.st b/Diya/DiyaDefaultStyle.class.st new file mode 100644 index 0000000..d46a7e2 --- /dev/null +++ b/Diya/DiyaDefaultStyle.class.st @@ -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) +] diff --git a/Diya/DiyaExampleApp.class.st b/Diya/DiyaExampleApp.class.st index 1de13c2..00fd552 100644 --- a/Diya/DiyaExampleApp.class.st +++ b/Diya/DiyaExampleApp.class.st @@ -33,16 +33,6 @@ DiyaExampleApp >> setup [ node borderWidth: 3.0. 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 extent: 240@320. node wordWrap: true. @@ -50,8 +40,7 @@ DiyaExampleApp >> setup [ node := root addNode: (DiyaLine from: 10@620 to: 200@635). node color: (Color red). node borderWidth: 2.0. - - + ell := root addNode: (DiyaEllipse rx:150 ry: 100) at: 320@300. ell borderColor: Color red. ell color: Color white. @@ -62,7 +51,6 @@ DiyaExampleApp >> setup [ ell on: #(mousebuttondown fingerdown) do:[:e| 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 color: Color green. node borderColor: Color red. diff --git a/Diya/DiyaLabel.class.st b/Diya/DiyaLabel.class.st index 47b8c99..871f7db 100644 --- a/Diya/DiyaLabel.class.st +++ b/Diya/DiyaLabel.class.st @@ -1,5 +1,55 @@ Class { #name : #DiyaLabel, #superclass : #DiyaWidget, + #instVars : [ + 'txt', + 'icon' + ], #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 +] diff --git a/Diya/DiyaWidget.class.st b/Diya/DiyaWidget.class.st index c88d9f9..a456113 100644 --- a/Diya/DiyaWidget.class.st +++ b/Diya/DiyaWidget.class.st @@ -1,5 +1,48 @@ Class { #name : #DiyaWidget, #superclass : #Diya2DNode, + #instVars : [ + 'style', + 'extent' + ], #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 +]