Add orientation property.

This commit is contained in:
Dave Davenport 2017-06-02 14:05:19 +02:00
parent 85b6e32158
commit eec5c6eadc
7 changed files with 64 additions and 30 deletions

View File

@ -120,6 +120,8 @@ typedef enum
P_HIGHLIGHT,
/** List */
P_LIST,
/** Orientation */
P_ORIENTATION,
} PropertyType;
/**
@ -354,6 +356,16 @@ int rofi_theme_get_integer_exact ( const widget *widget, const char *property, i
*/
int rofi_theme_get_boolean ( const widget *widget, const char *property, int def );
/**
* @param widget The widget to query
* @param property The property to query.
* @param def The default value.
*
* Obtain the orientation indicated by %property of the widget.
*
* @returns The orientation of this property for this widget or %def not found.
*/
Orientation rofi_theme_get_orientation ( const widget *widget, const char *property, Orientation def );
/**
* @param widget The widget to query
* @param property The property to query.

View File

@ -47,24 +47,13 @@
*/
typedef struct _box box;
/**
* The packing direction of the box
*/
typedef enum
{
/** Pack widgets horizontal */
BOX_HORIZONTAL = 0,
/** Pack widgets vertical */
BOX_VERTICAL = 1
} boxType;
/**
* @param name The name of the widget.
* @param type The packing direction of the newly created box.
*
* @returns a newly created box, free with #widget_free
*/
box * box_create ( const char *name, boxType type );
box * box_create ( const char *name, Orientation type );
/**
* @param box Handle to the box widget.

View File

@ -199,6 +199,12 @@ ANGLE_GRAD "grad"
ANGLE_RAD "rad"
ANGLE_TURN "turn"
/* Orientation */
ORIENTATION_HORI "horizontal"
ORIENTATION_VERT "vertical"
/* Color schema */
RGBA rgb[a]?
HWB "hwb"
@ -484,6 +490,9 @@ if ( queue == NULL ){
<PROPERTIES>{ANGLE_GRAD} { return T_ANGLE_GRAD; }
<PROPERTIES>{ANGLE_TURN} { return T_ANGLE_TURN; }
<PROPERTIES>{ORIENTATION_HORI} { return ORIENTATION_HORI; }
<PROPERTIES>{ORIENTATION_VERT} { return ORIENTATION_VERT; }
<PROPERTIES>{COLOR_TRANSPARENT} {
return T_COLOR_TRANSPARENT;
}

View File

@ -188,6 +188,9 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token T_ANGLE_RAD "Radians"
%token T_ANGLE_TURN "Turns"
%token ORIENTATION_HORI "Horizontal"
%token ORIENTATION_VERT "Vertical"
%token T_COL_RGBA "rgb[a] colorscheme"
%token T_COL_HSL "hsl colorscheme"
%token T_COL_HWB "hwb colorscheme"
@ -236,6 +239,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%type <ival> t_property_highlight_style
%type <ival> t_property_line_style
%type <list> t_property_element_list
%type <ival> t_property_orientation
%start t_entry_list
%%
@ -372,6 +376,11 @@ t_property
$$->name = $1;
$$->value.list = $4;
}
| t_property_name T_PSEP t_property_orientation T_PCLOSE {
$$ = rofi_theme_property_create ( P_ORIENTATION );
$$->name = $1;
$$->value.i = $3;
}
;
/** List of elements */
@ -569,6 +578,11 @@ t_property_color_value
| T_INT { $$ = $1; }
;
t_property_orientation
: ORIENTATION_HORI { $$ = ORIENTATION_HORIZONTAL; }
| ORIENTATION_VERT { $$ = ORIENTATION_VERTICAL; }
;
/** Property name */
t_property_name
: T_PROP_NAME { $$ = $1; }

View File

@ -541,6 +541,16 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int def
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def;
}
Orientation rofi_theme_get_orientation ( const widget *widget, const char *property, Orientation def )
{
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_ORIENTATION, property, FALSE );
if ( p ) {
return p->value.b;
}
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def;
}
const char *rofi_theme_get_string ( const widget *widget, const char *property, char *def )
{

View File

@ -709,7 +709,7 @@ void __create_window ( MenuFlags menu_flags )
}
// Setup font.
// Dummy widget.
box *win = box_create ( "window.box_window", BOX_HORIZONTAL );
box *win = box_create ( "window.box_window", ORIENTATION_HORIZONTAL);
const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
if ( font ) {
PangoFontDescription *pfd = pango_font_description_from_string ( font );
@ -1497,7 +1497,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
* MAINBOX
*/
if ( strcmp ( name, "mainbox") == 0 ){
wid = (widget *)box_create ( strbox, BOX_VERTICAL );
wid = (widget *)box_create ( strbox, ORIENTATION_VERTICAL );
box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE, 0 );
defaults = "inputbar,message,listview";
}
@ -1505,7 +1505,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
* INPUTBAR
*/
else if ( strcmp ( name, "inputbar" ) == 0 ){
wid = (widget *)box_create ( strbox, BOX_HORIZONTAL );
wid = (widget *)box_create ( strbox, ORIENTATION_HORIZONTAL );
defaults = "prompt,entry,case-indicator";
box_add ( (box *)parent_widget, WIDGET ( wid ), FALSE, 0 );
@ -1571,7 +1571,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
*/
else if ( strcmp( name, "sidebar" ) == 0 ) {
if ( config.sidebar_mode ){
state->sidebar_bar = box_create ( strbox, BOX_HORIZONTAL );
state->sidebar_bar = box_create ( strbox, ORIENTATION_HORIZONTAL );
box_add ( (box*)parent_widget, WIDGET ( state->sidebar_bar ), FALSE, 10 );
state->num_modi = rofi_get_num_enabled_modi ();
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
@ -1589,7 +1589,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget,
textbox *t = textbox_create ( str, TB_WRAP, NORMAL, "");
box_add ( (box *)parent_widget, WIDGET(t), TRUE, 0);
} else {
wid = box_create ( strbox, BOX_VERTICAL );
wid = box_create ( strbox, ORIENTATION_VERTICAL );
box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE, 0 );
//g_error("The widget %s does not exists. Invalid layout.", name);
}
@ -1632,7 +1632,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
TICK_N ( "Get active monitor" );
state->main_window = box_create ( "window.box", BOX_VERTICAL );
state->main_window = box_create ( "window.box", ORIENTATION_VERTICAL );
// Get children.
GList *list = rofi_theme_get_list ( WIDGET(state->main_window), "children", "mainbox");
for ( const GList *iter = list; iter != NULL; iter = g_list_next ( iter )){
@ -1683,8 +1683,8 @@ int rofi_view_error_dialog ( const char *msg, int markup )
state->menu_flags = MENU_ERROR_DIALOG;
state->finalize = process_result;
state->main_window = box_create ( "window.box", BOX_VERTICAL );
box *box = box_create ( "window.mainbox.message.box", BOX_VERTICAL );
state->main_window = box_create ( "window.box", ORIENTATION_VERTICAL );
box *box = box_create ( "window.mainbox.message.box", ORIENTATION_VERTICAL );
box_add ( state->main_window, WIDGET ( box ), TRUE, 0 );
state->text = textbox_create ( "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
NORMAL, ( msg != NULL ) ? msg : "" );

View File

@ -40,7 +40,7 @@
struct _box
{
widget widget;
boxType type;
Orientation type;
int max_size;
// Padding between elements
Distance spacing;
@ -54,9 +54,9 @@ static void box_update ( widget *wid );
static int box_get_desired_width ( widget *wid )
{
box *b = (box *) wid;
int spacing = distance_get_pixel ( b->spacing, b->type == BOX_VERTICAL ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL );
int spacing = distance_get_pixel ( b->spacing, b->type );
int width = 0;
if ( b->type == BOX_HORIZONTAL ) {
if ( b->type == ORIENTATION_HORIZONTAL ) {
int active_widgets = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
@ -89,9 +89,9 @@ static int box_get_desired_width ( widget *wid )
static int box_get_desired_height ( widget *wid )
{
box *b = (box *) wid;
int spacing = distance_get_pixel ( b->spacing, b->type == BOX_VERTICAL ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL );
int spacing = distance_get_pixel ( b->spacing, b->type );
int height = 0;
if ( b->type == BOX_VERTICAL ) {
if ( b->type == ORIENTATION_VERTICAL) {
int active_widgets = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
@ -287,7 +287,7 @@ void box_add ( box *box, widget *child, gboolean expand, int index )
return;
}
// Make sure box is width/heigh enough.
if ( box->type == BOX_VERTICAL ) {
if ( box->type == ORIENTATION_VERTICAL ) {
int width = box->widget.w;
width = MAX ( width, child->w + widget_padding_get_padding_width ( WIDGET ( box ) ) );
box->widget.w = width;
@ -335,7 +335,7 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin
return NULL;
}
box * box_create ( const char *name, boxType type )
box * box_create ( const char *name, Orientation type )
{
box *b = g_malloc0 ( sizeof ( box ) );
// Initialize widget.
@ -350,7 +350,7 @@ box * box_create ( const char *name, boxType type )
b->widget.get_desired_width = box_get_desired_width;
b->widget.enabled = rofi_theme_get_boolean ( WIDGET ( b ), "enabled", TRUE );
b->type = rofi_theme_get_boolean ( WIDGET (b), "vertical",b->type );
b->type = rofi_theme_get_orientation ( WIDGET (b), "orientation",b->type );
b->spacing = rofi_theme_get_distance ( WIDGET ( b ), "spacing", DEFAULT_SPACING );
return b;
@ -361,10 +361,10 @@ static void box_update ( widget *wid )
box *b = (box *) wid;
switch ( b->type )
{
case BOX_VERTICAL:
case ORIENTATION_VERTICAL:
vert_calculate_size ( b );
break;
case BOX_HORIZONTAL:
case ORIENTATION_HORIZONTAL:
default:
hori_calculate_size ( b );
}