66 */
77
88import { ButtonDefaults } from '../constants' ;
9-
9+ import { trackMousePosition , isMouseInside } from '../utils'
1010//TODO adjust Opacity when focus, Blur
1111type PressEvent = { || } ;
1212type ButtonProps = { |
@@ -66,8 +66,6 @@ type ButtonProps = {|
6666| } ;
6767
6868function renderButton ( props : ButtonProps , apeContext , parentLayout ) {
69- //
70- console . log ( '[RENDER]' ) ;
7169 const { spatialGeometry = { x : 0 , y : 0 } } = parentLayout ;
7270 const { ctx} = apeContext ;
7371
@@ -79,7 +77,7 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
7977 const backgroundColor = ButtonDefaults . containerStyle . backgroundColor ;
8078 let x = spatialGeometry . x || 0 ;
8179 let y = spatialGeometry . y || 0 ;
82- let width = x + y ;
80+ let width = x + y * title . length / 3 ;
8381 let height = ButtonDefaults . containerStyle . height ;
8482 let globalStyle = {
8583 width : width ,
@@ -105,7 +103,7 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
105103 } ;
106104
107105 ctx . beginPath ( ) ;
108- ctx . fillStyle = color ;
106+ ctx . fillStyle = backgroundColor ;
109107 ctx . moveTo ( x , y ) ;
110108 /**
111109* Top Right Radius
@@ -152,27 +150,15 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
152150 width,
153151 } ;
154152 const mousePosition = trackMousePosition ( ctx . canvas , event ) ;
155- if ( isInside ( mousePosition , rect ) ) {
153+ if ( isMouseInside ( mousePosition , rect ) ) {
156154 redrawButton ( ctx ) ;
157155 if ( props . onClick && typeof props . onClick === 'function' ) {
158156 props . onClick ( event ) ;
159157 }
160158 }
161159 } ;
162- function trackMousePosition ( canvas , event ) {
163- return {
164- x : event . clientX - canvas . offsetLeft ,
165- y : event . clientY - canvas . offsetTop ,
166- } ;
167- }
168- const isInside = ( pos , rect ) => {
169- return (
170- pos . x > rect . x &&
171- pos . x < rect . x + rect . width &&
172- pos . y < rect . y + rect . height &&
173- pos . y > rect . y
174- ) ;
175- } ;
160+
161+
176162
177163 ctx . canvas . addEventListener ( 'click' , onClick , false ) ;
178164 ctx . canvas . addEventListener ( 'focus' , redrawButton ) ;
0 commit comments