Skip to content

Commit

Permalink
Added support for fat components, refactored inheritance of component…
Browse files Browse the repository at this point in the history
…/app containers. Preparing support of path type in props. Extended fl:window props.
  • Loading branch information
karurochari committed Dec 1, 2024
1 parent 79e0f15 commit ff1c5f1
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 73 deletions.
8 changes: 8 additions & 0 deletions commons/schemas/json-component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
"const": "string",
"type": "string"
},
{
"const": "path",
"type": "string"
},
{
"const": "color",
"type": "string"
Expand Down Expand Up @@ -221,6 +225,10 @@
"const": "string",
"type": "string"
},
{
"const": "path",
"type": "string"
},
{
"const": "color",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions docs/developers/building.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Move material in here from index.md
6 changes: 4 additions & 2 deletions docs/developers/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

- [ ] libfltk and its subdeps are compiled into `/app/lib64`, which is not covered by paths
Investigation got results. Basically, all cmake libraries are in `/app/lib` while those through meson are in `/app/lib64` which is not added to the search path in that image.
Even outside of flatpak this problem occurs, just with different folder names. I must ensure cmake and meson behave the same.
Even outside of flatpak this problem occurs, just with different folder names. I must ensure cmake and meson behave the same.
- [ ] commons are not mounted in `/usr/local/share`. I must pass the relevant vars (already supported).
I must register a variable in the user with where these files are located? Or embed it during compilation? Still not sure.
I must register a variable in the user with where these files are located? Or embed it during compilation? Still not sure.
- [ ] Icons, signature and few more things are still missing.

### Scripts
Expand Down Expand Up @@ -87,6 +87,8 @@ does not somehow. But just `./two-buttons.xml` does? Check why!
- [x] Unable to append args to meson setup
- [ ] Escape vs_debug (tabs).
- [ ] Add TESTING flag in scripts to determine if some content should be run or not.
- [ ] Add contextual information in app and component (keys, policies & paths). Remove them from ui_tree as they can be accessed via root.
- [ ] Once that is done, properly implement the path type for props, to resolve correctly.

### Scripting

Expand Down
11 changes: 6 additions & 5 deletions examples/example-0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<label>It does not exist</label>
</import>
<mixin name="+fl:button" box.h="100" box.w="100" />
<debug value="Important string A"/>
<debug value="Important string A" />

<script-global lang="c">
<def>
Expand Down Expand Up @@ -45,19 +45,20 @@
</script>
</fl:button>
</fl:window>
<fl:window box.w="640" box.h="480" name="ss">
<fl:window box.w="640" box.h="480" name="ss" border="false"
icon="./commons/assets/icons/vs.fltk.dark.svg">
<use>
<on-load.fail>
<fl:button box="0,0,50,50" label="Oh no!"/>
<fl:button box="0,0,50,50" label="Oh no!" />
</on-load.fail>
</use>

<use src="./two-buttons.xml">
<on-load.fail>
<fl:button box="200,250,50,50" label="Oh no!"/>
<fl:button box="200,250,50,50" label="Oh no!" />
</on-load.fail>
<inject>
<fl:button box="200,200,50,50" label="Oh yes!"/>
<fl:button box="200,200,50,50" label="Oh yes!" />
</inject>
</use>

Expand Down
3 changes: 2 additions & 1 deletion examples/module-example-btn.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<component xmlns:fl="vs.fltk">
<component xmlns:fl="vs.fltk" thin="true">
<fl:button label="Banana" box="0,0,100,100">
<script type="module" lang="c">
<![CDATA[
void callback(){
$prop("label","HELLO");
$log(LOG_INFO,"hello");
}
]]>
</script>
Expand Down
8 changes: 4 additions & 4 deletions examples/module-example-root.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<app xmlns:fl="vs.fltk">
<fl:window box="0,0,600,200">
<use src="this://module-example-btn.xml"/>
<use src="this://module-example-btn.xml" box.x="100"/>
<use src="this://module-example-btn.xml" box.x="200"/>
<fl:window box="0,0,600,200" name="win-1">
<use src="this://module-example-btn.xml" />
<use src="this://module-example-btn.xml" box.x="100" />
<use src="this://module-example-btn.xml" box.x="200" />
</fl:window>
</app>
32 changes: 18 additions & 14 deletions include/components/containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,43 @@
namespace vs{


class ui_root_app :public ui_base{
protected:
cache::ctx_t cache_ctx;

class ui_root_thin_component :public ui_base{
public:
ui_root_app(frame_mode_t MODE):ui_base(nullptr){
ui_root_thin_component(frame_mode_t MODE):ui_base(nullptr){
//Cannot use mk_frame as it requires recursion and the widget property to operate.
local_frame=new frame(nullptr, MODE, this, nullptr, default_frame_type(), frame_access_t::PUBLIC);
}

virtual frame_type_t default_frame_type() override {return frame_type_t::CONTAINER;}
virtual const char* class_name() override{return "root";}
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 get_computed(const char *prop, const char **value) override{return 1;}
};

class ui_root_component :public ui_base{
class ui_root_component :public ui_root_thin_component{
protected:
cache::ctx_t cache_ctx;
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.

public:
ui_root_component(frame_mode_t MODE):ui_base(nullptr){
//Cannot use mk_frame as it requires recursion and the widget property to operate.
local_frame=new frame(nullptr, MODE, this, nullptr, default_frame_type(), frame_access_t::PUBLIC);
}
ui_root_component(frame_mode_t MODE):ui_root_thin_component(MODE){}

virtual frame_type_t default_frame_type() override {return frame_type_t::CONTAINER;}
virtual const char* class_name() override{return "component";}
};


int apply_prop(const char *prop, const char *value) override{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;}
class ui_root_app :public ui_root_component{

public:
ui_root_app(frame_mode_t MODE):ui_root_component(MODE){}

virtual const char* class_name() override{return "app";}
};


//TODO: Add a new ui_region similar to namespace but with extra cache::ctx_t like app, to nest a new "safe" region inside.

class ui_namespace : public ui_base{
Expand Down
2 changes: 1 addition & 1 deletion include/ui-tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace vs {

struct ui_tree {
enum class type_t{
NONE, APP, COMPONENT, FRAGMENT
NONE, APP, COMPONENT, COMPONENT_THIN, FRAGMENT
}type;

//Define the embedded mode supported.
Expand Down
29 changes: 19 additions & 10 deletions schemas/components/fl:window.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
{
"$schema": "../../commons/schemas/json-component.schema.json",
"description": "Base element to a window",
"usable": true,
"type": "node",
"headers": ["FL/Fl_Window.H"],
"extends": "fl:base",
"codegen": {"extends": "ui<Fl_Window>"},
"props":{
"$schema": "../../commons/schemas/json-component.schema.json",
"description": "Base element to a window",
"usable": true,
"type": "node",
"headers": ["FL/Fl_Window.H", "FL/Fl_SVG_Image.H"],
"extends": "fl:base",
"codegen": { "extends": "ui<Fl_Window>" },
"props": {
"border": {
"type": "flag",
"description": "True if using a border around",
"code": "w.border(computed);"
},
"computed":{
"icon": {
"type": "string",
"description": "True if using a border around",
"code": "w.icon(new Fl_SVG_Image(value));"
}
}
},
"computed": {}
}
40 changes: 17 additions & 23 deletions schemas/vs-ns.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
{
"elements":[
"app",
"component",
"static-data",
"import",
"use",
"slot",
"viewport",
"data.",
"script",
"mixin",
"debug",
"namespace"
],

"attributes":[
"src.",
"name",
"frame.",
"template",
"mixins"
]
}
"elements": [
"app",
"component",
"static-data",
"import",
"use",
"slot",
"viewport",
"data.",
"script",
"mixin",
"debug",
"namespace"
],

"attributes": ["src.", "name", "frame.", "template", "mixins"]
}
1 change: 1 addition & 0 deletions scripts/codegen/components-new.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const type_schema = t.Union([
t.Literal('flag'),
t.Literal('enum'),
t.Literal('raw'),
t.Literal('path'),
t.Literal('string'),
t.Literal('color'),
t.Literal('scalar-1'),
Expand Down
10 changes: 5 additions & 5 deletions scripts/codegen/components.schema.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Type as t } from "@sinclair/typebox"

export const type_schema = t.Union([t.Literal('flag'), t.Literal('enum'), t.Literal('raw'), t.Literal('string'), t.Literal('color'), t.Literal('scalar-1'), t.Literal('scalar-2'), t.Literal('scalar-4')], { description: 'type', default: 'string' });
export const type_schema = t.Union([t.Literal('flag'), t.Literal('enum'), t.Literal('raw'), t.Literal('string'), t.Literal('path'), t.Literal('color'), t.Literal('scalar-1'), t.Literal('scalar-2'), t.Literal('scalar-4')], { description: 'type', default: 'string' });

const entries_schema = t.Record(t.String(), t.Object({
type: type_schema,
subtype: t.Optional(t.String()),
code: t.Union([t.String(),t.Null()], {default:null}),
code: t.Union([t.String(), t.Null()], { default: null }),
description: t.Optional(t.String()),
alias: t.Optional(t.Array(t.String(), { description: "alias names" , default:[]}))
alias: t.Optional(t.Array(t.String(), { description: "alias names", default: [] }))
}))

export const widget_schema = t.Object({
$schema: t.Optional(t.String()),
ns: t.Optional(t.String()),
name: t.Optional(t.String()),
usable: t.Optional(t.Boolean({default:true})),
usable: t.Optional(t.Boolean({ default: true })),
description: t.Optional(t.String()),
use_main_header: t.Union([t.Null(), t.String()], { default: null }),
headers: t.Optional(t.Array(t.String())),
Expand All @@ -26,7 +26,7 @@ export const widget_schema = t.Object({
computed_tail: t.Optional(t.Union([t.Null(), t.String()])),
}, { additionalProperties: false }),
extends: t.Union([t.Null(), t.String()], { default: null }),
skip_props: t.Optional(t.Array(t.String(),{default:[],description:"Properties to be matched but ignored"})),
skip_props: t.Optional(t.Array(t.String(), { default: [], description: "Properties to be matched but ignored" })),
props: entries_schema,
computed: entries_schema,
}, { additionalProperties: false })
3 changes: 2 additions & 1 deletion scripts/codegen/gen-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function make_type_code(type: Static<typeof type_schema>, subtype: string, code:
else if (type === 'scalar-2') return `size_t computed[2]; if((ok = field_types::h_px(2,computed,value,that))){${code}}`
else if (type === 'scalar-4') return `size_t computed[4]; if((ok = field_types::h_px(4,computed,value,that))){${code}}`
else if (type === 'enum') return `int computed = field_types::${subtype}_i(value);if((ok=(computed!=-1))){${code}}`
else if (type === 'path') return `/*TODO*/`
}

function gen_cpp(data: Static<typeof widget_schema>) {
Expand All @@ -35,7 +36,7 @@ function gen_cpp(data: Static<typeof widget_schema>) {
#include <ui.hpp>
#include <ui-field.types.hpp>
${cextends ? `#include <components/autogen/${cextends[0]}/${cextends[1]}.hpp>\n` : ``}
${data.headers ? data.headers.map(x => `#include <${x}>\n`) : ``}
${data.headers ? data.headers.map(x => `#include <${x}>\n`).join('\n') : ``}
namespace vs{
Expand Down
19 changes: 12 additions & 7 deletions src/ui-tree.xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,18 @@ int ui_tree_xml::build(){
//cache_ctx.computed_key = key256compose(token, cache_ctx.computed_key);
cache_ctx.page_tag = xml_root.attribute("page").as_string("");
}
else if(type==type_t::COMPONENT && xml_root.attribute("thin").as_bool(false)==false){
base = (ui_base*)new ui_root_component(frame_mode_t::AUTO);
//TODO: Handle app.class token & page tag

auto token = string2key256(xml_root.attribute("class-token").as_string(nullptr), cache_ctx.src_key);
//cache_ctx.computed_key = key256compose(token, cache_ctx.computed_key);
cache_ctx.page_tag = xml_root.attribute("page").as_string("");
}
else base = caller_ui_node;

_build(doc.child((type==type_t::APP)?strings.APP_TAG:strings.COMPONENT_TAG),(type==type_t::APP)?base:caller_ui_node);
_build(doc.child(
(type==type_t::APP)?strings.APP_TAG:strings.COMPONENT_TAG), base);

if(type==type_t::APP)root=base;
else root = nullptr;
Expand Down Expand Up @@ -317,7 +326,7 @@ void ui_tree_xml::_build(const pugi::xml_node& root, ui_base* root_ui){
}

}
else if (strcmp(root.name(),"component")==0){}
else if (strcmp(root.name(),strings.COMPONENT_TAG)==0){}

# if __has_include("./ui.xml-widgets.autogen.cpp")
# include "./ui.xml-widgets.autogen.cpp"
Expand Down Expand Up @@ -523,14 +532,11 @@ void ui_tree_xml::_build_base_widget_extended_attr(const pugi::xml_node &root, u

_build_base_widget_extended_attr(root, (ui_base *)current);


//TODO: Check if this has still any effect
if(strcmp(root.parent().name(),strings.APP_TAG)==0){
current->reparent_frame(root_ui);
}




//TODO: Optimize copies
smap<std::string> props = current->compute_refresh_style(root.attribute("mixin").as_string(""));
/*{auto tmp = current->compile_mixins((std::string("+")+root.name()).data()); for(const auto& i: tmp)props.insert_or_assign(i.first,std::move(i.second));}
Expand Down Expand Up @@ -560,7 +566,6 @@ void ui_tree_xml::_build_base_widget_extended_attr(const pugi::xml_node &root, u
if(strcmp(i.name(),"src")!=0)props.insert_or_assign(i.name(), i.value());
}
}


for (const auto &i : root.attributes()) {
props.insert_or_assign(i.name(), i.value());
Expand Down

0 comments on commit ff1c5f1

Please sign in to comment.