Skip to content

Commit 14a99bd

Browse files
Unix4everArtem Chernyshev
andauthored
Implemented CSS styling support (#17)
Please note that supported CSS set is limited. 1. libcss mostly supports CSS2 syntax. CSS3 parts will be added but not all at once. 2. CSS spec is huge, it's hard to implement it right away. Co-authored-by: Artem Chernyshev <[email protected]>
1 parent 7fa4a9a commit 14a99bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6157
-299
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
[submodule "nanosvg"]
55
path = nanosvg
66
url = https://github.com/memononen/nanosvg.git
7-
[submodule "katana-parser"]
8-
path = katana-parser
9-
url = https://github.com/hackers-painters/katana-parser.git
7+
[submodule "libcss"]
8+
path = libcss
9+
url = https://github.com/Unix4ever/libcss.git

CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ option(BUILD_SAMPLES "build ImVue samples" OFF)
66
option(BUILD_IMGUI_FROM_SUBMODULE "build Dear ImGui from submodule" ON)
77
option(BUILD_LUA_BINDINGS "build Lua bindings" ON)
88
option(BUILD_CSS_STYLING "build css styling" ON)
9-
option(BUILD_KATANA_FROM_SUBMODULE "build libcss using submodule" ON)
9+
option(BUILD_CSS_FROM_SUBMODULE "build libcss using submodule" ON)
1010
option(BUILD_TESTS "build unit test for the project" OFF)
1111
option(IMVUE_NO_EXCEPTIONS "disable raising exceptions. Use log errors instead" OFF)
1212
option(IMVUE_USE_LUAJIT "use luajit" OFF)
@@ -40,14 +40,13 @@ if(BUILD_LUA_BINDINGS)
4040
set(ADDITIONAL_SOURCES src/lua/script.cpp ${ADDITIONAL_SOURCES})
4141
endif(BUILD_LUA_BINDINGS)
4242

43-
# disable it for now. It's not used, and does not build on windows
44-
#if(BUILD_KATANA_FROM_SUBMODULE)
45-
# set(KATANA_INCLUDE_DIRS katana-parser/src/)
46-
# set(KATANA_LIBRARY katana)
47-
# include_directories(${KATANA_INCLUDE_DIRS})
48-
# file(GLOB_RECURSE sources katana-parser/src/*.c)
49-
# add_library(${KATANA_LIBRARY} STATIC ${sources})
50-
#endif(BUILD_KATANA_FROM_SUBMODULE)
43+
if(BUILD_CSS_FROM_SUBMODULE)
44+
add_subdirectory(libcss)
45+
include_directories(libcss/libcss/include)
46+
include_directories(libcss/libwapcaplet/include)
47+
include_directories(libcss/libparserutils/include)
48+
set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} css wapcaplet parserutils)
49+
endif(BUILD_CSS_FROM_SUBMODULE)
5150

5251
if(BUILD_TESTS)
5352
find_package(GTest)
@@ -73,7 +72,10 @@ add_library(${LIB_NAME} STATIC
7372
src/imvue_element.cpp
7473
src/imvue_script.cpp
7574
src/imvue_context.cpp
75+
src/imvue_style.cpp
76+
src/imvue_layout.cpp
7677
src/imstring.cpp
78+
src/css/select.cpp
7779
${ADDITIONAL_SOURCES})
7880

7981
set(IMGUI_SOURCES

README.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ You can either define them using `lua` syntax or `imv` xml file.
3838

3939
`imv` files search path is configured using `package.imvpath` variable.
4040

41+
CSS Styles Support
42+
------------------
43+
44+
ImVue supports CSS styling and HTML syntax to some extent.
45+
46+
[Styled document example](samples/simple/styled.xml) in action:
47+
48+
![demo](demo.gif)
49+
4150
Vue Special Syntax
4251
------------------
4352

@@ -65,7 +74,6 @@ Vue Special Syntax
6574
- Getting `event.target` in event handlers.
6675
- Changing element properties using refs (RO access only).
6776
- `${}` eval syntax in attributes.
68-
- CSS styles.
6977
- V8 JS integration.
7078

7179
### Lua Implementation Specifics
@@ -76,33 +84,18 @@ there is no limitation on what you can do. Globals are also available.
7684
Besides, it will create reactive listeners for each field that was used in the
7785
evaluation.
7886

79-
Benchmarks
80-
----------
81-
82-
Rendering 1000 windows with a single button.
83-
84-
```
85-
------------------------------------------------------------------------------
86-
Benchmark Time CPU Iterations
87-
------------------------------------------------------------------------------
88-
ImVueBenchmark/RenderImGuiLuaStatic 1968641 ns 1963054 ns 3493 # lua bindings
89-
ImVueBenchmark/RenderImGuiStatic 1894949 ns 1894921 ns 3654 # vanilla ImGui
90-
ImVueBenchmark/RenderImVueScripted 1909691 ns 1909661 ns 3615 # imgui with lua scripting enabled
91-
ImVueBenchmark/RenderImVueStatic 1888849 ns 1888819 ns 3667 # static xml template
92-
```
93-
9487
Dependencies
9588
------------
9689

9790
- ImGui without any modifications.
9891
- NanoSVG is used for image rendering. Using customized rasterizer.
9992
- RapidXML is used for XML parsing.
93+
- customized version of [LibCSS](https://github.com/Unix4ever/libcss).
10094

10195
Optional Core Dependecies
10296
-------------------------
10397

10498
- Lua 5.1+/LuaJIT 2.0.5+ - adds script interpreter.
105-
- katana-parser allows reading CSS to change widgets style.
10699

107100
Samples Dependencies
108101
--------------------
@@ -119,7 +112,3 @@ Build
119112
1. Run:
120113

121114
`make build`
122-
123-
### Using conan
124-
125-
TODO

demo.gif

1.16 MB
Loading

imgui

Submodule imgui updated 64 files

katana-parser

Lines changed: 0 additions & 1 deletion
This file was deleted.

libcss

Submodule libcss added at 34258bb

samples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ add_library(imgui_sdl2
1515

1616
set(LIBS
1717
imgui
18+
${ADDITIONAL_LIBS}
1819
${OPENGL_LIBRARIES}
1920
${GLEW_LIBRARIES}
20-
#${SDL2_LIBRARIES}
21-
${LUA_LIBRARIES}
21+
${SDL2_LIBRARIES}
2222
SDL2::SDL2main
2323
SDL2::SDL2-static
2424
)
125 KB
Binary file not shown.

samples/fonts/times new roman.ttf

340 KB
Binary file not shown.

0 commit comments

Comments
 (0)