# Absolut position of texts always relativ to upper left corner?

s_o shared this question 6 years ago

Hey,

is there a simple way to position a text in the upper right corner for example, and make it stay there, no matter if the window is resized or the coordinate system is changed?

Best regards,

Stefan

2

You can use the command Corner[], that refers to the four corners of the screen. If you pass the numbers (integers) 1, 2, 3 or 4 to the command, it generates points at the bottom-left, bottom-right, top-right and top-left corners of the screen. So Corner[3] indicates the upperright corner of the screen, which you can use to define the position of a text. Howerver, if you define Corner[3] as the position of the text, it will be placed outside of the screen, but you can correct it with a vector, depending on the lenght of the text you want to place in the corner. You can experiment with the example added in which the position of "text" is defined as Corner[3]+u.

chris

1

Yes, make sure "Absolute Position" is checked

1

I already found the corner command and tried a solution like Chris proposed, but for me that only works as long as I do not zoom, because the vector is not absolute (size relative to coord-system and not pixel). I also did not find a GeoGebra-command to get the scaling to adjust the vector correctly, does it exist I just did not find it? That returns the value Xscale or invXscale like getViewProperties in JavaScript?

1

I can think of a solution that allows zooming, but depends on the size of the screen and I can think of a solution that allows resizing of the screen, but doesn't allow zooming (= the proposed one in my first answer). A solution that allows resizing and zooming seems difficult if not impossible.

If the size of the screen remains the same you can think of puzzling with x and y values of the corners. It's not very practical (understatement) but it's aa zoomfree solution. Of course when you resize the screen also the point moves absolutely, not relatively. Also thinking in terms of pixels is no solution since the number of pixels will change while resizing the screen. Here's a zoomfree proposal.

chris

1

Hey, that is a great idea Chris, I tried it, but for a text that has some width it's not that great, a part is either hidden or there is unused space right of it.

This is probably the easiest solution: Use the corner-command for the points like you did and then a vector "offset" like this (if you want 200px left from and 100px down): offset=(-200*invXscale,-100*invYscale), then P = Point[RU,offset].

The trick now is JavaScript: You write a function that updates invXscale and invYscale (you can get these values with getViewProperties()) and attach this function with registerObjectUpdateListener to all 4 corner points. In theory everytime the corners are changing the offset is corrected. Just an idea, not yet tested.

2

Works perfect! Was even simpler, you can directly name the function in the Update tab of each points, example included

1

Even simpler without script:

invXscale=(x(Corner[2]) - x(Corner[1])) / x(Corner[5])

invYscale=(y(Corner[3]) - y(Corner[2])) / y(Corner[5])

That's how you get scaling without Javscript