Made dual list selection widget generic.
This commit is contained in:
@@ -172,20 +172,33 @@ proc draw*(component: ConsoleComponent, ws: WebSocket) =
|
||||
Huge thanks to @dinau for implementing ImGuiTextSelect into imguin very rapidly after I requested it.
|
||||
]#
|
||||
let consolePadding: float = 10.0f
|
||||
let footerHeight = (consolePadding * 2) + (igGetStyle().ItemSpacing.y + igGetFrameHeightWithSpacing()) * 1.5f
|
||||
let footerHeight = (consolePadding * 2) + (igGetStyle().ItemSpacing.y + igGetFrameHeightWithSpacing()) * 0.75f
|
||||
let textSpacing = igGetStyle().ItemSpacing.x
|
||||
|
||||
# Padding
|
||||
igDummy(vec2(0.0f, consolePadding))
|
||||
|
||||
#[
|
||||
Session information
|
||||
]#
|
||||
let domain = if component.agent.domain.isEmptyOrWhitespace(): "" else: fmt".{component.agent.domain}"
|
||||
let sessionInfo = fmt"{component.agent.username}@{component.agent.hostname}{domain} | {component.agent.ip} | {$component.agent.pid}/{component.agent.process}"
|
||||
igTextColored(GRAY, sessionInfo)
|
||||
igSameLine(0.0f, 0.0f)
|
||||
|
||||
#[
|
||||
Filter & Options
|
||||
]#
|
||||
|
||||
var availableSize: ImVec2
|
||||
igGetContentRegionAvail(addr availableSize)
|
||||
var labelSize: ImVec2
|
||||
igCalcTextSize(addr labelSize, ICON_FA_MAGNIFYING_GLASS, nil, false, 0.0f)
|
||||
igSameLine(0.0f, igGetWindowWidth() - 200.0f - (labelSize.x + textSpacing) - (igGetStyle().WindowPadding.x * 2))
|
||||
|
||||
# SHow tooltip when hovering the search icon
|
||||
let searchBoxWidth: float32 = 200.0f
|
||||
igSameLine(0.0f, availableSize.x - (labelSize.x + textSpacing) - searchBoxWidth)
|
||||
|
||||
# Show tooltip when hovering the search icon
|
||||
igTextUnformatted(ICON_FA_MAGNIFYING_GLASS.cstring, nil)
|
||||
if igIsItemHovered(ImGuiHoveredFlags_None.int32):
|
||||
igBeginTooltip()
|
||||
@@ -199,7 +212,7 @@ proc draw*(component: ConsoleComponent, ws: WebSocket) =
|
||||
igSetKeyboardFocusHere(0)
|
||||
|
||||
igSameLine(0.0f, textSpacing)
|
||||
component.filter.ImGuiTextFilter_Draw("##ConsoleSearch", 200.0f)
|
||||
component.filter.ImGuiTextFilter_Draw("##ConsoleSearch", searchBoxWidth)
|
||||
|
||||
try:
|
||||
# Set styles of the console window
|
||||
@@ -245,9 +258,8 @@ proc draw*(component: ConsoleComponent, ws: WebSocket) =
|
||||
igSameLine(0.0f, textSpacing)
|
||||
|
||||
# Calculate available width for input
|
||||
var availableWidth: ImVec2
|
||||
igGetContentRegionAvail(addr availableWidth)
|
||||
igSetNextItemWidth(availableWidth.x)
|
||||
igGetContentRegionAvail(addr availableSize)
|
||||
igSetNextItemWidth(availableSize.x)
|
||||
|
||||
let inputFlags = ImGuiInputTextFlags_EnterReturnsTrue.int32 or ImGuiInputTextFlags_EscapeClearsAll.int32 or ImGuiInputTextFlags_CallbackHistory.int32 or ImGuiInputTextFlags_CallbackCompletion.int32
|
||||
if igInputText("##Input", addr component.inputBuffer[0], MAX_INPUT_LENGTH, inputFlags, callback, cast[pointer](component)):
|
||||
@@ -277,11 +289,4 @@ proc draw*(component: ConsoleComponent, ws: WebSocket) =
|
||||
|
||||
igSetItemDefaultFocus()
|
||||
if focusInput:
|
||||
igSetKeyboardFocusHere(-1)
|
||||
|
||||
#[
|
||||
Session information
|
||||
]#
|
||||
let sessionInfo = fmt"{component.agent.username}@{component.agent.hostname}.{component.agent.domain} [{component.agent.ip}] [{component.agent.process}/{$component.agent.pid}]"
|
||||
igTextColored(vec4(0.75f, 0.75f, 0.75f, 1.0f), sessionInfo)
|
||||
|
||||
igSetKeyboardFocusHere(-1)
|
||||
@@ -12,7 +12,7 @@ type
|
||||
spoofStack: bool
|
||||
listeners: seq[string]
|
||||
sleepMaskTechniques: seq[string]
|
||||
moduleSelection: DualListSelectionComponent
|
||||
moduleSelection: DualListSelectionComponent[ModuleType]
|
||||
|
||||
proc AgentModal*(listeners: seq[Listener]): AgentModalComponent =
|
||||
result = new AgentModalComponent
|
||||
@@ -30,7 +30,11 @@ proc AgentModal*(listeners: seq[Listener]): AgentModalComponent =
|
||||
var modules: seq[ModuleType]
|
||||
for module in ModuleType:
|
||||
modules.add(module)
|
||||
result.moduleSelection = DualListSelection(modules)
|
||||
|
||||
proc moduleName(module: ModuleType): string =
|
||||
return ($module).split("_")[1..^1].mapIt(it.toLowerAscii().capitalizeAscii()).join("")
|
||||
|
||||
result.moduleSelection = DualListSelection(modules, moduleName)
|
||||
|
||||
proc resetModalValues(component: AgentModalComponent) =
|
||||
discard
|
||||
|
||||
@@ -4,18 +4,23 @@ import ../../utils/[appImGui, colors]
|
||||
import ../../../common/[types, utils]
|
||||
|
||||
type
|
||||
DualListSelectionComponent* = ref object of RootObj
|
||||
items*: array[2, seq[ModuleType]]
|
||||
DualListSelectionComponent*[T] = ref object of RootObj
|
||||
items*: array[2, seq[T]]
|
||||
selection: array[2, ptr ImGuiSelectionBasicStorage]
|
||||
display: proc(item: T): string
|
||||
|
||||
proc DualListSelection*(items: seq[ModuleType]): DualListSelectionComponent =
|
||||
result = new DualListSelectionComponent
|
||||
proc defaultDisplay[T](item: T): string =
|
||||
return $item
|
||||
|
||||
proc DualListSelection*[T](items: seq[T], display: proc(item: T): string = defaultDisplay): DualListSelectionComponent[T] =
|
||||
result = new DualListSelectionComponent[T]
|
||||
result.items[0] = items
|
||||
result.items[1] = @[]
|
||||
result.selection[0] = ImGuiSelectionBasicStorage_ImGuiSelectionBasicStorage()
|
||||
result.selection[1] = ImGuiSelectionBasicStorage_ImGuiSelectionBasicStorage()
|
||||
result.display = display
|
||||
|
||||
proc moveAll(component: DualListSelectionComponent, src, dst: int) =
|
||||
proc moveAll[T](component: DualListSelectionComponent[T], src, dst: int) =
|
||||
for m in component.items[src]:
|
||||
component.items[dst].add(m)
|
||||
component.items[dst].sort()
|
||||
@@ -24,7 +29,7 @@ proc moveAll(component: DualListSelectionComponent, src, dst: int) =
|
||||
ImGuiSelectionBasicStorage_Swap(component.selection[src], component.selection[dst])
|
||||
ImGuiSelectionBasicStorage_Clear(component.selection[src])
|
||||
|
||||
proc moveSelection(component: DualListSelectionComponent, src, dst: int) =
|
||||
proc moveSelection[T](component: DualListSelectionComponent[T], src, dst: int) =
|
||||
var keep: seq[ModuleType]
|
||||
for i in 0 ..< component.items[src].len():
|
||||
let item = component.items[src][i]
|
||||
@@ -38,10 +43,7 @@ proc moveSelection(component: DualListSelectionComponent, src, dst: int) =
|
||||
ImGuiSelectionBasicStorage_Swap(component.selection[src], component.selection[dst])
|
||||
ImGuiSelectionBasicStorage_Clear(component.selection[src])
|
||||
|
||||
proc moduleName(module: ModuleType): string =
|
||||
return ($module).split("_")[1..^1].mapIt(it.toLowerAscii().capitalizeAscii()).join("")
|
||||
|
||||
proc draw*(component: DualListSelectionComponent) =
|
||||
proc draw*[T](component: DualListSelectionComponent[T]) =
|
||||
|
||||
if igBeginTable("split", 3, ImGuiTableFlags_None.int32, vec2(0.0f, 0.0f), 0.0f):
|
||||
|
||||
@@ -77,7 +79,7 @@ proc draw*(component: DualListSelectionComponent) =
|
||||
for row in 0 ..< modules.len().int32:
|
||||
var isSelected = ImGuiSelectionBasicStorage_Contains(selection, cast[ImGuiID](row))
|
||||
igSetNextItemSelectionUserData(row)
|
||||
discard igSelectable_Bool(modules[row].moduleName(), isSelected, ImGuiSelectableFlags_AllowDoubleClick.int32, vec2(0.0f, 0.0f))
|
||||
discard igSelectable_Bool(component.display(modules[row]), isSelected, ImGuiSelectableFlags_AllowDoubleClick.int32, vec2(0.0f, 0.0f))
|
||||
|
||||
# Move on Enter and double-click
|
||||
if igIsItemFocused():
|
||||
@@ -127,7 +129,7 @@ proc draw*(component: DualListSelectionComponent) =
|
||||
for row in 0 ..< modules.len().int32:
|
||||
var isSelected = ImGuiSelectionBasicStorage_Contains(selection, cast[ImGuiID](row))
|
||||
igSetNextItemSelectionUserData(row)
|
||||
discard igSelectable_Bool(modules[row].moduleName(), isSelected, ImGuiSelectableFlags_AllowDoubleClick.int32, vec2(0.0f, 0.0f))
|
||||
discard igSelectable_Bool(component.display(modules[row]), isSelected, ImGuiSelectableFlags_AllowDoubleClick.int32, vec2(0.0f, 0.0f))
|
||||
|
||||
# Move on Enter and double-click
|
||||
if igIsItemFocused():
|
||||
|
||||
Reference in New Issue
Block a user