Skip to content

New computed value system#188

Open
ananas-dev wants to merge 3 commits intomainfrom
lufio/media
Open

New computed value system#188
ananas-dev wants to merge 3 commits intomainfrom
lufio/media

Conversation

@ananas-dev
Copy link
Copy Markdown
Member

No description provided.

Comment thread src/vaev-engine/values/computed.cpp Outdated
Comment on lines +21 to +28
export struct Viewport {
// https://drafts.csswg.org/css-values/#small-viewport-size
RectAu small;
// https://drafts.csswg.org/css-values/#large-viewport-size
RectAu large = small;
// https://drafts.csswg.org/css-values/#dynamic-viewport-size
RectAu dynamic = small;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated from Layout::Viewport

Comment on lines 43 to 49

// FIXME: This should be renamed to changeDisplayArea, and we should make sure that
// its input is the page box and not the page area.
void changeViewport(Vec2Au viewport) {
if (_media.changeViewport(viewport))
if (_media.changeDisplayArea(viewport))
invalidateRender();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we renamed it changeDisplayAreana() it should take something like:

using DisplayArea = Union<Viewport, PageArea>

Comment on lines 81 to 86
Driver::RenderResult& ensureRender() {
if (_render)
return *_render;
_render = Driver::render(_document.upgrade(), _media, {.small = _media.viewportSize()});
_render = Driver::render(_document.upgrade(), _media, {.small = _media.displayArea()});
return *_render;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we keep the display reana object and the full Viewport, we can pass it here instead of digging in media. Which will be needed for stuff for position: sticky;

Comment thread src/vaev-engine/driver/print.cpp Outdated
Comment on lines +120 to +121
context.media.width / Au{context.media.resolution},
context.media.height / Au{context.media.resolution}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we transformed our resolution object from a nice and rich object to something semantically poor. This looks very confusing if you don't know/remeber that resolution actually means scale.

Comment thread src/vaev-engine/values/computed.cpp Outdated
Comment on lines +30 to +55
struct ComputationContext {
// FIXME: Fonts are not optional but are wrapped in Opt<> due to the lack of a default constructor.
// They also require mutability for caching stuff which forces ComputationContext to be passed
// by mut reference. Ideally they should be replaced by a richer version of
Opt<Gfx::Font> rootFont = NONE;
Opt<Gfx::Font> font = NONE;
WritingMode writingMode = WritingMode::HORIZONTAL_TB;
Viewport viewport = {.small = {800_au, 600_au}}; /// Viewport of the current box
Vec2Au displayArea = {800_au, 600_au};
};

export template <typename T>
concept Computible = requires(T const& a, ComputationContext& ctx) {
{ toComputed(a, ctx) } -> Meta::Convertible<Computed<T>>;
};

export template <typename T>
struct IdentityComputed {
using Type = T;
};

export template <typename T>
requires Meta::Derive<_Computed<T>, IdentityComputed<T>>
Computed<T> toComputed(T const& val, ComputationContext&) {
return val;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be consolidated into a Computable traits or something.

Exemple:

template <>
struct Computable<Foo> {
    using Type = FooComputed;
    static Type toComputed(Foo const&  val, ctx){}
}

And for a simple case, you can just do

template <>
struct Computable<Foo> : IdentityComputable<Foo> {};

Comment thread src/vaev-engine/values/ratio.cpp Outdated
Comment on lines +40 to +47
export template <>
struct _Computed<Ratio> {
using Type = Number;
};

export Computed<Ratio> toComputed(Ratio const& val, [[maybe_unused]] ComputationContext& ctx) {
return val.num / val.deno;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.orientation = Print::Orientation::LANDSCAPE,

.resolution = Resolution::fromDpi(96),
.resolution = Resolution::fromDpi(96).toDppx(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smell, see comment below and above 😅

.orientation = Print::Orientation::LANDSCAPE,

.resolution = Resolution::fromDpi(96),
.resolution = Resolution::fromDpi(96).toDppx(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread src/vaev-engine/style/media.cpp Outdated
.orientation = Print::orientationFromSize(viewport),

.resolution = Resolution::fromDpi(96),
.resolution = Resolution::fromDpi(96).toDppx(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same smell as all the resolution stuff.

Comment thread src/vaev-engine/values/computed.cpp Outdated
};

export template <typename T>
concept Computible = requires(T const& a, ComputationContext& ctx) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants