Skip to content

Commit d80b792

Browse files
committed
Knob props
1 parent 8f7ac02 commit d80b792

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/Controls/knob.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# module Poptart.Controls
22

33
"""
4-
Knob(; label::String, range, value, [frame])
4+
Knob(; label::String, range, value, [num_segments], [thickness], [frame])
55
"""
66
Knob
77

88
@UI Knob
99

1010
function properties(control::Knob)
11-
(properties(super(control))..., :label, :range, :value, )
11+
(properties(super(control))..., :label, :range, :value, :num_segments, :thickness, )
1212
end
1313

1414
# module Poptart.Controls

src/Desktop/Windows/imgui_controls.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ end
4545
function imgui_control_item(imctx::Ptr, item::Knob)
4646
label = item.label
4747
value_p = Ref{Cfloat}(item.value)
48-
v_min = minimum(item.range)
49-
v_max = maximum(item.range)
50-
fac = v_max
51-
sz = 20
52-
thickness = 4
48+
if item.range isa AbstractRange
49+
v_min, v_max = minimum(item.range), maximum(item.range)
50+
else
51+
v_min, v_max = item.range
52+
end
53+
num_segments = _get_item_props(item, :num_segments, 16)
54+
thickness = _get_item_props(item, :thickness, 4)
5355

54-
window_pos = CImGui.GetCursorScreenPos()
56+
frame = _get_item_props(item, :frame, (width=20,))
57+
radio = frame.width
5558

56-
radio = sz
59+
fac = v_max
60+
window_pos = CImGui.GetCursorScreenPos()
5761
center = ImVec2(window_pos.x + radio, window_pos.y + radio)
5862

5963
ANGLE_MIN = pi * 0.75
@@ -118,17 +122,15 @@ function imgui_control_item(imctx::Ptr, item::Knob)
118122

119123
if is_active
120124
col32idx = CImGui.ImGuiCol_FrameBgActive
125+
elseif is_hovered
126+
col32idx = CImGui.ImGuiCol_FrameBgHovered
121127
else
122-
if is_hovered
123-
col32idx = CImGui.ImGuiCol_FrameBgHovered
124-
else
125-
col32idx = CImGui.ImGuiCol_FrameBg
126-
end
128+
col32idx = CImGui.ImGuiCol_FrameBg
127129
end
128130
col32 = CImGui.igGetColorU32(col32idx, 1)
129131
col32line = CImGui.igGetColorU32(CImGui.ImGuiCol_SliderGrabActive, 1)
130132
draw_list = CImGui.GetWindowDrawList()
131-
CImGui.AddCircleFilled(draw_list, center, radio, col32, 16)
133+
CImGui.AddCircleFilled(draw_list, center, radio, col32, num_segments)
132134
CImGui.AddLine(draw_list, center, ImVec2(x2, y2), col32line, thickness)
133135
CImGui.SameLine()
134136

0 commit comments

Comments
 (0)