Skip to content

Commit

Permalink
Cleanup of special props for container tags, cleanup of the ui-tree i…
Browse files Browse the repository at this point in the history
…nterface, fixing example syntax for xml
  • Loading branch information
karurochari committed Dec 18, 2024
1 parent e67c094 commit c3bc5f2
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 93 deletions.
18 changes: 10 additions & 8 deletions examples/example-0.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Please ignore this example, it is used for
development-->
<app type="native" link-with="this://native-app/app" xmlns:fl="vs.fltk">
<app
link-with.lib="this://native-app/libapp.so"
link-with.header="this://native-app/app.h"
xmlns:fl="vs.fltk"
>
<import src="two-buttons.xml" as="TwoButtons" />
<import src="three-buttons.xml" as="ThreeButtons">
<label>It does not exist</label>
Expand Down Expand Up @@ -30,10 +34,8 @@ development-->
<fl:button label="callback-top">
<script lang="c">
<![CDATA[
//#include <app.h>
void callback(){
//add(1,2);
$log(0,"Tying call %p",$("..."));
$log(0,"Tying call %p %d",$("..."),42);
$$prop($("..."),"ciao","mondo");
return;
}
Expand Down Expand Up @@ -131,7 +133,7 @@ development-->
</script>
</fl:button>

<namespace type="native" name="%roots">
<namespace frame.type="native" name="%roots">
<mixin name="+fl:button" bg.colour="#00ae92" />
<mixin name="*" label.colour="#34a977" />
<mixin name="btn-2" box="150,40,80,30" label="Makika" />
Expand Down Expand Up @@ -198,13 +200,13 @@ development-->
</fl:button>
</fl:group>
</namespace>
<namespace type="wasm">
<namespace frame.type="wasm">

</namespace>
<namespace type="quickjs">
<namespace frame.type="quickjs">

</namespace>
<namespace type="ext">
<namespace frame.type="ext">

</namespace>
</fl:window>
Expand Down
25 changes: 23 additions & 2 deletions include/components/containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class ui_root_thin_component : public ui_base{
virtual frame_type_t default_frame_type() override {return frame_type_t::CONTAINER;}
virtual const char* class_name() override{return "component.thin";}

int apply_prop(const char *prop, const char *value) override{if(local_frame!=nullptr)return local_frame->call_dispatcher(prop,value);return 1;}
int apply_prop(const char *prop, const char *value) override{
if(strncmp(prop, "xmlns:", sizeof("xmlns:")-1)==0){return 0;}
else if(strcmp(prop, "name")==0){return 0;}
else if(strncmp(prop, "frame.", sizeof("frame.")-1)==0){return 0;}
if(local_frame!=nullptr)return local_frame->call_dispatcher(prop,value);
return 1;
}

int get_computed(const char *prop, const char **value) override{return 1;}
};

Expand All @@ -43,6 +50,14 @@ class ui_root_app :public ui_root_component{
ui_root_app(frame_mode_t MODE):ui_root_component(MODE){}

virtual const char* class_name() override{return "app";}
int apply_prop(const char *prop, const char *value) override{
if(strncmp(prop, "xmlns:", sizeof("xmlns:")-1)==0){return 0;}
else if(strncmp(prop, "link-with.", sizeof("link-with.")-1)==0){return 0;}
else if(strncmp(prop, "frame.", sizeof("frame.")-1)==0){return 0;}
if(local_frame!=nullptr)return local_frame->call_dispatcher(prop,value);
return 1;
}

};


Expand All @@ -59,7 +74,13 @@ class ui_namespace : public ui_base{
virtual frame_type_t default_frame_type() override {return frame_type_t::NODE;}
virtual const char* class_name() override{return "namespace";}

int apply_prop(const char *prop, const char *value) override{if(local_frame!=nullptr)return local_frame->call_dispatcher(prop,value);return 1;}
int apply_prop(const char *prop, const char *value) override{
if(strcmp(prop, "name")==0){return 0;}
else if(strncmp(prop, "frame.", sizeof("frame.")-1)==0){return 0;}
if(local_frame!=nullptr)return local_frame->call_dispatcher(prop,value);
return 1;
}

int get_computed(const char *prop, const char **value) override{return 1;}
};

Expand Down
27 changes: 20 additions & 7 deletions include/ui-tree.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "globals.hpp"
#include "pipelines/commons.hpp"
#include "ui-frame.hpp"
#include <ui.hpp>
#include <cache/commons.hpp>
Expand All @@ -15,21 +16,23 @@ struct ui_tree {
//Define the embedded mode supported.
frame_mode_t mode = frame_mode_t::AUTO;

global_ctx_t& globals; //Just for book-keeping
//Book-keeping. Duplicated info on nested structures, but they are short lived, and it is better compared to unrolling the stack each time.
global_ctx_t* globals;
//Book-keeping. Duplicated info on nested structures, but they are short lived, and it is better compared to unrolling the stack each time.
pipelines::link_with_t link_with = {nullptr, nullptr};

ui_tree* parent = nullptr; //Set if there is an explict owner of this root, for example a viewport/app.
ui_base* caller_ui_node=nullptr; //Element from a parent tree calling me
ui_base* root = nullptr; //Base element of this tree

policies_t policies; //Computed policies for this tree
scoped_rpath_t local; //Full path for the location of this component.
scoped_rpath_t fullname; //Full path for the location of this component.
scoped_rpath_t local; //Full path for the location of this component. Redundant but used to make some operations faster.
scoped_rpath_t fullname; //Full path with name for the location of this component.
size_t local_unique_counter = 0;

// Globals
std::string basename;
std::map<std::string, std::string, std::less<>> modules;
// TODO Add policies
std::map<std::string,std::string> imports;

std::map<std::string, std::string, std::less<>> props_from_above;
std::map<std::string, ui<> *, std::less<>> slots_from_above;

Expand All @@ -48,7 +51,17 @@ struct ui_tree {
virtual void cleanup();
virtual int runtime_testsuite();

inline ui_tree(global_ctx_t& g, ui_tree* parent, ui_base* caller_ui_node):globals(g){this->parent=parent;this->caller_ui_node=caller_ui_node;}
virtual int build() = 0;
virtual int load(const char* file, type_t type) = 0;

inline ui_tree(ui_tree* parent, ui_base* caller_ui_node){
this->parent=parent;
if(parent!=nullptr){
link_with=parent->link_with;
globals=parent->globals;
}
this->caller_ui_node=caller_ui_node;
}

};

Expand Down
22 changes: 9 additions & 13 deletions include/ui-tree.xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ struct ui_tree_xml : ui_tree {

pugi::xml_document doc; //Handle of the xml parser

std::map<std::string,std::string> imports;

template <std::derived_from<ui_base> T>
T *build_base_widget(const pugi::xml_node &root, ui_base * root_ui = nullptr);

void _build_base_widget_extended_attr(const pugi::xml_node &root, ui_base * current);
void _build(const pugi::xml_node &root, ui_base *root_ui = nullptr);

public:
void set_namespace(namespaces_t n, const char* prefix){
Expand All @@ -41,20 +44,13 @@ struct ui_tree_xml : ui_tree {
else if(n==namespaces_t::s){if(prefix[0]==0)ns.s="";else ns.s=std::string(prefix)+":";}
}

template <std::derived_from<ui_base> T>
T *build_base_widget(const pugi::xml_node &root, ui_base * root_ui = nullptr);

void _build_base_widget_extended_attr(const pugi::xml_node &root, ui_base * current);
void _build(const pugi::xml_node &root, ui_base *root_ui = nullptr);

int build();

int load(const char* file, type_t type);
virtual int build() override;
virtual int load(const char* file, type_t type) override;

inline ui_tree_xml(global_ctx_t& g, ui_tree* parent, ui_base* caller_ui_node, const pugi::xml_node* caller_xml_node):ui_tree(g,parent,caller_ui_node){this->caller_xml_node=caller_xml_node;}
inline ui_tree_xml(ui_tree* parent, ui_base* caller_ui_node, const pugi::xml_node* caller_xml_node):ui_tree(parent,caller_ui_node){this->caller_xml_node=caller_xml_node;}
virtual ~ui_tree_xml();
virtual void cleanup();
virtual int runtime_testsuite(){if(this->root!=nullptr)return this->root->all_tests();return 0;}
virtual void cleanup() override;
virtual int runtime_testsuite() override{if(this->root!=nullptr)return this->root->all_tests();return 0;}

// Logging

Expand Down
32 changes: 23 additions & 9 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ vs_fltk_deps = []

# Process options

add_global_arguments(['-DVS_COMMONS_DIR="'+join_paths(get_option('prefix'),get_option('datadir'),'vs-fltk')+'/"'], language: ['cpp', 'c'])

add_global_arguments(
[
'-DVS_COMMONS_DIR="'
+ join_paths(get_option('prefix'), get_option('datadir'), 'vs-fltk')
+ '/"',
],
language: ['cpp', 'c'],
)

if get_option('use_tcc')
add_global_arguments(['-DVS_USE_TCC'], language: ['cpp', 'c'])
Expand Down Expand Up @@ -64,7 +70,12 @@ if need_pugixml or get_option('use_system_pugixml') == false
endif

if get_option('use_system_fltk')
libfltk_dep = dependency('FLTK', version: '>=1.4.0', modules: ['fltk::fltk', 'fltk::images', 'fltk::forms'], required: false)
libfltk_dep = dependency(
'FLTK',
version: '>=1.4.0',
modules: ['fltk::fltk', 'fltk::images', 'fltk::forms'],
required: false,
)
if libfltk_dep.found() == false
#For MacOS14 assuming a brew dependency because there is something broken in there.
libfltk_dep = dependency('fltk', required: false)
Expand All @@ -83,7 +94,7 @@ if need_fltk == true or get_option('use_system_fltk') == false
'FLTK_BUILD_OPTIONS': false,
'FLTK_BUILD_SHARED_LIBS': true,
'CMAKE_POSITION_INDEPENDENT_CODE': true,
'CMAKE_INSTALL_LIBDIR': get_option('libdir')
'CMAKE_INSTALL_LIBDIR': get_option('libdir'),
},
)

Expand All @@ -92,7 +103,11 @@ if need_fltk == true or get_option('use_system_fltk') == false
endif

libfltk_proj = cmake.subproject('libfltk', options: opt_fltk)
libfltk_dep = [ libfltk_proj.dependency(['fltk-shared']), libfltk_proj.dependency(['fltk-images-shared']), libfltk_proj.dependency(['fltk-forms-shared'])]
libfltk_dep = [
libfltk_proj.dependency(['fltk-shared']),
libfltk_proj.dependency(['fltk-images-shared']),
libfltk_proj.dependency(['fltk-forms-shared']),
]
#libfltk_gl_dep = libfltk_proj.dependency(['fltk-gl'])
endif

Expand All @@ -102,7 +117,7 @@ if get_option('use_wamr')
{
'WAMR_BUILD_INTERP': 1,
'WAMR_BUILD_PLATFORM': target_machine.system(),
'CMAKE_INSTALL_LIBDIR': get_option('libdir')
'CMAKE_INSTALL_LIBDIR': get_option('libdir'),
},
)
wamr_proj = cmake.subproject('wamr', options: opt_wamr)
Expand All @@ -117,7 +132,7 @@ if get_option('use_quickjs')
opt_quickjs.add_cmake_defines(
{
'CMAKE_POSITION_INDEPENDENT_CODE': true,
'CMAKE_INSTALL_LIBDIR': get_option('libdir')
'CMAKE_INSTALL_LIBDIR': get_option('libdir'),
},
)

Expand All @@ -144,7 +159,7 @@ opt_fmt.add_cmake_defines(
{
'CMAKE_POSITION_INDEPENDENT_CODE': true,
'BUILD_SHARED_LIBS': false,
'CMAKE_INSTALL_LIBDIR': get_option('libdir')
'CMAKE_INSTALL_LIBDIR': get_option('libdir'),
},
)
fmt_proj = cmake.subproject('fmt', options: opt_fmt)
Expand Down Expand Up @@ -347,7 +362,6 @@ subdir(['./experiments/'])

subdir(['./metadata/'])


if get_option('tests')
subdir(['./test/'])
subdir(['./benchmark/'])
Expand Down
2 changes: 1 addition & 1 deletion schemas/components/fl:base.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "node",
"headers": ["FL/Fl_Group.H"],
"codegen": { "extends": "ui<Fl_Group>" },
"skip_fields": ["name", "frame.*", "xsml", "xsml:*"],
"skip_fields": ["name", "frame.*", "xmlns", "xmlns:*"],
"fields": {
"mixin": {
"type": "string",
Expand Down
8 changes: 5 additions & 3 deletions src/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ app_loader::app_loader(global_ctx_t& globals, const char *profile, const char *p
doc.load_string(embedded_profile);
}

root = new ui_tree_xml(globals,nullptr,nullptr,nullptr);
root = new ui_tree_xml(nullptr,nullptr,nullptr);
root->globals=&globals;

if (root->load(path, ui_tree::type_t::APP) != 0) {
throw "Unable to process file";
} else {
Expand All @@ -52,9 +54,9 @@ int app_loader::test() {
}

int app_loader::run() {
root->globals.mem_storage.cleanup();
root->globals->mem_storage.cleanup();
root->cleanup();
if (!root->globals.env.computed_policies.headless) {
if (!root->globals->env.computed_policies.headless) {
auto t = Fl::run();
delete root;
root = nullptr;
Expand Down
37 changes: 22 additions & 15 deletions src/pipelines/tcc-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::shared_ptr<tcc> tcc_c_pipeline(global_ctx_t& globals, bool is_runtime, vs::
auto script = std::make_shared<tcc>();

//This part is a bit of a mess.
//Without libc.so and libtcc1.a (not sure which) dynamic linking is not working as expected. I would really like to remove the libc dependency.
// I would really like to remove the libc dependency.

script->set_error_fn(ctx,error_fn);
script->set_opts("-nostdlib"); //-fno-builtin
Expand All @@ -76,31 +76,38 @@ std::shared_ptr<tcc> tcc_c_pipeline(global_ctx_t& globals, bool is_runtime, vs::
//- The location where it s headers are placed.
//- The path for bindings shall be computed as absolute based on VS_SHARE or whatever it is called.

//script->add_lib_path("/usr/lib/x86_64-linux-gnu/"); //I dont' want to hardcode this one.
//script->add_lib_path("./subprojects/libtcc");
//script->add_lib_path("/usr/lib/x86_64-linux-gnu/"); //TODO: set it via a macro passed by meson.

script->set_out_type(tcc::memory);

script->add_lib_path((globals.path_env.root.location+"./bindings/native/tcc/lib").c_str());
script->add_sysinclude_path((globals.path_env.root.location+"./bindings/native/tcc/include").c_str());

script->add_include_path((globals.path_env.root.location+"./bindings/native/include").c_str());

//script->add_lib("ld");
//script->add_lib("dl");
//script->add_lib("tcc1");
//script->add_lib("c");

script->set_out_type(tcc::memory);

/*if(link_with!=nullptr){
//TODO: Split in the last "/" position. Left is path for include and libraries to link, the remaining tag is the name it has.
std::string link_header=(std::string(link_with));
link_header.append(".h");
std::string link_lib=(std::string(link_with));
script->add_lib_path("/home/checkroom/Documents/projects/vs-fltk/examples/native-app/");
script->add_include_path("/home/checkroom/Documents/projects/vs-fltk/examples/native-app/");
script->add_lib("app");
}*/
if(link_with.header!=nullptr){
{
std::string h = link_with.header;
auto const pos = h.find_last_of('/');
std::string path = h.substr(0,pos );
std::string file = h.substr(pos + 1);
script->add_include_path(path.c_str());
}
}

/*
if(link_with.lib!=nullptr){
script->add_lib_path("/");
script->add_lib(link_with.lib);
}
*/

// Custom symbol
//script->add_sym("vs_self", (void *)obj==0?(void*)-1:obj); //Needed as obj nullptr would remove the symbol for some stupid reason.
script->add_sym("vs_debug", (void *)vs_debug);
script->add_sym("vs_log", (void *)vs_log);
script->add_sym("vs_resolve_name", (void *)+[](ui_base* w,const char* s){if(w==nullptr)return (const ui_base*)nullptr;return w->resolve_name(s, true); });
Expand Down
Loading

0 comments on commit c3bc5f2

Please sign in to comment.