arduino - 在处理 IDE 中的按钮内制作按钮
问题描述
我希望“pick_one”和“pick_all”按钮位于另一个称为“配置”按钮的通用按钮(如文件 - 或界面中的新页面)内。我在下面尝试了这段代码,但我得到了意外的令牌:无效错误。
有没有办法把按钮放在另一个按钮里面?
import controlP5.*; //import ControlP5 library
import processing.serial.*;
Serial port;
ControlP5 cp5; //create ControlP5 object
PFont font;
void setup(){ //Same as setup in arduino
size(900, 900);
port = new Serial(this, "COM4", 9600); //Change this to your port
cp5 = new ControlP5(this);
font = createFont ("Georgia Bold", 20);
cp5.addButton("PICK_ALL") //The button
.setPosition(100, 100) //x and y coordinates of upper left corner of button
.setSize(160, 150) //(width, height)
.setFont(font)
;
cp5.addButton("PICK_ONE") //The button
.setPosition(100, 400) //x and y coordinates of upper left corner of button
.setSize(160, 150) //(width, height)
.setFont(font)
;
cp5.addButton("CONFIGURATION") //The button
.setPosition(100, 400) //x and y coordinates of upper left corner of button
.setSize(160, 150) //(width, height)
.setFont(font)
;
}
void draw(){ //Same as loop in arduino
background(150, 0 , 150); //Background colour of window (r, g, b) or (0 to 255)
}
void CONFIGURATION() {
void PICK_ALL(){
port.write('t')
}
void PICK_ONE(){
port.write('l');
}}
解决方案
错误:
看起来您正在嵌套按钮单击处理程序函数。这些是单击按钮时触发的操作。它们不控制屏幕上按钮的布局或嵌套。
此外,处理中不允许嵌套函数,这就是您收到错误的原因。
确保您的CONFIGURATION
函数的大括号不包含任何其他函数:
void CONFIGURATION() {
} // close this function before starting any others
void PICK_ALL(){
port.write('t')
}
void PICK_ONE(){
port.write('l');
}
总体问题:
在另一个按钮中包含一个按钮意味着什么?我不确定我是否理解您要达到的目标。
我认为您可能正在寻找诸如Groups或Tabs之类的东西,它们都允许您将多个控件组合在一起。
对于您的项目,可能看起来像这样:
Group configGroup = cp5.addGroup("CONFIGURATION")
.setPosition(100,100)
.setBackgroundHeight(400)
.setWidth(180)
.setBackgroundColor(color(255,50))
;
cp5.addButton("PICK_ALL") // The button
.setPosition(10, 10) // x and y relative to the group
.setSize(160, 150) // (width, height)
.setFont(font)
.setGroup(configGroup) // add it to the group
;
cp5.addButton("PICK_ONE") // The button
.setPosition(10, 200) // x and y relative to the group
.setSize(160, 150) // (width, height)
.setFont(font)
.setGroup(configGroup) // add it to the group
;
您可以单击组的标题栏来隐藏和显示内容。
请注意,按钮的位置现在是相对于组容器的。
推荐阅读
- python - python中的Scraable游戏
- java - 我正在使用 NotifydataAdapter 但是当数据库上的值发生变化时它不起作用;
- asp.net-mvc - 在 ASP.NET MVC 中绑定二维数组
- android - 在 CircleCI 上 ReactNative 0.59.x 构建失败,退出值为 137
- javascript - 如何在聊天中为用户定义颜色
- java - java流过滤器与if-else条件,哪个更快?
- node.js - 使用 GraphicsMagick 重新着色图像
- javascript - highchart中不相关的图表线
- matlab - 如何使用 Matlab 3D 世界编辑器创建逼真的水体?
- sparql - 带有过滤器的 SPARQL 查询不存在