/*
 * Copyright © 2008 Keith Packard
 *
 * This library is free software; you can redistribute it and/or
 * modify it either under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 * notice, a recipient may use your version of this file under either
 * the MPL or the LGPL.
 *
 * You should have received a copy of the LGPL along with this library
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * You should have received a copy of the MPL along with this library
 * in the file COPYING-MPL-1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 * the specific language governing rights and limitations.
 *
 * The Original Code is the cairo graphics library.
 *
 * The Initial Developer of the Original Code is Keith Packard
 *
 * Contributor(s):
 *      Keith Packard <keithp@keithp.com>
 */

load "nichrome.5c"
load "nichrome-box.5c"
load "nichrome-label.5c"
load "nichrome-lozenge.5c"
load "nichrome-scrollbar.5c"

import Nichrome;
import Nichrome::Box;
import Nichrome::Scrollbar;
import Nichrome::Label;

void
main ()
{
    &nichrome_t	    nichrome = Nichrome::new ("Scrollbar Test", 400, 400);

    &label_t	    label = Label::new (&nichrome, "hello, world");

    void scrollbar_callback (&scrollbar_t widget, Scrollbar::action_t action)
    {
	union switch (action) {
	case drag pos:
	    Label::relabel (&label, sprintf ("%g", pos));
	    Scrollbar::set (&widget, pos, .1 + pos / 10);
	    break;
	case pos pos:
	    Label::relabel (&label, sprintf ("%g", pos));
	    Scrollbar::set (&widget, pos, .1 + pos / 10);
	    break;
	default:
	    break;
	}
    }

    &scrollbar_t vscrollbar = Scrollbar::new (&nichrome,
					  Scrollbar::dir_t.vertical,
					  scrollbar_callback);

    &scrollbar_t hscrollbar = Scrollbar::new (&nichrome,
					  Scrollbar::dir_t.horizontal,
					  scrollbar_callback);

    &box_t	    hbox = Box::new (Box::dir_t.horizontal,
				     Box::widget_item (&label, 1),
				     Box::widget_item (&vscrollbar, 0, 1));
    &box_t	    vbox = Box::new (Box::dir_t.vertical,
				     Box::box_item (&hbox),
				     Box::widget_item (&hscrollbar, 1, 0));
    Scrollbar::set (&hscrollbar, 0, .1);
    Scrollbar::set (&vscrollbar, 0, .1);
    Nichrome::set_box (&nichrome, &vbox);
    Nichrome::main_loop (&nichrome);
}

main ();
