I'm looking to set the size of a button within a box and row in a listbox to just be the size of a single character. I would like the button to be a small remove button, which is just a small square big enough to hold a single 'X' character.
I'm having trouble getting the button to go any smaller than this:
This is my current code:
GtkWidget *row1;
GtkWidget *box1;
GtkWidget *label1;
GtkWidget *remBox1;
GtkWidget *remBtn1;
GtkWidget *remBtnLbl1;
remBtnLbl1 = gtk_label_new("X");
gtk_widget_set_name(remBtnLbl1,"remBtnLabels");
row1 = gtk_list_box_row_new();
box1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 100);
label1 = gtk_label_new("Test");
remBox1 = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
remBtn1 = gtk_button_new();
gtk_widget_set_margin_start(remBtnLbl1, 0);
gtk_widget_set_margin_end(remBtnLbl1, 0);
gtk_container_add(GTK_CONTAINER(remBtn1), remBtnLbl1);
gtk_widget_set_name(remBtn1, "remButtons");
gtk_widget_set_size_request(remBox1, 1, -1);
gtk_widget_set_size_request(remBtn1, 1, 5);
gtk_box_pack_start(GTK_BOX(remBox1), remBtn1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box1), label1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box1), remBox1, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(row1), box1);
gtk_list_box_insert(GTK_LIST_BOX(hashListBox), row1, -1);
Stylesheet.css:
#remBtnLabels {
padding-left: 0px;
padding-right: 0px;
}
I've been trying all sorts of things to try and get the button smaller, and have been having no luck.
Any help would be greatly appreciated. Thanks.
In your specific example, just set the horizontal alignment of button:
gtk_widget_set_halign(remBtn1, GTK_ALIGN_END);
Related
trying to export a RingChart as png, I don't use title or legend, just the chart, still I have white space on the top and bottom:
creating via factory:
JFreeChart chart = ChartFactory.createRingChart(
null,
dataset,
false,
false,
false
);
the following didn't help:
chart.setPadding(new RectangleInsets(0, 0, 0, 0));
RingPlot plot = (RingPlot) chart.getPlot();
plot.setInsets(new RectangleInsets(0, 0, 0, 0.0));
I need the chart to be without any margins for the exported image, any idea?
Thanks
I'm new in the gtk's world and I cannot find a solution to this little problem.
I have this button :
But I would like that the small shadow behind the button can be removed.
I'd like this result :
How can I solve it?
Button's code:
sum_button = gtk_button_new_from_stock(GTK_STOCK_ADD);
/**/
style = gtk_widget_get_style(sum_button);
style->bg[GTK_STATE_PRELIGHT] = style->bg[GTK_STATE_NORMAL];
gtk_widget_set_style(sum_button, style);
/**/
gtk_widget_modify_bg(sum_button, GTK_STATE_NORMAL, &color2);
gtk_button_set_relief(GTK_BUTTON(sum_button), GTK_RELIEF_HALF);
g_signal_connect(G_OBJECT(sum_button), "clicked", G_CALLBACK(PrintNumber),&t_data);
gtk_box_pack_start(GTK_BOX (hbox3), sum_button, TRUE, TRUE, 0);
Try
gtk_button_set_relief(GTK_BUTTON(sum_button), GTK_RELIEF_NONE);
But then you can not set the background color:
When the button's border relief is set to none, it acts like a label as in it is "transparent", it has the same bg color as its parent container.
Take a look to this thread: https://stackoverflow.com/a/1709648/1606345
If you are writing new code, consider using GTK 3, where you can do this with CSS directly:
GtkCssProvider *provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(provider,
"button {"
" border: 0px;"
" background-color: green;"
" color: white;"
"}", -1, &error);
GtkStyleContext *context = gtk_widget_get_style_context(button);
gtk_style_context_add_provider(context, provider,
GTK_STYLE_PROVIDER_PRIORITY_USER);
I'm having this issue where when I resize the browser window, all the elements in the grid get cluttered on top of each other. I have added the link to how it looks before and after resizing window.
After resizing
Before resizing
The gridster options are as below:
$scope.gridsterOpts = {
columns: 10, // the width of the grid, in columns
pushing: false, // whether to push other items out of the way on move or resize
floating: true, // whether to automatically float items up so they stack (you can temporarily disable if you are adding unsorted items with ng-repeat)
swapping: true, // whether or not to have items of the same size switch places instead of pushing down if they are the same size
width: 'auto', // can be an integer or 'auto'. 'auto' scales gridster to be the full width of its containing element
colWidth: 'auto', // can be an integer or 'auto'. 'auto' uses the pixel width of the element divided by 'columns'
rowHeight: 'match', // can be an integer or 'match'. Match uses the colWidth, giving you square widgets.
margins: [30, 30], // the pixel distance between each widget
outerMargin: true, // whether margins apply to outer edges of the grid
isMobile: false, // stacks the grid items if true
mobileBreakPoint: 600, // if the screen is not wider that this, remove the grid layout and stack the items
mobileModeEnabled: true, // whether or not to toggle mobile mode when screen width is less than mobileBreakPoint
minColumns: 1, // the minimum columns the grid must have
minRows: 1, // the minimum height of the grid, in rows
maxRows: 100,
defaultSizeX: 2, // the default width of a gridster item, if not specifed
defaultSizeY: 1, // the default height of a gridster item, if not specified
minSizeX: 1, // minimum column width of an item
maxSizeX: 1, // maximum column width of an item
minSizeY: 1, // minumum row height of an item
maxSizeY: 1, // maximum row height of an item
resizable: {
enabled: false,
handles: ['n', 'e', 's', 'w', 'ne', 'se', 'sw', 'nw'],
start: function(event, $element, widget) {}, // optional callback fired when resize is started,
resize: function(event, $element, widget) {}, // optional callback fired when item is resized,
stop: function(event, $element, widget) {} // optional callback fired when item is finished resizing
},
draggable: {
enabled: true, // whether dragging items is supported
handle: '.my-class', // optional selector for resize handle
start: function(event, $element, widget) {}, // optional callback fired when drag is started,
drag: function(event, $element, widget) {}, // optional callback fired when item is moved,
stop: function(event, $element, widget) {} // optional callback fired when item is finished dragging
}
};
};
try this.
scope.$on('gridster-resized', function(sizes, gridster) {
// sizes[0] = width
// sizes[1] = height
// gridster.
})
I am using gtk_overlay_new () to create an overlay in gtk, is there any way i can add some background color to it? so far i have not been successful in finding anything in the documentation.
Use: void gtk_widget_override_background_color();
https://developer.gnome.org/gtk3/unstable/GtkWidget.html#gtk-widget-override-background-color
In GTK4 gtk_widget_override_background_color is no longer available. The same can be achieved with CSS using a style context.
GtkStyleContext *context = gtk_widget_get_style_context(someGtkWidget);
GtkCssProvider *provider = gtk_css_provider_new();
gtk_css_provider_load_from_data (provider, ".someClass { background: rgba(255,0,0,1)}", -1); //red
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_style_context_add_class (context, "someClass");
I have the following code:
void Test()
{
currentImage.Source = GetBitmap();
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}
This code is supposed to render currentImage, which is an Image control in my xaml to a RenderTargetBitmap.
It doesn't work, rtb returns a blank image, the problem is currentImage didn't render itself yet and so this behavior is expected, I think...
To workaround this problem, I wrote this code:
void Test()
{
currentImage.Source = GetBitmap();
this.Dispatcher.BeginInvoke((Action)delegate()
{
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}, System.Windows.Threading.DispatcherPriority.Render, null);
}
Basically, I wait for currentImage to be rendered and then I can get it properly rendered to my RenderTargetBitmap.
Is there any way to make it work without using this workaround? Force the Image control to render in memory maybe?
thanks!
use a ViewBox to render in memory
Grid grid = new System.Windows.Controls.Grid() { Background = Brushes.Blue, Width = 200, Height = 200 };
Viewbox viewbox = new Viewbox();
viewbox.Child = grid; //control to render
viewbox.Measure(new System.Windows.Size(200, 200));
viewbox.Arrange(new Rect(0, 0, 200, 200));
viewbox.UpdateLayout();
RenderTargetBitmap render = new RenderTargetBitmap(200, 200, 150, 150, PixelFormats.Pbgra32);
render.Render(viewbox);
I think this is a BETTER answer . The viewbox didn't work completely as expected, and it turned out to be an unnecessary overhead.
Here is a copy of that answer (instead of just link)
You need to force a render of the item, or wait for the item to be rendered. You can then use the ActualHeight and ActualWidth properties.
To force a render:
MenuItem item = new MenuItem();
item.Header = "bling";
item.Icon = someIcon;
//Force render
item.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
item.Arrange(new Rect(item.DesiredSize));
In this example the MenuItem has not been given an explicit height or width. However, forcing the render will render it taking the supplied header text and icon into consideration.