libxputty 0.1
Loading...
Searching...
No Matches
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
26void 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
33Widget_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
46Widget_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
60Widget_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);
69 wid->flags &= ~USE_TRANSPARENCY | ~HAS_TOOLTIP;
70 wid->scale.gravity = MENUITEM;
71 wid->label = label;
76 return wid;
77}
float min_value
Definition xadjustment.h:90
float max_value
Definition xadjustment.h:92
Widget_t ** childs
Definition xchildlist.h:51
xevfunc configure_notify_callback
Definition xwidget.h:93
evfunc button_release_callback
Definition xwidget.h:101
xevfunc map_notify_callback
Definition xwidget.h:94
xevfunc expose_callback
Definition xwidget.h:85
xevfunc leave_callback
Definition xwidget.h:88
xevfunc adj_callback
Definition xwidget.h:89
xevfunc enter_callback
Definition xwidget.h:87
Gravity gravity
Definition xwidget.h:347
int init_width
Definition xwidget.h:353
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
Adjustment_t * adj_y
Definition xwidget.h:495
Adjustment_t * adj
Definition xwidget.h:497
Childlist_t * childlist
Definition xwidget.h:499
long long flags
Definition xwidget.h:461
const char * label
Definition xwidget.h:463
Func_t func
Definition xwidget.h:481
Xputty * app
Definition xwidget.h:465
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
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
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 or create if it not exists yet
Definition xadjustment.c:80
@ CL_VIEWPORT
Definition xadjustment.h:57
@ CL_NONE
Definition xadjustment.h:47
int childlist_has_child(Childlist_t *childlist)
childlist_has_child - check if a Widget_t Childlist_t contain a child
Definition xchildlist.c:89
void listbox_set_active_entry(Widget_t *w, int active)
listbox_set_active_entry - set the active listbox entry
Definition xlistbox.c:26
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
Widget_t * listbox_add_entry(Widget_t *listbox, const char *label)
listbox_add_entry - add a item to listbox
Definition xlistbox.c:60
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
void _draw_listbox_viewslider(void *w_, void *user_data)
_draw_listbox_viewslider - draw a slider on the viewport to indicate the view point
void _reconfigure_listbox_viewport(void *w_, void *user_data)
_reconfigure_listbox_viewport - reconfigure the viewport adjustment on size changes
void _draw_listbox_item(void *w_, void *user_data)
_draw_listbox_item - draw item on expose call
void _listbox_entry_released(void *w_, void *button_, void *user_data)
_listbox_entry_released - redraw the slider when buttob released
void _draw_listbox(void *w_, void *user_data)
_draw_listbox - draw listbox on expose call
void _configure_listbox(void *w_, void *user_data)
_configure_listbox - configure the viewport on mapping
void _set_listbox_viewpoint(void *w_, void *user_data)
_set_listbox_viewpoint - move the view_port to position
void os_transparent_draw(void *w_, void *user_data)
os_transparent_draw - Draw the Widget_t to the back buffer
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:265
@ CENTER
Definition xwidget.h:320
@ MENUITEM
Definition xwidget.h:326
@ NORTHEAST
Definition xwidget.h:302