Skip to content

Commit a958bca

Browse files
committed
Add prelude and core themes
1 parent 42332e8 commit a958bca

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

builtin/ui/init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ dofile(UI_PATH .. "style.lua")
2727
dofile(UI_PATH .. "elem.lua")
2828
dofile(UI_PATH .. "window.lua")
2929
dofile(UI_PATH .. "elem_defs.lua")
30+
dofile(UI_PATH .. "theme.lua")

builtin/ui/style.lua

-10
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,3 @@ function ui._encode_props(props)
218218

219219
return ui._encode("s", ui._encode_flags(fl))
220220
end
221-
222-
local default_theme = ui.Style{}
223-
224-
function ui.get_default_theme()
225-
return default_theme
226-
end
227-
228-
function ui.set_default_theme(theme)
229-
default_theme = theme
230-
end

builtin/ui/theme.lua

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
--[[
2+
Minetest
3+
Copyright (C) 2023 v-rob, Vincent Robinson <[email protected]>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
--]]
19+
20+
local prelude_theme = ui.Style{
21+
ui.Style{
22+
sel = "root",
23+
24+
-- The root window should be centered on the screen, but have no size
25+
-- by default, since the size should be user-set.
26+
rel_pos = {1/2, 1/2},
27+
rel_anchor = {1/2, 1/2},
28+
rel_size = {0, 0},
29+
30+
-- Normally, we don't show the backdrop unless we have user focus.
31+
ui.Style{
32+
sel = "@backdrop",
33+
visible = false,
34+
},
35+
ui.Style{
36+
sel = "@backdrop$focused",
37+
visible = true,
38+
}
39+
},
40+
ui.Style{
41+
sel = "image",
42+
43+
-- We generally want images to take up as much space as possible.
44+
fg_scale = 0,
45+
},
46+
ui.Style{
47+
sel = "button, toggle, check, switch",
48+
49+
-- By default, buttons, toggle buttons, checkboxes, radio buttons, and
50+
-- switches have their image placed on the left side by default.
51+
fg_halign = "left",
52+
},
53+
}
54+
55+
function ui.get_prelude_theme()
56+
return prelude_theme
57+
end
58+
59+
local core_theme = ui.Style{
60+
-- Like any good theme should, we include the prelude theme first.
61+
prelude_theme,
62+
63+
-- TODO
64+
ui.Style{
65+
sel = "root",
66+
67+
bg_fill = "black#8C",
68+
69+
ui.Style{
70+
sel = "@backdrop",
71+
72+
bg_fill = "black#50",
73+
},
74+
},
75+
}
76+
77+
function ui.get_core_theme()
78+
return core_theme
79+
end
80+
81+
local default_theme = core_theme
82+
83+
function ui.get_default_theme()
84+
return default_theme
85+
end
86+
87+
function ui.set_default_theme(theme)
88+
default_theme = theme
89+
end

0 commit comments

Comments
 (0)