line线

1.Connection接口:draw2d里面的线必须实现这个接口,这个接口里面有一个PointList,这个list里面放跟这个线相关的所有ConnectionAnchor。ConnectionAnchor是一个个瞄点,线是必须穿过这些瞄点的。

?

2.Polyline:这个相当于线的实现类,一个Figure,是在Shape的基础上发展出来的。这个类里面控制线的宽度大小形状还有颜色之类的,是对线的外观的定义。尽管Polyline是一个线,但它只是一个线的实现,一般使用的不是它,而是它的子类。

?

3.PolylineConnection是我们经常使用的线,它继承自Polyline同时实现了Connection接口。同时它里面有两个RotatableDecoration对象,用于描述线的两头的形状。默认有两个实现:PolylineDecoration虚心箭头,PolygonDecoration实心箭头,其实就是一个Figure自己想画随便画成啥样。

?

?

public static void createLine(IFigure panel,IFigure node1,IFigure node2){
PolylineConnection conn = new PolylineConnection();

// 设置连线起点的锚点
conn.setSourceAnchor(new ChopboxAnchor(node1));
// 设置连线目标的锚点
conn.setTargetAnchor(new ChopboxAnchor(node2));
// 设置连线目标的装饰器,箭头
conn.setTargetDecoration(new PolylineDecoration());

panel.add(conn);
}

?

?

?

4.在线上面加label:

在线上面加label其实就是在线上面加一个Figure,Figure本身你画什么并不重要。

?


        Label label = new Label("Midpoint");
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.buttonLightest);
label.setBorder(new LineBorder());
// 添加连线的Locator
conn.add(label, new MidpointLocator(conn, 0));

?
5.<span style="white-space: pre;">Anchor锚点:线两端的点,定位连线的起始和终结点。</span>

?

6.<span style="white-space: pre;">Router路由:有些路由是直接在线上使用的,有些路由必须在父容器中使用。</span>

?


conn.setConnectionRouter(new ManhattanConnectionRouter());

?
在LVGL(Light and Versatile Graphics Library)中,清除绘制的线条可以通过以下几种方法实现: 1. **重新绘制背景**: 如果线条是绘制在某个对象(如按钮、标签等)上,可以通过重新绘制该对象的背景来覆盖线条。 ```c lv_obj_t * obj = lv_obj_create(lv_scr_act()); lv_obj_set_style_bg_color(obj, LV_COLOR_BLUE, 0); // 绘制线条 lv_obj_t * line = lv_line_create(obj); static lv_point_t line_points[] = { {10, 10}, {100, 10} }; lv_line_set_points(line, line_points, 2); // 清除线条 lv_obj_clean(obj); ``` 2. **删除线条对象**: 如果线条是作为一个独立的对象创建的,可以通过删除该对象来清除线条。 ```c lv_obj_t * line = lv_line_create(lv_scr_act()); static lv_point_t line_points[] = { {10, 10}, {100, 10} }; lv_line_set_points(line, line_points, 2); // 清除线条 lv_obj_del(line); ``` 3. **覆盖线条**: 可以通过在相同位置绘制一个与背景颜色相同的线条来覆盖原来的线条。 ```c lv_obj_t * line = lv_line_create(lv_scr_act()); static lv_point_t line_points[] = { {10, 10}, {100, 10} }; lv_line_set_points(line, line_points, 2); // 覆盖线条 lv_obj_set_style_line_color(line, LV_COLOR_BLUE, 0); ``` 4. **更新线条点**: 如果需要清除线条,可以将线条的点设置为空数组。 ```c lv_obj_t * line = lv_line_create(lv_scr_act()); static lv_point_t line_points[] = { {10, 10}, {100, 10} }; lv_line_set_points(line, line_points, 2); // 清除线条 static lv_point_t empty_points[] = { {0, 0} }; lv_line_set_points(line, empty_points, 0); ``` 以上方法可以根据具体需求选择使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值