🟡cl_combobox

The Dlib.ComboBox is an enhanced combo box component tailored for a better visual experience and more intuitive interactions in Garry's Mod interfaces.

Overview:

Initialization (Init)

  • The combo box has a default height of 30 units.

  • The default text color is set to white (Color(255, 255, 255)).

  • It utilizes the default font ("DermaDefault").

Opening the Menu (OpenMenu)

  • This function facilitates the opening of the dropdown menu.

  • It checks if the text entry field is already opened, preventing it from re-opening.

  • If the menu already exists, it's removed before a new one is created.

  • The menu's background color is set to a shade of grey (Color(60, 60, 60)).

  • Each option in the menu:

    • Has its text color set to white.

    • Displays a slightly lighter background when hovered (Color(80, 80, 80)).

  • The menu is displayed right below the combo box when triggered.

Paint Method (Paint)

  • This function handles the visual rendering of the combo box.

  • The combo box is painted with a grey background color (Color(60, 60, 60)).

  • A slim vertical red strip (Color(255, 100, 100)) decorates its left side.

The component is registered in the vGUI system under the name "Dlib.ComboBox" and extends the behavior of the "DComboBox".

Usage Example:

In the provided example, the Dlib.ComboBox is tested within a frame. Here's a step-by-step breakdown:


concommand.Add("test", function()
    -- Tworzenie głównego okna
    local frame = vgui.Create("Dlib.Frame")
    frame:SetSize(400, 300)
    frame:Center()
    frame:SetTitle("Test Dlib.ComboBox")
    frame:MakePopup()

    -- Tworzenie Dlib.ComboBox
    local combo = vgui.Create("Dlib.ComboBox", frame)
    combo:SetPos(50, 50)
    combo:SetSize(300, 30)
    combo:AddChoice("Opcja 1")
    combo:AddChoice("Opcja 2")
    combo:AddChoice("Opcja 3")
    combo.OnSelect = function(panel, index, value)
        print("Wybrano:", value)
    end
end)
  • A frame named "Test Dlib.ComboBox" is created and centered on the screen.

  • Inside this frame, the Dlib.ComboBox is positioned and three choices ("Opcja 1", "Opcja 2", and "Opcja 3") are added.

  • When a choice is selected from the dropdown, the selected value is printed to the console.

By customizing and utilizing Dlib.ComboBox, developers can seamlessly integrate a visually appealing and functional combo box into their Garry's Mod interfaces.

Preview:

Last updated