How can I align text inside a GnomeCanvas text item - gtk

I would like to have a GnomeCanvas text item and according to its content (and the content language) decide whether to align the text to the right or to the left.
I found one way to do it by changing the anchor property, but using this method would require me to manage the anchor position myself (change it to the right of the text bounding box when aligning to the right), and it seems there must be a simpler way.
EDIT: I see there is also the justification property, which allows me to align the text to the right. However, I still need to set the anchor point according to the language, instead of setting a bounding box that would apply to any language.

Its about a month without another answer. I guess my first understanding was correct and there isn't another way with the canvas. My solution would then be to change the anchor to east and change the anchor point accordingly.

Related

Text aligment cursor problem in user Input field (WIX sites)

I'm creating my own site on the Wix platform, and I met one problem. When I'm setting up text alignment to the right side, after starting typing, the cursor moves to the left side of the text, but I want to make it usual and keep it on the right side (with left and center text alignment it works fine). I can't find any setting in Wix, to fix this.
I don't think that I can add custom CSS code in WIX elements, but I can add some JS code there/
Cursor problem image
I would appreciate any help

Keep cursor position on bottom line in textView Swift

I need to create a UI where, as the user types, the cursor/typing area stays in the middle of the page and the newly typed text is pushed 'up and off' the top of the page.
I've tried to set the cursor position to the bottom of a text view which covers 0.6 of the superview but that doesn't work (presumably because it doesn't have any text?). This is a great answer for general cursor placement but my use case isn't catered for.
The code I used to try place the cursor at the end of the text view is :
func setCursorPosition() {
let newPosition = textViewOutlet.endOfDocument
textViewOutlet.selectedTextRange = textViewOutlet.textRange(from: newPosition, to: newPosition)
}
This doesn't work because it is looking for filled in text but sometimes the text view would be empty and I'd still need to load it on the bottom line.
The effect I'm trying to create would look like this :
quite a complex problem I think - any ideas?
For people who have this problem in future. I solved this by coming at it from a different angle. Rather than attempting to place the cursor half way down the page, I removed the height constraints and made the text view dynamically resize based on the content.
Then I adjusted the constraints (helped by this answer) to fix the space to the bottom safe area but didn't specify a height.
This way, the text view dynamically resizes but in an upwards direction. When it reaches the gradient I have placed over the frame it starts to fade out.
Perfect (I also disabled scrolling to make this work)
Top tip - if something seems really hard there might be a different way to approach the problem!

How can I make a NSTextfield with left or right indicator for validation?

I need to make a custom NSTextField with an indicator like this:
https://i.stack.imgur.com/LAhfA.png
On the right side, you could see an indicator icon.
What code I need to make this?
Thanks for all.
EDIT
The text never could be overlap the icon. The icon is not always displayed, but it can be shown when it is being written and when the text is correct, this text must also occupy the position of the icon.
A text field control is a view where the drawing is all done with an NSTextFieldCell. What you'd need to do is subclass NSTextFieldCell, and customize the drawing. Look at NSCell's API and you'll see there's a drawWithFrame:inView: method which is what does all of the drawing for the entire field. Various other methods of NSCell are used in this process.
Unfortunately some of how the drawing is done is a bit private and not eeeasily fiddled with, but the main thing is drawWithFrame:inView: will draw the background and then call drawInteriorWithFrame:inView: to draw the text. Off the top of my head, I can't remember if NSTextFieldCell uses titleRectForBounds: to determine what the text's bounds are, but I'm pretty sure it is. So you could override that to return a narrower rectangle, leaving room to either draw the validation icon with the cell itself, or use a subview.
Additionally, you'll need to adjust the bounds in which the NSTextView field editor draws and edits the text, otherwise when you view the field while it is not first responder it will look fine, but when you edit the field's text it will overlap the icon. For that you may need to adjust the frame given to editWithFrame:inView:editor:delegate:event:.
It's always a bit finicky to tweak text fields because it takes a while to find all the methods and code paths involved, but that's the gist of what you need to do.

CodeMirror: auto-resize horizontally, without scrollbar

I need a CodeMirror editor which starts with a certain width and then grows automatically to the right to match the maximum line length. I.e. roughly what CodeMirror does when height is set to auto, but with width.
Here's a self-contained example. The editor grows automatically along the y-axis fine, but not along the x-axis. By tweaking the CSS, I can either have a fixed width editor with a scrollbar, or one which fills the entire width of the browser, but not one which grows as you type. I assume overflow-x is relevant, but I don't understand how it interacts with other CSS size properties set on parent elements. I also tried setting that property on CodeMirror-scroll, but it didn't help.
I believe this can be done using CSS properties alone. In fact I have this behaviour in my application already, but growing to the left, rather than the right, but I don't understand why it happens, or how to reproduce it in a small example.
This question is essentially the same, but for the vertical scrollbar.
Simply add float:left to the CodeMirror div.
<div id="here" style="float:left"></div>
This is not something CodeMirror supports. You may be able to get something working by setting .CodeMirror's width to (-webkit-)fit-content, but there will likely be corner cases where this breaks the scrollbars or cursor placement.

Graphview legend position

I can place the legend top, middle, bottom, but its always on the right side of the graphview. How can I place it left side?
The most important problem that "too long" texts doesn't fit in the box, so the end of the text is outside the box / screen. I know I can change the text size, but I don't want to solve the problem in this way.
This solved my problem:
graph.getLegendRenderer().resetStyles();
Just called if I need to resize the legend box.
in the current version it's also possible to freely set the position of legend and also the width