Text-align and GTK CSS - gtk3

This is interesting, according to the docs there isn't a text-align and trying it gives
gi.repository.GLib.Error: gtk-css-provider-error-quark: <data>:3:14'text-align' is not a valid property name (3)
Is there an alternative to text-align: left/right/etc for buttons or other widgets with GTK CSS?

You might try the "gtk_widget_set_halign" function. Following is an example.
gtk_widget_set_halign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
The first parameter is the widget that you want to affect (e.g. a button). The second parameter is the type of alignment that you want to perform within the widget. The second parameter has five pre-defined constants:
GTK_ALIGN_BASELINE
GTK_ALIGN_CENTER
GTK_ALIGN_END
GTK_ALIGN_FILL
GTK_ALIGN_START
I hope that is clear.
Regards.

I should have updated with answer -
self.builder.get_object("button1").set_alignment(0,0);

Related

Modify an ag-grid row after rendering

I need to slightly modify a ag-grid row after it has been rendered. In ag-grid, the actual HTML elements are not necessarily persistent, so manually-set styles may fall off.
For one thing, I have to modify the selection checkbox to set its tabindex to -1. This can technically be done in the cellRenderer callback, although it looks quite hacky. (The checkbox can be found at params.eGridCell.children[0].children[0].wrappedElement.)
But I also have to add a CSS class to some rows to highlight them based on external criteria. I haven't found a way to do this at all.
The best solution would seem to be using some sort of after-rendering callback, but to my knowledge no such thing exists.
I found a couple of related questions, but they were both resolved via cellStyle, which would not suffice here:
Row formatting in ag-Grid
How to provide a background color for an entire row in ag grid based on a certain value in a column?
You have not 1 but 3 options:
getRowClass(params):
Callback version of property 'rowClass'. Function should return a string or an array of strings.
getRowStyle(params):
Callback version of property 'rowStyle'. Function should return an object of CSS values.
processRowPostCreate(params):
Allows you to process rows after they are created. So do final adding of custom attributes etc.
In this last one you have the row in params.eRow.
All taken from https://www.ag-grid.com/javascript-grid-callbacks/index.php

GWT Expand/Collapse boxes?

Im looking to create something like the image( https://www.dropbox.com/s/i2h1813c13v12y0/samp.jpg ) using GWT-UiBinder method. I cannot use a tree becoz i need the collapsed view to have - Title, a single field value , icons that that are like status symbols. The expanded view than contains the Title and icon like the collapsed but the value + additional values are displayed in detail.
please let me know your ideas! Examples would be great!!
Thanks
Are you looking for the DisclosurePanel? (with a custom header widget)
This looks like a use case for DeckLayoutPanel.
You should then embed any widget Image/Input/CellTable/DataGrid in each container per "Deck".
You might have some good example here - http://www.slideshare.net/martyhall/gwt-tutorial-laying-out-windows-with-panels-part-ii-composite-panels#btnNext
Edit - I probably did not understand the requirement correctly. Check out these demos.
http://examples.roughian.com/index.htm#Panels~DeckPanel
http://examples.roughian.com/index.htm#Panels~StackPanel
T Broyers Suggestion - http://examples.roughian.com/index.htm#Panels~DisclosurePanel

GWT Widget not properly set in the DOM

I would like to print a GWT widget which extends Composite. This widget is composed of a grid whose cells are built with a ListDataProvider. When the user clic on a button print, the widget to print is built. Once this is done, I launch the print:
Element element = widgetToPrint.getElement();
String content = element.getInnerHTML();
print(content);
public static native boolean print(String content)
/*-{
var mywindow = window.open('', 'Printing', '');
mywindow.document.write('<html><head><title>Test</title>');
mywindow.document.write('<link rel="stylesheet" href="/public/stylesheets/ToPrintWidget.css" type="text/css" media="all"/></head><body>');
mywindow.document.write(content);
mywindow.document.write('</body></html>');
mywindow.print();
return true;
}-*/;
So, here is my problem:
The window which is opened by this method contains the core of the widget (built by the UI Binder), but some children are missing...
If I look inside the ListDataProvider and its related FlowPanel, the data are consistent, i.e. I've got several item in my list and in the flowPanel.
Consequently, it should be visible on the printing window...
I thought that maybe the problem was related to the method used to print the widget, so I also tried to add this widget into a dialogbox just before launching the print, to see if the widget was properly built... and it was.
So my widget displays well on a dialogbox, but if I try to give its innerHTML to the print method, by using getElement(), some widgets are missing... I've the feeling that the widgets which should have been built when the ListDataProvider changes are not properly set in the DOM... Somehow it works when I add the widget to a regular component, but it doesn't work when I have to give directly its innerHTML...
Do you have any idea ?
Thanks in advance.
Widgets are not just the sum of their elements, and DOM elements are not just the string that they are serialized to. Widgets are the element, and all events sunk to the dom to listen for any changes or interactions by the user. Elements then have callback functions or handlers they invoke when the user interacts with them.
By serializing the element (i.e. invoking getInnerHTML()), you are only reading out the structure of the dom, not the callbacks, and additionally not the styles set by CSS. This probably shouldn't be expected to work correctly, and as your experience is demonstrating, it doesn't.
As this is just a print window you are trying to create, event handling is probably not a concern. You just want the ability to see, but not interact with, the content that would be in that set of widgets. Styles are probably the main problem here then (though your question doesn't specify 'some children are missing' doesn't tell us what is missing, or give us any more clues as to why...) - you are adding one stylesheet in your JSNI code, but CellTable (which I assume you are using since you reference ListDataProvider) needs additional CssResource instances to appear correctly. I'm not sure how you can hijack those to draw in a new window.
Are you only using this to print content, not to let the user directly interact with the data? If so, consider another approach - use a SafeHtmlBuilder to create a giant, properly escaped string of content to draw in the new window.
String content = element.toString();
This will include all hierarchy elements in the node.
Just a reminder, all the GWT handlers will not work, and you have to sink all the events using DOM.
You might want to grab the outer HTML rather than the inner one.
GWT unfortunately has no getOuterHTML, but it's relatively easy to emulate.
If your widget is the only child within an element, then simply get the inner HTML of the parent element (w.getElement().getParentElement().getInnerHTML())
Otherwise, clone your widget's node add it to a newly created parent element, from which you'll be able to get the inner HTML:
DivElement temp = Document.get().createDivElement();
temp.appendChild(w.getElement().cloneNode(true));
return temp.getInnerHTML();
First thank you for your answers, it helped me to work out this problem.
I've almost solve the problem:
First, I do not use ListDataProvider anymore, because it wasn't clear for me when and how the view was refreshed. Instead I add my widgets by hand, which makes sense since, they are not going to move anyway.
Then, I define the style of my widgets using a common CSS stylesheet. However, in order to do it, I can't rely on CssResource, which was the way I was used to do it with GWT. I think that this comes from the JS method which gets lost by this kind of styles... Instead, I have to specify everything in a static CSS stylesheet, and to give it to the JS.
It works perfectly well, ie, I have my widgets, with thei styles, and I can print it.
But...
The color of some widgets depends on the color of the object that they represent. Consequently, I cannot write a generic CSS stylesheet... And as I said, I can't add a style using CssResource... Do you have any ideas on the way to handle that ?
To make sure I'm clear on the way I'm adding styles, here is an example:
Label l = new Label("Here is a cell in my grid to be printed");
l.addStyleName("PrintLineCell-kind_1");
With, in a public CSS stylesheet:
.PrintLineCell-kind_1{
background-color: red;
}
I hope there is a better way than to write 300 styles to cover 300 different colors...

GWT Column turn off word wrap

I am using a Gwt DataGrid with multiple Columns. The default behavior of the columns is to wordwrap. I would like for one of the columns to not wordwrap and just cut off. Is this possible?
For example, currently this is displayed:
I am making a
sandwich
I would like it to display:
I am making a
In addition to overflow:hidden you may need white-space:nowrap and finally add a text-overflow: ellipsis so there is an indicator to the user that the incomplete text is being shown.
You can set overflow: hidden in the style of each Column.
You can use DataGrid.addColumnStyleName to set styles on individual columns, or just addStyleName to add a style to the whole widget.

Setting Cursor-Color in GTK+ 3

I'm looking to set a GtkTextView cursor-color. I know I can do it through the gtk_rc_parse command or something similar, but the documentation says that those commands are depreciated, and I don't think GtkCssProvider supports cursor-color. Is it possible to set it some other way?
This can be done in gtk3 with CSS. GtkTextView itself doesn't have a "cursor-color" property. You must go up in hierarchy to GtkWidget which does have that property and since GtkTextView is a type of GtkWidget you can style the GtkTextView through GtkWidget. So you use: -GtkWidget-cursor-color
This is true for other properties as well. For instance, "focus-line-width". This property is shared by several widgets including GtkButton and the rows of a GtkTreeView.
The style property listed for a specific widget in the documentation must be preceded by: -widgetname-
For instance, the only style property listed for GtkTextView is "error-underline-color" So in the CSS you would use: -GtkTextView-error-underline-color
Here's an example of changing "cursor-color" and other properties in a GtkTextView:
http://www.gtkforums.com/viewtopic.php?f=988&p=195276=Styling+a+GtkTextView+with+Gtk3+and+Css%3A#p195276
This is probably what you are looking for: http://developer.gnome.org/gtk3/3.0/GtkWidget.html#gtk-widget-override-cursor
Actually, there seem to be cursor-color style property:
http://developer.gnome.org/gtk3/3.0/GtkWidget.html#GtkWidget--s-cursor-color