|
| |
| Navigation |
Synopsis Control the height of a box with user input.
Description The challenge is to create a user interface that consists of
Examples Here is a solution:
@license{
Copyright (c) 2009-2013 CWI
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
}
module demo::vis::Higher
import vis::Figure;
import vis::Render;
public bool intInput(str s){
return /^[0-9]+$/ := s;
}
public Figure higher(){
int H = 100;
return vcat( [ textfield("<H>", void(str s){H = toInt(s);}, intInput),
box(width(100), vresizable(false), vsize(num(){return H;}), fillColor("red"))
], shrink(0.5), resizable(false));
}
The auxiliary function intInput checks that a strings consists solely of digits.
Function higher can be understood as follows:
import demo::vis::Higher; render(higher());gives
Unfortunately we cannot show the interaction here, so run this example from the demo directory and watch how the height of the box changes when you enter a new number in the text field.
|