How can I stop Immediate GUI from selecting all text on click - unity3d

Unitys Immediate GUI insists on selecting all contents of any text-based input field (TextField, TextArea, IntField...) every time you click into it (and it hasn't got focus already).
Is there a way to prevent this?

Unity itself does not offer a way to prevent this.
After trying many solutions I found elsewhere and failing I did some reverse engineering and came up with the following workaround.
This wrapper method will prevent select-all by temporarily setting cursorColor.a to 0. Internally, Unity will only do select-all when the cursor is not transparent.
private T WithoutSelectAll<T>(Func<T> guiCall)
{
bool preventSelection = (Event.current.type == EventType.MouseDown);
Color oldCursorColor = GUI.skin.settings.cursorColor;
if (preventSelection)
GUI.skin.settings.cursorColor = new Color(0, 0, 0, 0);
T value = guiCall();
if (preventSelection)
GUI.skin.settings.cursorColor = oldCursorColor;
return value;
}
Use it like this:
int foo;
string bar;
foo = WithoutSelectAll(() => GUI.IntField("foo", foo));
bar = WithoutSelectAll(() => EditorGUILayout.TextArea(bar));

#Thomas Hilbert
change
bool preventSelection = (Event.current.type == EventType.MouseDown);
to
bool preventSelection = Event.current.type != EventType.Repaint;

Related

Gtk (mm) limit width of combobox

Because I use Comboboxes that may contain text entries of very long size,
which leads to the combobox increasing its width far beyond reasonable size,
I am trying to give a maximum width to the combobox.
If I am doing this like this:
class MyCombo : public Gtk::ComboBox {
private:
CellRendererText render;
public:
MyCombo() {
render.property_width_chars() = 10;
render.property_ellipsize() = Pango::ELLIPSIZE_END;
pack_start(render, true);
}
};
The result will be an empty cell of the desired width, which seems logical since I did not specify which column to show. But how can I do this with that attempt? Using pack_start will just bypass the renderer...
Another approach is this one:
class MyCombo : public Gtk::ComboBox {
private:
CellRendererText render;
public:
MyCombo() {
pack_start(render, true);
set_cell_data_func(render, sigc::mem_fun(*this, &MyCombo::render_iter));
}
void render_iter(const TreeModel::const_iterator& iter) {
Glib::ustring data = get_string_from_iter(iter);
int desired_width_chars = 10; //for example
render.property_text() = ellipsize_string(data, desired_width_chars);
}
};
Using that approach, it works, but the text in the popup (what opens up when u click the combobox) is also shortened which is not what I want (obviously the user should be able to read the whole string and I dont care about the popup widht.)
Can you please help me with this? I would be happy for any advice/alternative solutions.
Regards tagelicht
NOTE: set_wrap_width is a function that wraps the total number of entries in the combo box over a number of columns specified; it does not answer the question.
Using set_wrap_width(1) | Using set_wrap_width(5)
Following Noup's answer as a guide I managed to get the below code; which directly answers the question and its requirements (C++/Gtkmm).
// Get the first cell renderer of the ComboBox.
auto v_cellRenderer = (Gtk::CellRendererText*)v_comboBox.get_first_cell();
// Probably obsolete; Sets character width to 1.
v_cellRenderer->property_width_chars() = 1;
// Sets the ellipses ("...") to be at the end, where text overflows.
// See Pango::ELLIPSIZE enum for other values.
v_cellRenderer->property_ellipsize() = Pango::ELLIPSIZE_END;
// Sets the size of the box, change this to suit your needs.
// -1 sets it to automatic scaling: (width, height).
v_cellRenderer->set_fixed_size(200, -1);
Result (image):
Result of code
BE AWARE: Depending on where you perform the above code; either all the cells will be the same size, or just the box itself (intended).
From experimenting, I've found:
In the parent object constructor: All cell sizes are the same.
In a separate function: Only the first cell (the box) is affected.
I'd recommend you put the code in a function that's connected to the comboBox's changed signal, such as:
v_comboBox.signal_changed().connect(sigc::mem_fun(*this, &YourClass::comboBox_changedFunction));
This may be what you are looking for:
cell_renderer_text.set_wrap_width(10)
This is for Python, but you get the idea :-)
Unfortunately, the documentation is scarce. I found this by poking around in Anjuta/Glade.
Edit:
the docs are here. They are not overly helpful, but they do exist.
As an alternative, the following works for me without having to set wrap_width nor to subclass ComboBox (in Gtk#):
ComboBoxText cb = new ComboBoxText();
cb.Hexpand = true; //If there's available space, we use it
CellRendererText renderer = (cb.Cells[0] as CellRendererText); //Get the ComboBoxText only renderer
renderer.WidthChars = 20; //Always show at least 20 chars
renderer.Ellipsize = Pango.EllipsizeMode.End;
Note: I'm using Expand to use space if it's available. If you just want to keep the combo box on a fixed width, just remove that bit.

JSX/Photoshop: Toggling non selected layer visibility by name?

I'm using this piece for hide/show selected layer:
app.activeDocument.activeLayer.visible = !app.activeDocument.activeLayer.visible;
I wonder if there exist a way of toggling a non selected layer by it's name.
Many thanks
Update:
I got it working with this thing (I know, it must be cleaned):
function toggleLayer() {
for( var i = 0; i < app.activeDocument.artLayers.length; i++) {
if (app.activeDocument.artLayers[i].name == "theLayer"){
app.activeDocument.artLayers[i].allLocked = false;
app.activeDocument.artLayers[i].visible = !app.activeDocument.artLayers[i].visible;
}
}
}
I'd like to know if we can do the same without the loop.
Thanks
Here is the solution I did write. Unexpectedly it worked :P
function toggleLayer() {
var tl = app.activeDocument.layers["theLayer"];
tl.visible = !tl.visible;
}
toggleLayer();
Now, I have another doubt: Whats the difference between "layers" and "artLayers"?
Cheers

GXT 3 - Sorting causes grid to horizontally scroll

If I try to sort a column that's out of view (I need to scroll on the right to see it)
then the column sorts but the table scrolls back to the left, (and the column i sorted is out of view again)
One can try this in the Basic Gid of the GXT showcase:
Just make the width of the columns larger so that the horizontal scroller shows up and then try to scroll at the end of the table and sort.
How to fix this?
Thanks
This is how I solved it:
Override onDataChanged of GridView and set preventScrollToTopOnRefresh to true before sorting and then set it back to whatever it was. I wonder why this is not the default behaviour.
final GroupSummaryView<Row> view = new GroupSummaryView<Row>()
{
protected void onDataChanged(StoreDataChangeEvent<Row> se)
{
boolean b = preventScrollToTopOnRefresh;
preventScrollToTopOnRefresh = true;
super.onDataChanged(se);
preventScrollToTopOnRefresh = b;
}
};
_table.setView(view);
There is no built-in feature to prevent that behavior, so you have to write it yourself. You just need to store the scroll state before sorting and restore it after:
// save scroll state
final int scrollTop = getView().getScroller().getScrollTop();
final int scrollLeft = getView().getScroller().getScrollLeft();
// restore scroll state
getView().getScroller().setScrollTop(scrollTop);
getView().getScroller().setScrollLeft(scrollLeft);
#Darek Kay : Thank You very much. I was having an issue of scroll down while changing the option by selecting value from EditorTreeGrid. Your suggesion worked for me. Here's what I did and worked for me :
final int scrollTop = editorTreeGrid.getView().getScroller().getScrollTop();
final int scrollLeft = ditorTreeGrid.getView().getScroller().getScrollLeft();
editorTreeGrid.getView().refresh(true);
editorTreeGrid.getView().getScroller().setScrollTop(scrollTop);
editorTreeGrid.getView().getScroller().setScrollLeft(scrollLeft);

Creating advanced user interfaces blackberry

I am looking out to create a text box similar to the image shown below in my blackberry form. As of now i am able to add a textfield which has a label like say
Name:(Cursor blinks)
Also when i try adding an image it doesnt show up beside the label but below it.I have tried aligning and adjusting image size etc but all in vain.How can layout managers help me do this any idea?
Can some one provide me an exact way as to how this can be achieved.Thanks in advance.
//Lets say adding textfield with validation for name
TextField1 = new TextField("\n Customer Name: ",null)
{
protected boolean keyChar(char ch, int status, int time)
{
if (CharacterUtilities.isLetter(ch) || (ch == Characters.BACKSPACE || (ch == Characters.SPACE)))
{
return super.keyChar(ch, status, time);
}
return true;
}
};
add(TextField1);
//Or either by using this,the text is placed within the image
Border myBorder = BorderFactory.createBitmapBorder(
new XYEdges(20, 16, 27, 23),
Bitmap.getBitmapResource("border.png"));
TextField myField = new TextField(" Write something ",TextField.USE_ALL_WIDTH | TextField.FIELD_HCENTER)
{
protected void paint(Graphics g) {
g.setColor(Color.BLUE);
super.paint(g);
}
};
myField.setBorder(myBorder);
add(myField);
//After trying out code given at Blackberry App Appearance VS Facebook App i am getting the following layout
I would still want to achieve a box that stands beside the label.Like the one shown in green image.Please guide.
Have a look to this answer. I think it may be helpful to you. Just play with the code until you get your desired look and feel.

Using Eclipse TableViewer, how do I navigate and edit cells with arrow keys?

I am using a TableViewer with a content provider, label provider, a ICellModifier and TextCellEditors for each column.
How can I add arrow key navigation and cell editing when the user selects the cell? I would like this to be as natural a behavior as possible.
After looking at some of the online examples, there seems to be an old way (with a TableCursor) and a new way (TableCursor does not mix with CellEditors??).
Currently, my TableViewer without a cursor will scroll in the first column only. The underlying SWT table is showing cursor as null.
Is there a good example of TableViewer using CellEditors and cell navigation via keyboard?
Thanks!
I don't know if there is a good example. I use a cluster of custom code to get what I would consider to be basic table behaviors for my application working on top of TableViewer. (Note that we are still targetting 3.2.2 at this point, so maybe things have gotten better or have otherwise changed.) Some highlights:
I do setCellEditors() on my TableViewer.
On each CellEditor's control, I establish what I consider to be an appropriate TraverseListener. For example, for text cells:
cellEditor = new TextCellEditor(table, SWT.SINGLE | getAlignment());
cellEditor.getControl().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
switch (e.detail) {
case SWT.TRAVERSE_TAB_NEXT:
// edit next column
e.doit = true;
e.detail = SWT.TRAVERSE_NONE;
break;
case SWT.TRAVERSE_TAB_PREVIOUS:
// edit previous column
e.doit = true;
e.detail = SWT.TRAVERSE_NONE;
break;
case SWT.TRAVERSE_ARROW_NEXT:
// Differentiate arrow right from down (they both produce the same traversal #*$&#%^)
if (e.keyCode == SWT.ARROW_DOWN) {
// edit same column next row
e.doit = true;
e.detail = SWT.TRAVERSE_NONE;
}
break;
case SWT.TRAVERSE_ARROW_PREVIOUS:
// Differentiate arrow left from up (they both produce the same traversal #*$&#%^)
if (e.keyCode == SWT.ARROW_UP) {
// edit same column previous row
e.doit = true;
e.detail = SWT.TRAVERSE_NONE;
}
break;
}
}
});
(For drop-down table cells, I catch left and right arrow instead of up and down.)
I also add a TraverseListener to the TableViewer's control whose job it is to begin cell editing if someone hits "return" while an entire row is selected.
// This really just gets the traverse events for the TABLE itself. If there is an active cell editor, this doesn't see anything.
tableViewer.getControl().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
// edit first column of selected row
}
}
});
Now, how exactly I control the editing is another story. In my case, my whole TableViewer (and a representation of each column therein) is loosely wrapped up in a custom object with methods to do what the comments above say. The implementations of those methods ultimately end up calling tableViewer.editElement() and then checking tableViewer.isCellEditorActive() to see if the cell was actually editable (so we can skip to the next editable one if not).
I also found it useful to be able to programmatically "relinquish editing" (e.g. when tabbing out of the last cell in a row). Unfortunately the only way I could come up with to do that is a terrible hack determined to work with my particular version by spelunking through the source for things that would produce the desired "side effects":
private void relinquishEditing() {
// OMG this is the only way I could find to relinquish editing without aborting.
tableViewer.refresh("some element you don't have", false);
}
Sorry I can't give a more complete chunk of code, but really, I'd have to release a whole mini-project of stuff, and I'm not prepared to do that now. Hopefully this is enough of a "jumpstart" to get you going.
Here is what has worked for me:
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(tableViewer,new FocusCellOwnerDrawHighlighter(tableViewer));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tableViewer) {
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
I can navigate in all directions with tab while editing, and arrow around when not in edit mode.
I got it working based on this JFace Snippet, but I had to copy a couple of related classes also:
org.eclipse.jface.snippets.viewers.TableCursor
org.eclipse.jface.snippets.viewers.CursorCellHighlighter
org.eclipse.jface.snippets.viewers.AbstractCellCursor
and I don't remember exactly where I found them. The is also a org.eclipse.swt.custom.TableCursor, but I couldn't get that to work.
Have a look at
Example of enabling Editor Activation on a Double Click.
The stuff between lines [ 110 - 128 ] add a ColumnViewerEditorActivationStrategy and TableViewerEditor. In my case the I wanted a single click to begin editing so i changed line 115 from:
ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
to ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION. After adding this to my TableViewer, the tab key would go from field to field with the editor enabled.