Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions luaui/Include/keybind_dropdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ local colorText = "\255\235\235\235"
-- SelectHighlight defaults to 0.35 and the rest of the UI stays near it. At 1 the
-- overlay is opaque and swallows the option label under it.
local hoverOpacity = 0.25
-- Lighter for the control itself than for a row of the open list: one says the cursor
-- is on it, the other says this is the option a click would take.
local controlHoverOpacity = 0.14
local white = { 1, 1, 1 }
local listFill = { 0.09, 0.09, 0.09, 0.96 }

Expand Down Expand Up @@ -124,6 +127,9 @@ function Dropdown:draw()
local inset = floor((y2 - y1) * 0.3)

Selector(x1, y1, x2, y2)
if mx >= x1 and mx <= x2 and my >= y1 and my <= y2 then
Highlight(x1, y1, x2, y2, floor(WG.FlowUI.elementCorner * 0.66), controlHoverOpacity, white)
end

-- Chevron in the gap already reserved at the right edge, so the control reads as a
-- select rather than a button. Drawn before the text: geometry inside a font batch
Expand Down Expand Up @@ -151,9 +157,9 @@ function Dropdown:draw()
font:Print(
fittedLabel(fitted, 0, font, label, labelW, self.fontSize),
x1 + inset,
floor((y1 + y2) * 0.5),
text.baseline(font, y1, y2, self.fontSize),
self.fontSize,
"ov"
"o"
)
font:End()

Expand All @@ -179,9 +185,9 @@ function Dropdown:draw()
font:Print(
fittedLabel(fitted, i, font, optionLabel(opt), w, self.fontSize),
r.x1 + inset,
floor((r.y1 + r.y2) * 0.5),
text.baseline(font, r.y1, r.y2, self.fontSize),
self.fontSize,
"ov"
"o"
)
end
font:End()
Expand Down
24 changes: 19 additions & 5 deletions luaui/Include/keybind_editbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
local utf8 = VFS.Include("common/luaUtilities/utf8.lua")

local KEYSYMS = VFS.Include("luaui/Include/keybind_keysyms.lua")
local text = VFS.Include("luaui/Include/keybind_text.lua")

local Editbox = {}
Editbox.__index = Editbox
Expand All @@ -20,6 +21,11 @@ local colorDim = "\255\160\160\160"
local cursorBlinkDuration = 1
local cursorGrey = 0.7

-- What the panels light a row with under the cursor. The field takes the same, so it
-- reads as something you can click into rather than a plate with text on it.
local hoverOpacity = 0.14
local white = { 1, 1, 1 }

-- Font is fetched per draw; it does not exist when this file is included.
local function getFont()
return WG["fonts"].getFont()
Expand Down Expand Up @@ -55,7 +61,7 @@ end
function Editbox:setRect(x1, y1, x2, y2, fontSize, pad)
self.rect = { x1, y1, x2, y2 }
self.fontSize = fontSize or (y2 - y1) * 0.5
self.pad = pad or floor((y2 - y1) * 0.2)
self.pad = pad or floor((y2 - y1) * 0.3)
end

function Editbox:getText()
Expand Down Expand Up @@ -333,10 +339,18 @@ function Editbox:draw()
local cs = floor(WG.FlowUI.elementCorner * 0.66)
local inset = floor((y2 - y1) * 0.18)
local tx = x1 + self.pad
local ty = floor((y1 + y2) * 0.5)
-- The middle of the field, for the caret and the selection, which are box-shaped and
-- want the box; and the baseline the text is drawn from, which wants the font.
local cy = floor((y1 + y2) * 0.5)
local ty = text.baseline(font, y1, y2, self.fontSize)

R(x1, y1, x2, y2, cs, 1, 1, 1, 1, fieldFill)

local mx, my = Spring.GetMouseState()
if mx >= x1 and mx <= x2 and my >= y1 and my <= y2 then
WG.FlowUI.Draw.SelectHighlight(x1, y1, x2, y2, cs, hoverOpacity, white)
end

if self:hasSelection() then
local a, b = self:selRange()
local sa = floor(font:GetTextWidth(utf8.sub(self.text, 1, a)) * self.fontSize)
Expand All @@ -363,16 +377,16 @@ function Editbox:draw()
end

font:Begin()
font:Print(shown, tx, ty, self.fontSize, "ov")
font:Print(shown, tx, ty, self.fontSize, "o")
font:End()

if self.focused then
-- Sharp bar rather than a rounded one, sized and placed off the font like chat's:
-- a fixed span around the text's middle, so it does not stretch with the field.
local cx = floor(tx + caretOffset(self, font))
local cWidth = 1 + floor(self.fontSize / 14)
local cy1 = math.max(y1 + 1, floor(ty - self.fontSize * 0.6))
local cy2 = math.min(y2 - 1, floor(ty + self.fontSize * 0.64))
local cy1 = math.max(y1 + 1, floor(cy - self.fontSize * 0.6))
local cy2 = math.min(y2 - 1, floor(cy + self.fontSize * 0.64))
gl.Color(cursorGrey, cursorGrey, cursorGrey, caretAlpha(self))
gl.Rect(cx, cy1, cx + cWidth, cy2)
gl.Color(1, 1, 1, 1)
Expand Down
Loading
Loading