Changeset ef734b7 in mainline for uspace/app/uidemo/uidemo.c


Ignore:
Timestamp:
2021-02-05T15:59:16Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2ab8ab3
Parents:
5a68791
Message:

Slider UI control

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/uidemo/uidemo.c

    r5a68791 ref734b7  
    3737#include <io/pixelmap.h>
    3838#include <stdio.h>
     39#include <stdlib.h>
    3940#include <str.h>
    4041#include <ui/entry.h>
     
    7475};
    7576
     77static void slider_moved(ui_slider_t *, void *, gfx_coord_t);
     78
     79static ui_slider_cb_t slider_cb = {
     80        .moved = slider_moved
     81};
     82
    7683/** Window close button was clicked.
    7784 *
     
    150157}
    151158
     159/** Slider was moved.
     160 *
     161 * @param slider Slider
     162 * @param arg Argument (demo)
     163 * @param pos Position
     164 */
     165static void slider_moved(ui_slider_t *slider, void *arg, gfx_coord_t pos)
     166{
     167        ui_demo_t *demo = (ui_demo_t *) arg;
     168        char *str;
     169        errno_t rc;
     170        int rv;
     171
     172        rv = asprintf(&str, "Slider at %d of %d", (int) pos,
     173            ui_slider_length(slider));
     174        if (rv < 0) {
     175                printf("Out of memory.\n");
     176                return;
     177        }
     178
     179        rc = ui_entry_set_text(demo->entry, str);
     180        if (rc != EOK)
     181                printf("Error changing entry text.\n");
     182        (void) ui_entry_paint(demo->entry);
     183
     184        free(str);
     185}
     186
    152187/** Run UI demo on display server. */
    153188static errno_t ui_demo(const char *display_spec)
     
    177212        params.rect.p0.y = 0;
    178213        params.rect.p1.x = 220;
    179         params.rect.p1.y = 330;
     214        params.rect.p1.y = 340;
    180215
    181216        memset((void *) &demo, 0, sizeof(demo));
     
    397432
    398433        rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb3));
     434        if (rc != EOK) {
     435                printf("Error adding control to layout.\n");
     436                return rc;
     437        }
     438
     439        rc = ui_slider_create(ui_res, "Slide!", &demo.slider);
     440        if (rc != EOK) {
     441                printf("Error creating button.\n");
     442                return rc;
     443        }
     444
     445        ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo);
     446
     447        rect.p0.x = 15;
     448        rect.p0.y = 300;
     449        rect.p1.x = 130;
     450        rect.p1.y = 320;
     451        ui_slider_set_rect(demo.slider, &rect);
     452
     453        rc = ui_fixed_add(demo.fixed, ui_slider_ctl(demo.slider));
    399454        if (rc != EOK) {
    400455                printf("Error adding control to layout.\n");
Note: See TracChangeset for help on using the changeset viewer.