fix a layout bug

This commit is contained in:
王劲鹏 2021-04-19 17:57:10 +08:00 committed by osborn
parent bb03b8b5a3
commit 00528a3ce5
2 changed files with 15 additions and 43 deletions

View File

@ -211,12 +211,12 @@ void DoricLayouts::measureContent(qreal targetWidth, qreal targetHeight) {
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined && if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit && parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) { this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
setMeasuredWidth(0); setMeasuredWidth(targetWidth);
} }
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined && if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit && parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) { this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
setMeasuredHeight(0); setMeasuredHeight(targetHeight);
} }
} }
} }

View File

@ -1,47 +1,19 @@
import { Group, Panel, text, gravity, Color, LayoutSpec, vlayout, hlayout, scroller, layoutConfig } from "doric"; import { Group, Panel, stack, Color, LayoutSpec, layoutConfig } from "doric";
import { colors } from "./utils";
@Entry @Entry
class LayoutDemo extends Panel { class SimpleDemo extends Panel {
build(rootView: Group) { build(rootView: Group) {
scroller( stack([
vlayout( stack([
[ stack(
text({ [],
text: "五子棋",
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
textSize: 30,
textColor: Color.WHITE,
backgroundColor: colors[0],
textAlignment: gravity().center(),
height: 50,
}),
hlayout(
[
text({
text: "当前:",
textSize: 20,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just().configWeight(1),
height: 50,
backgroundColor: colors[1],
}),
text({
text: "获胜方:",
textSize: 20,
textColor: Color.WHITE,
layoutConfig: layoutConfig().just().configWeight(1),
height: 50,
backgroundColor: colors[2],
}),
],
{ {
layoutConfig: layoutConfig().fit().configWidth(LayoutSpec.MOST), layoutConfig: layoutConfig().just().configWidth(LayoutSpec.MOST),
}), height: 50,
], { backgroundColor: Color.RED
layoutConfig: layoutConfig().most(), }
backgroundColor: Color.parse('#ecf0f1'), )
}) ])
).in(rootView) ]).in(rootView)
} }
} }