LayerTooltip.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { useContext, useMemo } from 'react'
  21. import { LayerContext } from '../util'
  22. import { SecondaryGraphTypes } from '../../Setting'
  23. import { useSelector } from 'react-redux'
  24. import { makeSelectCurrentOperateItemParams } from 'app/containers/Display/selectors'
  25. const LayerTooltip: React.FC = () => {
  26. const { operationInfo, layer } = useContext(LayerContext)
  27. const { resizing, dragging } = operationInfo
  28. const { id: layerId, subType } = layer
  29. const operateItemParams = useSelector(makeSelectCurrentOperateItemParams())
  30. const params = useMemo(
  31. () =>
  32. dragging
  33. ? operateItemParams.find((_) => _.id === layerId)?.params
  34. : layer.params,
  35. [dragging, operateItemParams, layer.params]
  36. )
  37. const labelText = useMemo(
  38. (): boolean => subType === SecondaryGraphTypes.Label,
  39. [subType]
  40. )
  41. const { positionX, positionY, width, height } = params
  42. let tooltip: string
  43. if (resizing) {
  44. tooltip = !labelText && `宽度:${width}px,高度:${height}px`
  45. } else if (dragging) {
  46. tooltip = `x:${positionX}px,y:${positionY}px`
  47. }
  48. return <div className="display-slide-layer-tooltips">{tooltip}</div>
  49. }
  50. export default LayerTooltip