Change drawing commands in customwidget example

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
Christopher Arndt 2024-04-09 18:45:43 +02:00
parent 85b669385f
commit 2ea0ad23e9
2 changed files with 13 additions and 8 deletions

View File

@ -3,7 +3,7 @@
import math
from nanogui import Color, Cursor, FloatBox, Vector2f, Vector2i, Widget, glfw
from nanogui.nanovg import BUTT, RGB, RGBA, RGBAf, LerpRGBA, NVGwinding, RGBAf
from nanogui.nanovg import BUTT, LerpRGBA, NVGwinding, RGB, RGBA, RGBAf
class Knob(Widget):

View File

@ -3,14 +3,14 @@
import nanogui
from nanogui import glfw
from nanogui import BoxLayout, Color, Label, Orientation, Screen, Widget, Window, Vector2i
from nanogui.nanovg import RGBAf, RGB
from nanogui.nanovg import LerpRGBA, RGBAf, RGB
class CustomWidget(Widget):
def __init__(self, parent, size=(100, 100), color=Color(192, 0, 0, 255)):
super().__init__(parent)
self._size = size
self._color = RGBAf(color.r, color.g, color.b, color.w)
self.color = RGBAf(color.r, color.g, color.b, color.w)
def preferred_size(self, ctx):
return Vector2i(self._size)
@ -21,13 +21,18 @@ class CustomWidget(Widget):
ctx.BeginPath()
ctx.Rect(pos[0], pos[1], size[0], size[1])
ctx.FillColor(RGB(128, 128, 0))
bg = LerpRGBA(RGB(64, 64, 64), self.color, 0.3)
ctx.FillColor(bg)
ctx.Fill()
ctx.BeginPath()
ctx.StrokeWidth(5.0)
ctx.StrokeColor(self._color)
ctx.MoveTo(pos[0], pos[1])
ctx.LineTo(pos[0] + size[0], pos[1] + size[1] / 3.0)
ctx.StrokeColor(self.color)
ctx.Rect(
pos[0] + size[0] / 4.0,
pos[1] + size[1] / 4.0,
size[0] / 2.0,
size[1] / 2.0,
)
ctx.Stroke()
ctx.ClosePath()
@ -42,7 +47,7 @@ class CustomWidgetApp(Screen):
Label(self.win, "NanoGUI CustomWidget Demo", "sans-bold")
cw = CustomWidget(self.win, (200, 100))
_ = CustomWidget(self.win, (200, 100))
self.draw_all()
self.set_visible(True)