summaryrefslogtreecommitdiffstats
path: root/source/widgets
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-12-27 22:19:15 +0100
committerDave Davenport <qball@gmpclient.org>2016-12-27 22:19:15 +0100
commit1c611b0eecff798c576771a72c58504579e581c8 (patch)
tree42d36af10625184a0e09b2556624a836fd77d04b /source/widgets
parentc5439118a70a8c8370ff3730962752356b3dd466 (diff)
First start at adding 4 sided padding
Diffstat (limited to 'source/widgets')
-rw-r--r--source/widgets/box.c95
-rw-r--r--source/widgets/listview.c16
-rw-r--r--source/widgets/separator.c22
-rw-r--r--source/widgets/widget.c13
4 files changed, 84 insertions, 62 deletions
diff --git a/source/widgets/box.c b/source/widgets/box.c
index 32680696..97d3c52d 100644
--- a/source/widgets/box.c
+++ b/source/widgets/box.c
@@ -33,14 +33,15 @@
#include "settings.h"
#define LOG_DOMAIN "Widgets.Box"
+const char *BOX_CLASS_NAME = "@box";
/**
* @param box Handle to the box widget.
- * @param padding The padding to apply.
+ * @param spacing The spacing to apply.
*
- * Set the padding to apply between the children in pixels.
+ * Set the spacing to apply between the children in pixels.
*/
-void box_set_padding ( box * box, unsigned int padding );
+void box_set_spacing ( box * box, unsigned int spacing );
struct _box
{
@@ -48,7 +49,7 @@ struct _box
boxType type;
int max_size;
// Padding between elements
- int padding;
+ int spacing;
GList *children;
};
@@ -72,15 +73,17 @@ static void vert_calculate_size ( box *b )
}
b->max_size += child->h;
}
- b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->padding ) );
- if ( b->max_size > b->widget.h ) {
+ int rem_width = b->widget.w - b->widget.pad.left-b->widget.pad.right;
+ int rem_height = b->widget.h - b->widget.pad.top-b->widget.pad.bottom;
+ b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
+ if ( b->max_size > rem_height ) {
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h );
return;
}
if ( active_widgets > 0 ) {
- int bottom = b->widget.h;
- int top = 0;
- double rem = b->widget.h - b->max_size;
+ int bottom = b->widget.h - b->widget.pad.bottom;
+ int top = b->widget.pad.top;
+ double rem = rem_height - b->max_size;
int index = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
@@ -92,30 +95,30 @@ static void vert_calculate_size ( box *b )
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
if ( child->end ) {
bottom -= expanding_widgets_size;
- widget_move ( child, child->x, bottom );
- widget_resize ( child, b->widget.w, expanding_widgets_size );
- bottom -= b->padding;
+ widget_move ( child, b->widget.pad.left, bottom );
+ widget_resize ( child, rem_width, expanding_widgets_size );
+ bottom -= b->spacing;
}
else {
- widget_move ( child, child->x, top );
+ widget_move ( child, b->widget.pad.left, top );
top += expanding_widgets_size;
- widget_resize ( child, b->widget.w, expanding_widgets_size );
- top += b->padding;
+ widget_resize ( child, rem_width, expanding_widgets_size );
+ top += b->spacing;
}
rem -= expanding_widgets_size;
index++;
}
else if ( child->end ) {
bottom -= widget_get_height ( child );
- widget_move ( child, child->x, bottom );
- widget_resize ( child, b->widget.w, child->h );
- bottom -= b->padding;
+ widget_move ( child, b->widget.pad.left, bottom );
+ widget_resize ( child, rem_width, child->h );
+ bottom -= b->spacing;
}
else {
- widget_move ( child, child->x, top );
+ widget_move ( child, b->widget.pad.left, top );
top += widget_get_height ( child );
- widget_resize ( child, b->widget.w, child->h );
- top += b->padding;
+ widget_resize ( child, rem_width, child->h );
+ top += b->spacing;
}
}
}
@@ -138,15 +141,17 @@ static void hori_calculate_size ( box *b )
// Size used by fixed width widgets.
b->max_size += child->w;
}
- b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->padding ) );
- if ( b->max_size > b->widget.w ) {
+ int rem_height = b->widget.h - b->widget.pad.top-b->widget.pad.bottom;
+ int rem_width = b->widget.w - b->widget.pad.left-b->widget.pad.right;
+ b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
+ if ( b->max_size > (rem_width)) {
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w );
return;
}
if ( active_widgets > 0 ) {
- int right = b->widget.w;
- int left = 0;
- double rem = b->widget.w - b->max_size;
+ int right = b->widget.w-b->widget.pad.right;
+ int left = b->widget.pad.left;
+ double rem = rem_width - b->max_size;
int index = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
@@ -158,30 +163,30 @@ static void hori_calculate_size ( box *b )
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
if ( child->end ) {
right -= expanding_widgets_size;
- widget_move ( child, right, child->y );
- widget_resize ( child, expanding_widgets_size, b->widget.h );
- right -= b->padding;
+ widget_move ( child, right, b->widget.pad.top);
+ widget_resize ( child, expanding_widgets_size, rem_height );
+ right -= b->spacing;
}
else {
- widget_move ( child, left, child->y );
+ widget_move ( child, left, b->widget.pad.top );
left += expanding_widgets_size;
- widget_resize ( child, expanding_widgets_size, b->widget.h );
- left += b->padding;
+ widget_resize ( child, expanding_widgets_size, rem_height );
+ left += b->spacing;
}
rem -= expanding_widgets_size;
index++;
}
else if ( child->end ) {
right -= widget_get_width ( child );
- widget_move ( child, right, child->y );
- widget_resize ( child, child->w, b->widget.h );
- right -= b->padding;
+ widget_move ( child, right, b->widget.pad.top );
+ widget_resize ( child, child->w, rem_height );
+ right -= b->spacing;
}
else {
- widget_move ( child, left, child->y );
+ widget_move ( child, left, b->widget.pad.top );
left += widget_get_width ( child );
- widget_resize ( child, child->w, b->widget.h );
- left += b->padding;
+ widget_resize ( child, child->w, rem_height );
+ left += b->spacing;
}
}
}
@@ -276,12 +281,11 @@ static gboolean box_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme
box * box_create ( const char *name, boxType type, short x, short y, short w, short h )
{
box *b = g_malloc0 ( sizeof ( box ) );
+ // Initialize widget.
+ widget_init ( WIDGET(b), name, BOX_CLASS_NAME);
b->type = type;
- b->widget.name = g_strdup (name);
- b->widget.x = x;
b->widget.y = y;
b->widget.w = w;
- b->widget.h = h;
b->widget.draw = box_draw;
b->widget.free = box_free;
b->widget.resize = box_resize;
@@ -290,7 +294,10 @@ box * box_create ( const char *name, boxType type, short x, short y, short w, sh
b->widget.motion_notify = box_motion_notify;
b->widget.enabled = TRUE;
- box_set_padding ( b, rofi_theme_get_integer ( "@box", b->widget.name, NULL, "padding",config.line_margin ));
+ box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin ));
+ // Do this dynamically
+ b->widget.h = h+b->widget.pad.top+b->widget.pad.bottom;
+ b->widget.x = x+b->widget.pad.left+b->widget.pad.right;
return b;
}
@@ -315,10 +322,10 @@ int box_get_fixed_pixels ( box *box )
return 0;
}
-void box_set_padding ( box * box, unsigned int padding )
+void box_set_spacing ( box * box, unsigned int spacing )
{
if ( box != NULL ) {
- box->padding = padding;
+ box->spacing = spacing;
widget_queue_redraw ( WIDGET ( box ) );
}
}
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index 5d663ac6..489a1250 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -54,7 +54,7 @@ struct _listview
unsigned int req_elements;
unsigned int cur_elements;
- unsigned int padding;
+ unsigned int spacing;
unsigned int menu_lines;
unsigned int menu_columns;
unsigned int fixed_num_lines;
@@ -163,15 +163,15 @@ static void listview_draw ( widget *wid, cairo_t *draw )
cairo_translate ( draw, wid->x, wid->y );
unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset );
if ( lv->rchanged ) {
- unsigned int width = lv->widget.w - lv->padding * ( lv->cur_columns - 1 );
+ unsigned int width = lv->widget.w - lv->spacing * ( lv->cur_columns - 1 );
if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) ) {
- width -= lv->padding;
+ width -= lv->spacing;
width -= widget_get_width ( WIDGET ( lv->scrollbar ) );
}
unsigned int element_width = ( width ) / lv->cur_columns;
for ( unsigned int i = 0; i < max; i++ ) {
- unsigned int ex = ( ( i ) / lv->max_rows ) * ( element_width + lv->padding );
- unsigned int ey = ( ( i ) % lv->max_rows ) * ( lv->element_height + lv->padding );
+ unsigned int ex = ( ( i ) / lv->max_rows ) * ( element_width + lv->spacing );
+ unsigned int ey = ( ( i ) % lv->max_rows ) * ( lv->element_height + lv->spacing );
textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height );
update_element ( lv, i, i + offset, TRUE );
@@ -249,7 +249,7 @@ static void listview_resize ( widget *wid, short w, short h )
listview *lv = (listview *) wid;
lv->widget.w = MAX ( 0, w );
lv->widget.h = MAX ( 0, h );
- lv->max_rows = ( lv->padding + lv->widget.h ) / ( lv->element_height + lv->padding );
+ lv->max_rows = ( lv->spacing + lv->widget.h ) / ( lv->element_height + lv->spacing );
lv->max_elements = lv->max_rows * lv->menu_columns;
widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET ( lv->scrollbar ) ), 0 );
@@ -338,7 +338,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->udata = udata;
// Some settings.
- lv->padding = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "padding", config.line_margin );
+ lv->spacing = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "spacing", config.line_margin );
lv->menu_lines = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "lines", config.menu_lines );
lv->menu_columns = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "columns", config.menu_columns);
lv->fixed_num_lines = rofi_theme_get_boolean ("@listview", lv->widget.name, NULL, "fixed-height", config.fixed_num_lines );
@@ -455,7 +455,7 @@ unsigned int listview_get_desired_height ( listview *lv )
if ( h == 0 ) {
return 0;
}
- return h * lv->element_height + ( h - 1 ) * lv->padding;
+ return h * lv->element_height + ( h - 1 ) * lv->spacing;
}
void listview_set_show_scrollbar ( listview *lv, gboolean enabled )
diff --git a/source/widgets/separator.c b/source/widgets/separator.c
index c04cecec..7aad0eee 100644
--- a/source/widgets/separator.c
+++ b/source/widgets/separator.c
@@ -33,6 +33,7 @@
#include "settings.h"
#include "theme.h"
+const char *SEPARATOR_CLASS_NAME = "@separator";
/**
* @param sp The separator widget handle.
* @param style_str String representation of the style.
@@ -69,17 +70,17 @@ static void separator_free ( widget * );
separator *separator_create ( const char *name, separator_type type, short sw )
{
separator *sb = g_malloc0 ( sizeof ( separator ) );
+ widget_init ( WIDGET (sb), name, SEPARATOR_CLASS_NAME );
sb->type = type;
- sb->widget.name = g_strdup ( name );
sb->widget.x = 0;
sb->widget.y = 0;
if ( sb->type == S_HORIZONTAL ) {
sb->widget.w = 1;
- sb->widget.h = MAX ( 1, sw );
+ sb->widget.h = MAX ( 1, sw )+sb->widget.pad.top+sb->widget.pad.bottom;
}
else {
sb->widget.h = 1;
- sb->widget.w = MAX ( 1, sw );
+ sb->widget.w = MAX ( 1, sw )+sb->widget.pad.left+sb->widget.pad.right;
}
sb->widget.draw = separator_draw;
@@ -88,7 +89,7 @@ separator *separator_create ( const char *name, separator_type type, short sw )
// Enabled by default
sb->widget.enabled = TRUE;
- const char *line_style = rofi_theme_get_string ( "@separator", sb->widget.name, NULL, "line-style", "solid");
+ const char *line_style = rofi_theme_get_string ( sb->widget.class_name, sb->widget.name, NULL, "line-style", "solid");
separator_set_line_style_from_string ( sb, line_style );
return sb;
}
@@ -129,22 +130,23 @@ static void separator_draw ( widget *wid, cairo_t *draw )
return;
}
color_separator ( draw );
- rofi_theme_get_color ( "@separator", wid->name, NULL, "foreground", draw );
+ rofi_theme_get_color ( wid->class_name, wid->name, NULL, "foreground", draw );
if ( sep->line_style == S_LINE_DASH ) {
const double dashes[1] = { 4 };
cairo_set_dash ( draw, dashes, 1, 0.0 );
}
if ( sep->type == S_HORIZONTAL ) {
cairo_set_line_width ( draw, wid->h );
- double half = wid->h / 2.0;
- cairo_move_to ( draw, wid->x, wid->y + half );
- cairo_line_to ( draw, wid->x + wid->w, wid->y + half );
+ int height= wid->h-wid->pad.top-wid->pad.bottom;
+ double half = height / 2.0;
+ cairo_move_to ( draw, wid->x+wid->pad.left, wid->y + wid->pad.top +half );
+ cairo_line_to ( draw, wid->x+wid->w-wid->pad.right, wid->y +wid->pad.top + half );
}
else {
cairo_set_line_width ( draw, wid->w );
double half = wid->w / 2.0;
- cairo_move_to ( draw, wid->x + half, wid->y );
- cairo_line_to ( draw, wid->x + half, wid->y + wid->h );
+ cairo_move_to ( draw, wid->x + wid->pad.left + half, wid->y +wid->pad.top);
+ cairo_line_to ( draw, wid->x + wid->pad.left + half, wid->y + wid->h-wid->pad.bottom );
}
cairo_stroke ( draw );
}
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index 93c14cff..04f52008 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -1,6 +1,16 @@
#include <glib.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
+#include "theme.h"
+
+
+void widget_init ( widget *widget , const char *name, const char *class_name )
+{
+ widget->name = g_strdup(name);
+ widget->class_name = g_strdup(class_name);
+ widget->pad = rofi_theme_get_padding (widget->class_name, widget->name, NULL, "padding", (Padding){0,0,0,0,FALSE});
+
+}
int widget_intersect ( const widget *widget, int x, int y )
{
@@ -72,6 +82,9 @@ void widget_free ( widget *wid )
if ( wid->name ) {
g_free ( wid->name );
}
+ if ( wid->class_name ) {
+ g_free( wid->class_name );
+ }
if ( wid->free ) {
wid->free ( wid );
}