Clay-UI
view release on metacpan or search on metacpan
examples/09-xs-floating-scroll.pl view on Meta::CPAN
#!/usr/bin/env perl
# 09-xs-floating-scroll.pl - Scrolling, floating elements and pointer input.
#
# Builds a small window with Clay::XS: a scrollable list, a "Menu" button
# that opens a dropdown and a help icon that shows a tooltip. Then it feeds
# the window a scripted sequence of pointer moves, a click and mouse-wheel
# input. Each frame prints
# what Clay reports; the last frame's render commands are listed as a table.
# Nothing is drawn: the point is the order of the input calls and what each
# query returns.
#
# Shows:
# - a scroll container: clip with the scroll offset fed back as childOffset
# - mouse-wheel scrolling and jumping to a scroll position from code
examples/09-xs-floating-scroll.pl view on Meta::CPAN
});
open_element('menu-button');
Clay__ConfigureOpenElement({
layout => {
sizing => { width => sizing_fixed(80), height => sizing_fixed(28) },
childAlignment => { x => CLAY_ALIGN_X_CENTER, y => CLAY_ALIGN_Y_CENTER },
},
backgroundColor => $ACCENT,
cornerRadius => corner_radius_all(4),
});
text('Menu', $WHITE);
# A floating child is declared inside its parent but takes no
# space there; see Clay::XS, floating.
declare_dropdown() if $ui{menu_open};
Clay__CloseElement();
text('Floating and scrolling demo');
Clay__CloseElement();
}
sub declare_list () {
open_element('list');
examples/09-xs-floating-scroll.pl view on Meta::CPAN
# hovered until the script moves it.
my @input_script = (
{ title => 'first frame, pointer outside the window',
pointer => sub { { x => -1, y => -1 } } },
{ title => 'pointer moves over row 2',
pointer => sub { center_of('row', 2) } },
{ title => 'mouse wheel: 3 notches down over the list',
pointer => sub { center_of('row', 2) }, wheel => -3 },
{ title => 'pointer moves over the help icon',
pointer => sub { center_of('help-icon') } },
{ title => 'button pressed over Menu',
pointer => sub { center_of('menu-button') }, down => 1 },
{ title => 'button released',
pointer => sub { center_of('menu-button') } },
{ title => 'pointer moves onto the dropdown, above the list',
pointer => sub { center_of('menu-item', 1) } },
{ title => 'mouse wheel over the dropdown',
pointer => sub { center_of('menu-item', 1) }, wheel => -3 },
{ title => 'code jumps the list to its end with set_scroll_position',
pointer => sub { center_of('help-icon') }, scroll_list_to_end => 1 },
);
examples/09-xs-floating-scroll.pl view on Meta::CPAN
my $data = Clay_GetScrollContainerData( Clay_GetElementId('list') );
my $bottom = $data->{scrollContainerDimensions}{height} - $data->{contentDimensions}{height};
set_scroll_position(Clay_GetElementId('list'), { x => 0, y => $bottom });
push @log, "set_scroll_position(list, y => $bottom)";
}
my $clicked_menu = Clay_GetPointerState()->{state} == CLAY_POINTER_DATA_PRESSED_THIS_FRAME
&& Clay_PointerOver( Clay_GetElementId('menu-button') );
if ($clicked_menu) {
$ui{menu_open} = !$ui{menu_open};
push @log, 'Menu clicked: dropdown ' . ($ui{menu_open} ? 'opens' : 'closes');
}
my $was_showing = $ui{show_tooltip};
$ui{show_tooltip} = Clay_PointerOver( Clay_GetElementId('help-icon') ) ? 1 : 0;
push @log, 'tooltip ' . ($ui{show_tooltip} ? 'shown' : 'hidden') if $was_showing != $ui{show_tooltip};
return @log;
}
sub run_frame ($step) {
my @log = apply_input($step);
( run in 0.705 second using v1.01-cache-2.11-cpan-60884a8df76 )