Update location widget

This commit is contained in:
Bill 2021-06-13 04:12:21 -04:00
parent c55c0c1ee2
commit 535c9560df
2 changed files with 6 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import { ObjectLocationViewProps } from './ObjectLocationView.types';
export const ObjectLocationView: FC<ObjectLocationViewProps> = props => export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
{ {
const { objectId = -1, objectType = -1, children = null } = props; const { objectId = -1, category = -1, children = null } = props;
const [ posX, setPosX ] = useState(0); const [ posX, setPosX ] = useState(0);
const [ posY, setPosY ] = useState(0); const [ posY, setPosY ] = useState(0);
const elementRef = useRef<HTMLDivElement>(); const elementRef = useRef<HTMLDivElement>();
@ -13,13 +13,13 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
const updatePosition = useCallback(() => const updatePosition = useCallback(() =>
{ {
const roomSession = GetRoomSession(); const roomSession = GetRoomSession();
const objectBounds = GetRoomEngine().getRoomObjectBoundingRectangle(roomSession.roomId, objectId, objectType, 1); const objectBounds = GetRoomEngine().getRoomObjectBoundingRectangle(roomSession.roomId, objectId, category, 1);
if(!objectBounds) return; if(!objectBounds || !elementRef.current) return;
setPosX(Math.round(((objectBounds.left + (objectBounds.width / 2)) - (elementRef.current.offsetWidth / 2)))); setPosX(Math.round(((objectBounds.left + (objectBounds.width / 2)) - (elementRef.current.offsetWidth / 2))));
setPosY(Math.round((objectBounds.top - elementRef.current.offsetHeight) + 10)); setPosY(Math.round((objectBounds.top - elementRef.current.offsetHeight) + 10));
}, [ objectId, objectType ]); }, [ objectId, category ]);
useEffect(() => useEffect(() =>
{ {
@ -32,7 +32,7 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
}, [ updatePosition ]); }, [ updatePosition ]);
return ( return (
<div ref={ elementRef } className="position-absolute w-100" style={ { left: posX, top: posY } }> <div ref={ elementRef } className="position-absolute" style={ { left: posX, top: posY } }>
{ children } { children }
</div> </div>
); );

View File

@ -1,5 +1,5 @@
export interface ObjectLocationViewProps export interface ObjectLocationViewProps
{ {
objectId: number; objectId: number;
objectType: number; category: number;
} }