//#style sendMessage
txtSendMessage = new TextField("Send Message","",150, TextField.ANY);
this.smsScreen.append(txtSendMessage);
In what language, java?
You can add an event listener to the textbox and every time, some one types a char, you can check the size of the text that the texbox is holding and change the style of the textbox.
If you want a more precise answer, please supply some more info about the programming language, what type of gui you are using etc. etc.
Related
A Button in Godot can only hold a single line of text. I can overcome this limitation by placing RichTextLabel node inside the button.
Now the button can contain more lines of text, but its height doesn't change automatically when more lines are needed. Instead the text just overflows:
Of course I can manually resize the button to be higher, but I'd like this to happen automatically depending on the amount of text inside. Specifically, I'm generating a list of these buttons programmatically and showing inside a HBoxContainer, with some buttons having longer and other shorter text.
Is there a way to achieve this with Godot layout tools?
Since the Button is in a Container, it is in control of its rect_size. The best we can do is specify a rect_min_size. There is no layout preset to have a Control depend on children Control. So, to answer the question as posted: No, we cannot achieve this with Godot layout tools. We need some scripting.
We need to set the rect_min_size for the Button depending on the RichTextLabel. We can ask it for the height of its content with get_content_height. Which also means we need to set the width beforehand. However, it will not update right away when we set the text (we are going to use yield).
Apparently you don't want the Container to control the height of the Button. If that is the case, I think you can remove all the flags from size_flags_vertical.
About the width, since as I was explaining before we need to set the width to get the height… I suggest you let the Container expand the width of the Button as much a posible. Which mean setting both the Fill and Expand flags on size_flags_horizontal.
Then, with the RichTextLabel properly set to take as much width of the parent Button as possible, you can read it height, and use it to set the height of the rect_min_size of the Button.
One more thing: you want to set the mouse filter of the RichTextLabel to Ignore or Pass, or it will prevent pressing the Button.
This is the code I came up with:
var b := Button.new()
b.size_flags_vertical = 0
b.size_flags_horizontal = SIZE_EXPAND_FILL
add_child(b)
var l := RichTextLabel.new()
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
l.set_anchors_and_margins_preset(Control.PRESET_WIDE)
l.text = "Some\nMultiline\nText"
b.add_child(l)
yield(get_tree(), "idle_frame")
b.rect_min_size.y = l.get_content_height()
I'd like this to happen automatically depending on the amount of text inside
Sadly changing the text does not resize, nor change the minimum size of the RichTextLabel. And RichTextLabel does not have a "text changed" signal. Nor "bbcode text changed" signal. Furthermore, it might not be feasible to intercept these properties (see append_bbcode et.al). It is proabaly easier to do with a regular Label.
Anyway, what I'm going to suggest for this is to make a Control that wraps the RichTextLabel, offers whatever interface you actually need, and in any method where you change the text, afterwards, you do the equivalent of this:
yield(get_tree(), "idle_frame")
b.rect_min_size.y = l.get_content_height()
(Godot 3.x)
Without using scripting, it is also possible to achieve the same goal by wrapping both nodes as sibilings within a container, for example a MarginContainer. Enable the RichTextLabel's fit_content_height property, which will result in the label expanding the container's area as much as necessary, which will in turn resize the Button.
Am a newbee to javascript but have plenty of experience in VB, C, and even 86 assembler. Maybe I am trying to do the impossible in porting a VB app to js here. Basically, I need to change the color for only part of the string in an input element. Here is the problem:
A function takes an entered input box text field, and processes it first to see if it is in conformity to a set of requirements. If part of that string is not in conformity, I would like to in some way highlight that part in the input field. For instance, maybe I can send back the string to the input element (eg using the value attribute) but with some highlighting for that part, such as changing its text color or background color. Is this possible in js?
I'm not sure whether you can change colors of partial text in a simple text box. But what you're trying to do is certainly possible with this: https://editorjs.io/
The example on the homepage shows you how.
I hope this is a possibility for you and not too heavy for your purpose.
Simple question, not sure if there is an answer.
Imagine you have 2 text boxes in a tkinter window, is it possible to know which of the 2 the user is focused on, then return the text widget object itself, or a variable that tells you something.
**Context: **Trying to insert a set of characters at the users cursor, but I want it to add it at their cursor regardless of the text box. Instead of:
self.text1.insert(tk.INSERT, "
Some text..."), I want self.focusedText.insert(tk.INSERT, "
Some text at your cursor in the focused text widget..."). Is there some way to figure out which of many Text widgets a user is focused on? Thanks!
I have a TextArea in my application that actually takes no interactions from the user.
Is there a way to either
Remove the scrollbar entirely and let me handle what happens when the scrollbar would appear?
Use a different object to display text to the screen? I need to be able to append text, but I don't need it to be highlight-able or take any user input.
According to your needs, you need to use label.
If you need TextArea, to remove scrollBars, you can do the next :
Use lookupAll(java.lang.String selector) method to find scrollBars, and
call scrollBar.setOpacity(0.0) for each found scrollBar.
2a. Don't call setVisible(false), as visible property (I believe) is used to TextArea to control scrollBar visibility.
We have a legacy code MFC VC++ one.
I need to add a message box asking for 2 inputs(both are string).
No need to consider security issue. Just need input.
How to do this?
I am really not MFC guy. Searched several pages. Not good for me.
Best
Thank you
To get input you want a dialog, not a message box.
Assuming you're working in VS, you'll go to the resource view, expand the tree, right-click on "Dialog" and pick "Insert Dialog" from the pop-up menu. That'll let you draw your dialog, where you'll insert a couple of edit controls, probably with a static control next to each to describe what to enter there, etc. It'll start out with Ok and Cancel buttons, so you don't need to add those.
Once you've drawn what the dialog will look like, you need to add some code and such to back it up. Right click on one of the controls, and pick "Add Class" from the menu. That'll bring up a dialog that'll ask for the name of the class for the dialog. You'll enter some class name (e.g., "my_input") and it'll pick matching names for the source/header file. You'll probably want to change the base class from "CDHtmlDialog" to "CDialog". When you're happy with that, click "finish" and it'll create the class/files.
Then you'll go back to the dialog, right-click in one of the edit controls, and choose "add variable". To keep things simple toward the far right, change the "Category" from "Control" to "Value". Then pick a name for the string you'll receive from that control and click Ok. Repeat for the other control. Repeat for the other edit control (obviously choosing a different name for its variable).
The last thing you need to add is some code to invoke that dialog. To do that, you'll need to include the dialog's header in where you're going to use it. Then you'll add a bit of code something like:
my_input inp;
if (inp.DoModal() == IDOK) {
// retrieve your two strings
CString input1 = inp.field1;
Cstring input2 = inp.field2;
}