libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xlistbox.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 
22 #include "xlistbox.h"
23 #include "xlistbox_private.h"
24 
25 
26 void listbox_set_active_entry(Widget_t *w, int active) {
27  float value = (float)active;
28  if (value>w->adj->max_value) value = w->adj->max_value;
29  else if (value<w->adj->min_value) value = w->adj->min_value;
30  adj_set_value(w->adj, value);
31 }
32 
33 Widget_t* create_listbox_viewport(Widget_t *parent, int elem, int width, int height) {
34  Widget_t *wid = create_widget(parent->app, parent, 0, 0, width, height);
35  wid->scale.gravity = NORTHEAST;
36  float max_value = -elem ;
37  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, max_value,1.0, CL_VIEWPORT);
38  wid->adj = wid->adj_y;
43  return wid;
44 }
45 
46 Widget_t* add_listbox(Widget_t *parent, const char * label,
47  int x, int y, int width, int height) {
48 
49  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
50  wid->label = label;
51  wid->scale.gravity = CENTER;
53  int elem = height/25;
54  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, -1.0,1.0, CL_NONE);
55  wid->adj = wid->adj_y;
56  create_listbox_viewport(wid, elem, width, height);
57  return wid;
58 }
59 
60 Widget_t* listbox_add_entry(Widget_t *listbox, const char * label) {
61  Widget_t* view_port = listbox->childlist->childs[0];
62  int width = listbox->scale.init_width;
63  int si = childlist_has_child(view_port->childlist);
64  Widget_t *wid = create_widget(listbox->app, view_port, 0, 25*si, width, 25);
65  float max_value = view_port->adj->max_value+1.0;
66  set_adjustment(view_port->adj,0.0, 0.0, 0.0, max_value,1.0, CL_VIEWPORT);
67  max_value = listbox->adj->max_value+1.0;
68  set_adjustment(listbox->adj,0.0, 0.0, 0.0, max_value,1.0, CL_NONE);
70  wid->scale.gravity = MENUITEM;
71  wid->label = label;
76  return wid;
77 }
Func_t::leave_callback
xevfunc leave_callback
Definition: xwidget.h:83
HAS_TOOLTIP
@ HAS_TOOLTIP
Definition: xwidget.h:249
Func_t::enter_callback
xevfunc enter_callback
Definition: xwidget.h:82
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
MENUITEM
@ MENUITEM
Definition: xwidget.h:171
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
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
_draw_listbox
void _draw_listbox(void *w_, void *user_data)
_draw_listbox - draw listbox on expose call
Definition: xlistbox_private.c:26
Widget_t::flags
long long flags
Definition: xwidget.h:324
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
CL_VIEWPORT
@ CL_VIEWPORT
Definition: xadjustment.h:57
Widget_t::app
Xputty * app
Definition: xwidget.h:300
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
_draw_listbox_viewslider
void _draw_listbox_viewslider(void *w_, void *user_data)
_draw_listbox_viewslider - draw a slider on the viewport to indicate the view point
Definition: xlistbox_private.c:100
xlistbox.h
Func_t::map_notify_callback
xevfunc map_notify_callback
Definition: xwidget.h:89
_reconfigure_listbox_viewport
void _reconfigure_listbox_viewport(void *w_, void *user_data)
_reconfigure_listbox_viewport - reconfigure the viewport adjustment on size changes
Definition: xlistbox_private.c:77
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
_listbox_entry_released
void _listbox_entry_released(void *w_, void *button_, void *user_data)
_listbox_entry_released - redraw the slider when buttob released
Definition: xlistbox_private.c:132
_configure_listbox
void _configure_listbox(void *w_, void *user_data)
_configure_listbox - configure the viewport on mapping
Definition: xlistbox_private.c:90
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
create_listbox_viewport
Widget_t * create_listbox_viewport(Widget_t *parent, int elem, int width, int height)
create_listbox_viewport - create a viewport on a listbox to a Widget_t
Definition: xlistbox.c:33
CL_NONE
@ CL_NONE
Definition: xadjustment.h:47
listbox_set_active_entry
void listbox_set_active_entry(Widget_t *w, int active)
listbox_set_active_entry - set the active listbox entry
Definition: xlistbox.c:26
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
_set_listbox_viewpoint
void _set_listbox_viewpoint(void *w_, void *user_data)
_set_listbox_viewpoint - move the view_port to position
Definition: xlistbox_private.c:123
Func_t::configure_notify_callback
xevfunc configure_notify_callback
Definition: xwidget.h:88
childlist_has_child
int childlist_has_child(Childlist_t *childlist)
childlist_has_child - check if a Widget_t Childlist_t contain a child
Definition: xchildlist.c:91
listbox_add_entry
Widget_t * listbox_add_entry(Widget_t *listbox, const char *label)
listbox_add_entry - add a item to listbox
Definition: xlistbox.c:60
add_listbox
Widget_t * add_listbox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_label - add a listbox to a Widget_t
Definition: xlistbox.c:46
Widget_t::label
const char * label
Definition: xwidget.h:326
xlistbox_private.h
Adjustment_t::min_value
float min_value
Definition: xadjustment.h:88
_draw_listbox_item
void _draw_listbox_item(void *w_, void *user_data)
_draw_listbox_item - draw item on expose call
Definition: xlistbox_private.c:33
Resize_t::init_width
int init_width
Definition: xwidget.h:198
NORTHEAST
@ NORTHEAST
Definition: xwidget.h:159