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
16 changes: 16 additions & 0 deletions LuaGObject/override/Gtk4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gtk.Widget._attribute = {
width = { get = Gtk.Widget.get_allocated_width },
height = { get = Gtk.Widget.get_allocated_height },
children = {},
extra_css_classes = {},
}

-- Allow to query a widget's currently-allocated dimensions by indexing .width or .height, and set the requested dimensions by assigning these pseudo-properties.
Expand Down Expand Up @@ -70,6 +71,21 @@ function Gtk.Widget._attribute.children:get()
return setmetatable({ _widget = self }, widget_children_mt)
end

function Gtk.Widget._attribute.extra_css_classes:get()
error("%s: Cannot read extra_css_classes; attribute is read-only.", self._type.name)
end
function Gtk.Widget._attribute.extra_css_classes:set(value)
if type(value) == "string" then
value = { value }
end
if type(value) ~= "table" then
error("%s: Cannot assign value of type %s to extra_css_classes", self._type.name, type(value))
end
for _, c in pairs(value) do
self:add_css_class(c)
end
end

-- Simple container support --

Gtk.Box._container_add = Gtk.Box._method.append
Expand Down
11 changes: 11 additions & 0 deletions tests/gtk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,14 @@ function gtk.notebook_container()
check(notebook:get_nth_page(1) == label2)
check(notebook:get_nth_page(2) == label3)
end

function gtk.extra_css_classes()
local Gtk = LuaGObject.Gtk
local box = Gtk.Box {
orientation = "VERTICAL",
extra_css_classes = { "linked" },
}
check(box:has_css_class "linked")
-- The .vertical CSS class comes from setting the orientation to vertical. By checking it here, the test ensures that the existing class isn't overwritten by extra_css_classes.
check(box:has_css_class "vertical")
end
Loading