包重新开发(package development without restarting)
我开发像这样的
Sublime 3
软件包:import sublime, sublime_plugin class RelativeCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.insert(edit, 0, "Hello World")
我需要在每次编辑后重新加载sublime以查看更改工作的结果。
如何在不退出sublime并重新打开的情况下获取插件中的工作更改?
我相信这是可能的,因为例如sublime在编辑键映射时无需重新加载就可以动态更改。
Update1:当我在更改文件后按保存时,我在控制台中收到消息:
Writing file /Users/maks/Library/Application Support/Sublime Text 3/Packages/relative/relative.py with encoding UTF-8 (atomic) reloading plugin relative.relative
Update2:我使用符号链接在
Dropbox
文件夹中存储Packages
和Installed Packages
。Update3:我的操作系统是
OS X version 10.8.5
I develop
Sublime 3
packages like this:import sublime, sublime_plugin class RelativeCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.insert(edit, 0, "Hello World")
I need to reload sublime after every editing in it to see result of changing in work.
How to get working changes in plugin without exiting the sublime and reopening it?
I believe that it is possible, because for example sublime get changes on the fly without reloading when you edit key mappings.
Update1 : When I press save after changing file, I got message in console:
Writing file /Users/maks/Library/Application Support/Sublime Text 3/Packages/relative/relative.py with encoding UTF-8 (atomic) reloading plugin relative.relative
Update2 : I am using symlinks to store
Packages
andInstalled Packages
inDropbox
folder.Update3: My os is
OS X version 10.8.5
原文:https://stackoverflow.com/questions/19501323
最满意答案
您使用错误的逻辑来绘制线,如果您调用
invalidate()
您将请求调用draw()
,这将重置您的画布。试试这个版本的课程:
public class BreakDownBar extends View { private List<Point> points = new ArrayList<>(); private Path path = new Path(); private Paint p = new Paint(); public BreakDownBar(Context context) { super(context); p.setStrokeWidth(5); p.setStyle(Paint.Style.STROKE); p.setColor(Color.BLACK); } public void addPoint(Point point) { points.add(point); //this will request a call to draw(canvas) method invalidate(); } @Override public void draw(Canvas canvas) { super.draw(canvas); //move to the first point in the list path.moveTo(points.get(0).getX(), points.get(0).getY()); for (int i = 1; i < points.size(); i++) { path.lineTo(points.get(i).getX(), points.get(i).getY()); } canvas.drawPath(path, p); } }
然后在你的代码中你可以做到
BreakDownBar bar = new BreakDownBar(context); bar.addPoint(new Point(100f, 200f)) bar.addPoint(new Point(200f, 300f)) bar.addPoint(new Point(400f, 200f))
如果这对您有用,请告诉我。
You are using a bad logic to draw the line, if you call
invalidate()
you will request a call todraw()
and this will reset your canvas.Try with this version of your class:
public class BreakDownBar extends View { private List<Point> points = new ArrayList<>(); private Path path = new Path(); private Paint p = new Paint(); public BreakDownBar(Context context) { super(context); p.setStrokeWidth(5); p.setStyle(Paint.Style.STROKE); p.setColor(Color.BLACK); } public void addPoint(Point point) { points.add(point); //this will request a call to draw(canvas) method invalidate(); } @Override public void draw(Canvas canvas) { super.draw(canvas); //move to the first point in the list path.moveTo(points.get(0).getX(), points.get(0).getY()); for (int i = 1; i < points.size(); i++) { path.lineTo(points.get(i).getX(), points.get(i).getY()); } canvas.drawPath(path, p); } }
Then in your code you can simply do
BreakDownBar bar = new BreakDownBar(context); bar.addPoint(new Point(100f, 200f)) bar.addPoint(new Point(200f, 300f)) bar.addPoint(new Point(400f, 200f))
Let me know if this works for you.
相关问答
更多-
Android Canvas。(Android Canvas. Moving and Rotating Bitmap along Circular Path based on Touch?)[2023-05-20]
更新:完整示例发布在GitHub上https://github.com/jselbie/xkcdclock 每次触摸事件时,抓住触摸点的x,y坐标并计算相对于位图中心的旋转角度。 使用该值确定旋转要绘制的位图的量。 首先,让我们假设一个逻辑坐标系,其中上面元素的中心点位于x,y空间中的(0,0)。 因此,任何触摸点相对于中心的角度(以度为单位)可以如下计算: double ComputeAngle(float x, float y) { final double RADS_TO_DEGREES = ... -
newsList为null ,因为您从不为其赋值。 如果要避免NullPointerException ,请不要在newsList上调用add() ,直到为newsList分配了值(例如, newsList=new ArrayList
>(); )。 newsList is null, because you never assign a value to it. If you want to avoid a NullPointerException, do n ... -
您无法在Canvas上撤消drawPath。 从文档 : 通过画布,您的绘图实际上是在基础位图上执行的,该位图放置在窗口中。 正如您所说,您需要一个备份Bitmap来保存当前Bitmap的状态,然后再绘制它,例如使用Memento模式 。 当内存有限时,请查看位图编辑器的快速撤消/重做? 和位图编辑器应用程序的快速撤消工具 (最后一个目标iPhone,但基本的想法是相同的) 另一种减少内存消耗的方法可能是保存您想要在画布上绘制的对象的状态,并根据需要绘制它们(当您需要显示部分或完整结果时)。 You can ...
-
您使用错误的逻辑来绘制线,如果您调用invalidate()您将请求调用draw() ,这将重置您的画布。 试试这个版本的课程: public class BreakDownBar extends View { private List
points = new ArrayList<>(); private Path path = new Path(); private Paint p = new Paint(); public BreakDownBar(Co ... -
我能行。 从WKT读LatLong并添加到Array private LatLng[] GetPolygonPoints(String polygonWkt) { Bundle bundle = getIntent().getExtras(); wkt = bundle.getString("wkt"); ArrayList
points = new ArrayList (); Pattern p = Pattern.compile("(\\d ... -
请试试这个..希望它对你有用。 canvas.drawPath(path, currentPaint); canvas.drawCircle(x1, y1, 8, currentPaint); canvas.drawCircle(x2, y2, 8, currentPaint); canvas.drawCircle(x3, y3, 8, currentPaint); canvas.drawCircle(x4, y4, 8, currentPaint); 使用此代码获取此输出... Please try t ...
-
尝试这个: link_to 'Add', [:new, params[:controller].singularize] 在内部, Rails会将[:new, params[:controller].singularize]转换为对[:new, params[:controller].singularize]的调用(例如,如果控制器posts则[:new, params[:controller].singularize]生成像new_post_path这样的路径助手)。 大多数(如果不是全部的话)期望路径 ...
-
设置一个方法来改变DrawLine类中的paint实例,并通过按钮的onClick方法调用它 public void changeColor(int color) { paint.setColor(color); } Set a method to change paint instance inside DrawLine class and invoke it from the onClick method of the button public void changeColor(int co ...
-
类Paint具有方法setTypeface ,可以传递一个Typeface 。 代码例子: paint.setTypeface(Typeface.DEFAULT_BOLD); 所以如果你想改变文本的一部分,可以通过改变字体逐个绘制。 另外,你可以尝试使用像 c 这样的HTML代码 the class Paint has method setTypeface , you can pass a Typeface. code exmaple: paint.setTypeface(Typeface. ...
-
我不确定你在做什么。 但请牢记以下内容 不要长期保持对上下文活动的引用(对活动的引用应该与活动本身具有相同的生命周期)。 http://www.curious-creature.org/2008/12/18/avoid-memory-leaks-on-android/ 你可以这样做 例: new MyClass(ActivityName.this); class MyClass { Context mContext; public MyClass(Context context ...