mirror of
https://github.com/lbonn/rofi
synced 2024-11-15 00:27:36 +00:00
Fix some of the sizing issues.
This commit is contained in:
parent
04ad719c01
commit
eafd4697a2
7 changed files with 107 additions and 56 deletions
|
@ -41,6 +41,8 @@ struct _widget
|
|||
/** Handle mouse motion, used for dragging */
|
||||
gboolean ( *motion_notify )( struct _widget *, xcb_motion_notify_event_t * );
|
||||
|
||||
int (*get_desired_height) ( struct _widget * );
|
||||
|
||||
/** widget clicked callback */
|
||||
widget_clicked_cb clicked;
|
||||
/** user data for clicked callback */
|
||||
|
|
|
@ -176,5 +176,6 @@ gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
|
|||
|
||||
|
||||
void widget_set_name ( widget *wid, const char *name );
|
||||
int widget_get_desired_height ( widget *wid );
|
||||
/*@}*/
|
||||
#endif // ROFI_WIDGET_H
|
||||
|
|
|
@ -1361,26 +1361,10 @@ static int rofi_view_calculate_height ( RofiViewState *state )
|
|||
widget_enable ( WIDGET ( state->input_bar_separator ) );
|
||||
widget_enable ( WIDGET ( state->list_view) );
|
||||
}
|
||||
height = listview_get_desired_height ( state->list_view );
|
||||
// Why not a factor 2 here?
|
||||
height += window_get_border_width ( state->main_window );
|
||||
height += box_get_fixed_pixels ( state->main_box );
|
||||
// How to merge this....
|
||||
int perc =0;
|
||||
|
||||
|
||||
widget *main_window = WIDGET ( state->main_window );
|
||||
if ( main_window->pad.top >= 0 ){
|
||||
height += main_window->pad.top;
|
||||
} else {
|
||||
perc -= main_window->pad.top;
|
||||
}
|
||||
if ( main_window->pad.bottom >= 0 ){
|
||||
height += main_window->pad.bottom;
|
||||
} else {
|
||||
perc -= main_window->pad.bottom;
|
||||
}
|
||||
if ( perc > 0){
|
||||
height = (100*height)/(100-perc);
|
||||
}
|
||||
height = widget_get_desired_height ( main_window );
|
||||
return height;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,10 +56,43 @@ struct _box
|
|||
|
||||
static void box_update ( widget *wid );
|
||||
|
||||
static int box_get_desired_height ( widget *wid )
|
||||
{
|
||||
box *b = (box *)wid;
|
||||
int active_widgets = 0;
|
||||
int height = widget_padding_get_padding_height ( wid );
|
||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||
widget * child = (widget *) iter->data;
|
||||
if ( !child->enabled ) {
|
||||
continue;
|
||||
}
|
||||
active_widgets++;
|
||||
if ( child->expand == TRUE ) {
|
||||
height += widget_get_desired_height ( child );
|
||||
continue;
|
||||
}
|
||||
height += child->h;
|
||||
}
|
||||
if ( active_widgets > 0 ){
|
||||
height += (active_widgets - 1)*b->spacing;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
static void vert_calculate_size ( box *b )
|
||||
{
|
||||
int expanding_widgets = 0;
|
||||
int active_widgets = 0;
|
||||
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
||||
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||
widget * child = (widget *) iter->data;
|
||||
if ( child->enabled && child->expand == FALSE ){
|
||||
widget_resize ( child, rem_width, child->h );
|
||||
}
|
||||
}
|
||||
b->max_size = 0;
|
||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||
widget * child = (widget *) iter->data;
|
||||
|
@ -71,14 +104,15 @@ static void vert_calculate_size ( box *b )
|
|||
expanding_widgets++;
|
||||
continue;
|
||||
}
|
||||
b->max_size += child->h;
|
||||
if ( child->h > 0 ){
|
||||
b->max_size += child->h;
|
||||
}
|
||||
}
|
||||
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
||||
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
||||
if ( active_widgets > 0 ){
|
||||
b->max_size += ( active_widgets - 1 ) * b->spacing;
|
||||
}
|
||||
if ( b->max_size > rem_height ) {
|
||||
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;
|
||||
}
|
||||
|
@ -109,18 +143,16 @@ static void vert_calculate_size ( box *b )
|
|||
}
|
||||
rem -= expanding_widgets_size;
|
||||
index++;
|
||||
b->max_size += widget_padding_get_padding_height ( child);
|
||||
// b->max_size += widget_padding_get_padding_height ( child);
|
||||
}
|
||||
else if ( child->end ) {
|
||||
bottom -= widget_get_height ( child );
|
||||
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), bottom );
|
||||
widget_resize ( child, rem_width, child->h );
|
||||
bottom -= b->spacing;
|
||||
}
|
||||
else {
|
||||
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
|
||||
top += widget_get_height ( child );
|
||||
widget_resize ( child, rem_width, child->h );
|
||||
top += b->spacing;
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +163,14 @@ static void hori_calculate_size ( box *b )
|
|||
{
|
||||
int expanding_widgets = 0;
|
||||
int active_widgets = 0;
|
||||
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
||||
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||
widget * child = (widget *) iter->data;
|
||||
if ( child->enabled && child->expand == FALSE ){
|
||||
widget_resize ( child, child->w, rem_height );
|
||||
}
|
||||
}
|
||||
b->max_size = 0;
|
||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||
widget * child = (widget *) iter->data;
|
||||
|
@ -143,12 +183,13 @@ static void hori_calculate_size ( box *b )
|
|||
continue;
|
||||
}
|
||||
// Size used by fixed width widgets.
|
||||
if ( child->h > 0 ){
|
||||
b->max_size += child->w;
|
||||
}
|
||||
}
|
||||
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
||||
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
||||
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
|
||||
if ( b->max_size > (rem_width)) {
|
||||
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;
|
||||
}
|
||||
|
@ -179,18 +220,16 @@ static void hori_calculate_size ( box *b )
|
|||
}
|
||||
rem -= expanding_widgets_size;
|
||||
index++;
|
||||
b->max_size += widget_padding_get_padding_width ( child);
|
||||
// b->max_size += widget_padding_get_padding_width ( child);
|
||||
}
|
||||
else if ( child->end ) {
|
||||
right -= widget_get_width ( child );
|
||||
widget_move ( child, right, widget_padding_get_top ( WIDGET ( b ) ) );
|
||||
widget_resize ( child, child->w, rem_height );
|
||||
right -= b->spacing;
|
||||
}
|
||||
else {
|
||||
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
|
||||
left += widget_get_width ( child );
|
||||
widget_resize ( child, child->w, rem_height );
|
||||
left += b->spacing;
|
||||
}
|
||||
}
|
||||
|
@ -291,14 +330,15 @@ box * box_create ( const char *name, boxType type )
|
|||
box *b = g_malloc0 ( sizeof ( box ) );
|
||||
// Initialize widget.
|
||||
widget_init ( WIDGET(b), name, BOX_CLASS_NAME);
|
||||
b->type = type;
|
||||
b->widget.draw = box_draw;
|
||||
b->widget.free = box_free;
|
||||
b->widget.resize = box_resize;
|
||||
b->widget.update = box_update;
|
||||
b->widget.clicked = box_clicked;
|
||||
b->widget.motion_notify = box_motion_notify;
|
||||
b->widget.enabled = TRUE;
|
||||
b->type = type;
|
||||
b->widget.draw = box_draw;
|
||||
b->widget.free = box_free;
|
||||
b->widget.resize = box_resize;
|
||||
b->widget.update = box_update;
|
||||
b->widget.clicked = box_clicked;
|
||||
b->widget.motion_notify = box_motion_notify;
|
||||
b->widget.get_desired_height = box_get_desired_height;
|
||||
b->widget.enabled = TRUE;
|
||||
|
||||
box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin ));
|
||||
return b;
|
||||
|
@ -320,6 +360,7 @@ static void box_update ( widget *wid )
|
|||
int box_get_fixed_pixels ( box *box )
|
||||
{
|
||||
if ( box != NULL ) {
|
||||
printf("max size: %d\n", box->max_size);
|
||||
return box->max_size;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -322,12 +322,13 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
|
|||
listview *lv = g_malloc0 ( sizeof ( listview ) );
|
||||
|
||||
widget_init ( WIDGET ( lv ), name, "@listview" );
|
||||
lv->widget.free = listview_free;
|
||||
lv->widget.resize = listview_resize;
|
||||
lv->widget.draw = listview_draw;
|
||||
lv->widget.clicked = listview_clicked;
|
||||
lv->widget.motion_notify = listview_motion_notify;
|
||||
lv->widget.enabled = TRUE;
|
||||
lv->widget.free = listview_free;
|
||||
lv->widget.resize = listview_resize;
|
||||
lv->widget.draw = listview_draw;
|
||||
lv->widget.clicked = listview_clicked;
|
||||
lv->widget.motion_notify = listview_motion_notify;
|
||||
lv->widget.get_desired_height = listview_get_desired_height;
|
||||
lv->widget.enabled = TRUE;
|
||||
lv->eh = eh;
|
||||
|
||||
char *n = g_strjoin(".", lv->widget.name,"scrollbar", NULL);
|
||||
|
|
|
@ -35,7 +35,9 @@ void widget_resize ( widget *widget, short w, short h )
|
|||
{
|
||||
if ( widget != NULL ) {
|
||||
if ( widget->resize != NULL ) {
|
||||
widget->resize ( widget, w, h );
|
||||
if ( widget->w != w || widget->h != h ) {
|
||||
widget->resize ( widget, w, h );
|
||||
}
|
||||
}
|
||||
else {
|
||||
widget->w = w;
|
||||
|
@ -151,8 +153,6 @@ void widget_update ( widget *widget )
|
|||
if ( widget->update ) {
|
||||
widget->update ( widget );
|
||||
}
|
||||
// Recurse back.
|
||||
widget_update ( widget->parent );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,15 +253,25 @@ int widget_padding_get_remaining_height ( const widget *wid )
|
|||
}
|
||||
int widget_padding_get_padding_height ( const widget *wid )
|
||||
{
|
||||
int height = 0;
|
||||
int height = 0;
|
||||
height += widget_padding_get_top ( wid );
|
||||
height += widget_padding_get_bottom ( wid );
|
||||
return height;
|
||||
}
|
||||
int widget_padding_get_padding_width ( const widget *wid )
|
||||
{
|
||||
int width = 0;
|
||||
int width = 0;
|
||||
width += widget_padding_get_left ( wid );
|
||||
width += widget_padding_get_right ( wid );
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
int widget_get_desired_height ( widget *wid )
|
||||
{
|
||||
if ( wid->get_desired_height )
|
||||
{
|
||||
return wid->get_desired_height ( wid );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,17 @@ struct _window
|
|||
static void window_update ( widget *wid );
|
||||
|
||||
|
||||
static int window_get_desired_height ( widget *widget )
|
||||
{
|
||||
window *b = (window *) widget;
|
||||
int height = b->border_width*2;
|
||||
if ( b->child ) {
|
||||
height += widget_get_desired_height ( b->child );
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
static void window_draw ( widget *wid, cairo_t *draw )
|
||||
{
|
||||
window *b = (window *) wid;
|
||||
|
@ -126,13 +137,14 @@ window * window_create ( const char *name )
|
|||
window *b = g_malloc0 ( sizeof ( window ) );
|
||||
// Initialize widget.
|
||||
widget_init ( WIDGET(b), name, WINDOW_CLASS_NAME);
|
||||
b->widget.draw = window_draw;
|
||||
b->widget.free = window_free;
|
||||
b->widget.resize = window_resize;
|
||||
b->widget.update = window_update;
|
||||
b->widget.clicked = window_clicked;
|
||||
b->widget.motion_notify = window_motion_notify;
|
||||
b->widget.enabled = TRUE;
|
||||
b->widget.draw = window_draw;
|
||||
b->widget.free = window_free;
|
||||
b->widget.resize = window_resize;
|
||||
b->widget.update = window_update;
|
||||
b->widget.clicked = window_clicked;
|
||||
b->widget.motion_notify = window_motion_notify;
|
||||
b->widget.get_desired_height = window_get_desired_height;
|
||||
b->widget.enabled = TRUE;
|
||||
b->border_width = rofi_theme_get_integer (
|
||||
b->widget.class_name, b->widget.name, NULL, "border-width" , config.menu_bw);
|
||||
|
||||
|
|
Loading…
Reference in a new issue