libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xcombobox.c
Go to the documentation of this file.
1 /*
2  * 0BSD
3  *
4  * BSD Zero Clause License
5  *
6  * Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 #include "xcombobox.h"
22 #include "xcombobox_private.h"
23 
24 
25 void combobox_set_active_entry(Widget_t *w, int active) {
26  float value = (float)active;
27  if (value>w->adj->max_value) value = w->adj->max_value;
28  else if (value<w->adj->min_value) value = w->adj->min_value;
29  adj_set_value(w->adj, value);
30 }
31 
32 Widget_t* add_combobox(Widget_t *parent, const char * label, int x, int y, int width, int height) {
33 
34  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
35  wid->label = label;
36  wid->scale.gravity = CENTER;
37  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, -1.0,1.0, CL_ENUM);
38  wid->adj = wid->adj_y;
44 
45  Widget_t* button = add_button(wid, "", width-20, 0, 20, height);
48 
49  Widget_t* menu = create_menu(wid, 25);
51 
52 
53  return wid;
54 }
55 
56 Widget_t *combobox_add_entry(Widget_t *wid, const char * label) {
57  Widget_t *menu = wid->childlist->childs[1];
58  Widget_t *item = menu_add_item(menu,label);
59  wid->label = label;
60  float max_value = wid->adj->max_value+1.0;
61  set_adjustment(wid->adj,0.0, max_value, 0.0, max_value,1.0, CL_ENUM);
62 
63  return item;
64 }
65 
66 void combobox_add_numeric_entrys(Widget_t *wid, int imin, int imax) {
67  Widget_t *menu = wid->childlist->childs[1];
68  menu_add_numeric_items(menu, &imin, &imax);
69  float max_value = wid->adj->max_value+(imax-imin)+1;
70  set_adjustment(wid->adj,0.0, max_value, 0.0, max_value,1.0, CL_ENUM);
71 }
Func_t::leave_callback
xevfunc leave_callback
Definition: xwidget.h:83
combobox_add_numeric_entrys
void combobox_add_numeric_entrys(Widget_t *wid, int imin, int imax)
combobox_add_numeric_items - add numeric items from imin to imax to wid
Definition: xcombobox.c:66
Func_t::enter_callback
xevfunc enter_callback
Definition: xwidget.h:82
_button_combobox_released
void _button_combobox_released(void *w_, void *button_, void *user_data)
_button_combobox_released - popup the combobox menu
Definition: xcombobox_private.c:173
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
combobox_set_active_entry
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
Definition: xcombobox.c:25
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
CL_ENUM
@ CL_ENUM
Definition: xadjustment.h:55
menu_add_item
Widget_t * menu_add_item(Widget_t *menu, const char *label)
menu_add_item - add a item to menu
Definition: xmenu.c:137
create_widget
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition: xwidget.c:268
transparent_draw
void transparent_draw(void *wid, void *user_data)
transparent_draw - copy parent surface to child surface you usaualy didn't need to call this,...
Definition: xwidget.c:469
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
CENTER
@ CENTER
Definition: xwidget.h:165
adj_set_value
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
Definition: xadjustment.c:163
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
_set_entry
void _set_entry(void *w_, void *user_data)
_set_entry - set the active combobox entry on adjustment change
Definition: xcombobox_private.c:198
Widget_t::app
Xputty * app
Definition: xwidget.h:300
combobox_add_entry
Widget_t * combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Definition: xcombobox.c:56
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
Func_t::button_release_callback
evfunc button_release_callback
Definition: xwidget.h:94
Widget_t::childlist
Childlist_t * childlist
Definition: xwidget.h:336
Adjustment_t::max_value
float max_value
Definition: xadjustment.h:90
set_adjustment
void set_adjustment(Adjustment_t *adj, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*set_adjustment - set a new range to a existing Adjustment_t it will be created if it not exsits yet
Definition: xadjustment.c:80
Func_t::adj_callback
xevfunc adj_callback
Definition: xwidget.h:84
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
Widget_t::func
Func_t func
Definition: xwidget.h:310
menu_add_numeric_items
void menu_add_numeric_items(Widget_t *menu, int *imin, int *imax)
menu_add_numeric_items - add numeric items from imin to imax to menu
Definition: xmenu.c:193
_combobox_button_released
void _combobox_button_released(void *w_, void *button_, void *user_data)
_combobox_button_released - popup menu on right click
Definition: xcombobox_private.c:162
add_combobox
Widget_t * add_combobox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_combobox - add a combobox
Definition: xcombobox.c:32
add_adjustment
Adjustment_t * add_adjustment(Widget_t *w, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*add_adjustment - adding a adjustment to a Widget_t
Definition: xadjustment.c:25
xcombobox.h
_entry_released
void _entry_released(void *w_, void *item_, void *user_data)
_entry_released - the combobox menu release func
Definition: xcombobox_private.c:184
create_menu
Widget_t * create_menu(Widget_t *parent, int height)
create_menu - create a menu to a Widget_t
Definition: xmenu.c:107
_draw_combobox_button
void _draw_combobox_button(void *w_, void *user_data)
_draw_combobox_button - internal draw the combobox button to the buffer
Definition: xcombobox_private.c:26
Widget_t::label
const char * label
Definition: xwidget.h:326
Adjustment_t::min_value
float min_value
Definition: xadjustment.h:88
add_button
Widget_t * add_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_button - add a button to a Widget_t connect to func.value_changed_callback to implement your acti...
Definition: xbutton.c:26
xcombobox_private.h
_draw_combobox
void _draw_combobox(void *w_, void *user_data)
_draw_combobox - internal draw the combobox to the buffer
Definition: xcombobox_private.c:100