-
Notifications
You must be signed in to change notification settings - Fork 42
Ametric percent #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Ametric percent #714
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,9 @@ | |
| #include "BorderRadius.h" | ||
|
|
||
| void ass::prop::Property<ass::BorderRadius>::applyFor(AView* view) { | ||
| view->setBorderRadius(mInfo.radius); | ||
| if (mInfo.radius.getUnit() == AMetric::T_PR) { | ||
| view->setBorderRadius((glm::min(view->getWidth(), view->getHeight())) * (mInfo.radius.getValuePx() * 0.01f)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not sure this would work perfectly fine but your solution is definitely small and simple. Give me some time to test please. |
||
| } else { | ||
| view->setBorderRadius(mInfo.radius.getValuePx()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,14 +67,16 @@ class AString; | |
| * <!-- aui:index_alias _dp --> | ||
| * <!-- aui:index_alias _pt --> | ||
| * <!-- aui:index_alias _px --> | ||
| * <!-- aui:index_alias _pr --> | ||
| * | ||
| * Currently supported units: | ||
| * | ||
| * | Unit | Enum | Literal | Value | | ||
| * | -------------------------- | ---- | ------- | --------------------------- | | ||
| * | Density-independent Pixels | T_DP | _dp | px * `scale_factor` | | ||
| * | Typography point | T_PT | _pt | px * `scale_factor` * 4 / 3 | | ||
| * | Pixels | T_PX | _px | px | | ||
| * | Unit | Enum | Literal | Value | | ||
| * | -------------------------- | ---- | ------- | ---------------------------------------- | | ||
| * | Density-independent Pixels | T_DP | _dp | px * `scale_factor` | | ||
| * | Typography point | T_PT | _pt | px * `scale_factor` * 4 / 3 | | ||
| * | Pixels | T_PX | _px | px | | ||
| * | Percent | T_PR | _pr | reference_dimension * value / 100 | | ||
| * | ||
| * It's highly recommended to use only Density-independent Pixel unit (_dp). DP guarantees that your application | ||
| * will correctly handle systems with hidpi screens. | ||
|
|
@@ -88,6 +90,7 @@ class API_AUI_VIEWS AMetric | |
| T_PX, | ||
| T_DP, | ||
| T_PT, | ||
| T_PR, | ||
| }; | ||
|
|
||
| private: | ||
|
|
@@ -141,6 +144,7 @@ class API_AUI_VIEWS AMetric | |
| [[nodiscard]] float getValuePx() const; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling It would be safer to make Example for // in AMetric::getValuePx()
switch (mUnit) {
// ... other cases
case T_PR:
AUI_ASSERT_NOT_REACHED("AMetric with T_PR unit cannot be converted to pixels without a reference dimension. Use getValuePx(float) instead.");
return 0.f;
default:
return mValue;
} |
||
| [[nodiscard]] float getValueDp() const; | ||
|
|
||
|
|
||
| static float fromPxToMetric(float value, Unit unit); | ||
|
|
||
| operator float() const { | ||
|
|
@@ -247,6 +251,10 @@ constexpr inline AMetric operator""_pt(unsigned long long v) | |
| { | ||
| return AMetric(static_cast<float>(static_cast<long long>(v)), AMetric::T_PT); | ||
| } | ||
| constexpr inline AMetric operator""_pr(unsigned long long v) | ||
| { | ||
| return AMetric(static_cast<float>(static_cast<long long>(v)), AMetric::T_PR); | ||
| } | ||
|
|
||
| inline std::ostream& operator<<(std::ostream& o, const AMetric& value) { | ||
| o << value.getRawValue(); | ||
|
|
@@ -260,6 +268,9 @@ inline std::ostream& operator<<(std::ostream& o, const AMetric& value) { | |
| case AMetric::T_PT: | ||
| o << "_pt"; | ||
| break; | ||
| case AMetric::T_PR: | ||
| o << "_pr"; | ||
| break; | ||
|
|
||
| default: | ||
| break; | ||
|
|
@@ -279,6 +290,7 @@ template <> struct fmt::formatter<AMetric> { | |
| case AMetric::T_PX: suffix = "px"; break; | ||
| case AMetric::T_DP: suffix = "dp"; break; | ||
| case AMetric::T_PT: suffix = "pt"; break; | ||
| case AMetric::T_PR: suffix = "pr"; break; | ||
| default: suffix = ""; break; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
|
|
||
| get_filename_component(_t ${CMAKE_CURRENT_SOURCE_DIR} NAME) | ||
|
|
||
| aui_executable("aui.example.${_t}") | ||
| aui_link("aui.example.${_t}" PRIVATE aui::core aui::views) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * AUI Framework - Declarative UI toolkit for modern C++20 | ||
| * Copyright (C) 2020-2025 Alex2772 and Contributors | ||
| * | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| #include <AUI/Platform/Entry.h> | ||
| #include <AUI/Platform/AWindow.h> | ||
| #include <AUI/Util/UIBuildingHelpers.h> | ||
|
|
||
| using namespace ass; | ||
| using namespace declarative; | ||
|
|
||
|
|
||
| AUI_ENTRY { | ||
| auto window = _new<AWindow>("Checkbox", 300_dp, 100_dp); | ||
| window->setContents( | ||
| Vertical { | ||
| Centered { | ||
| _new<ALabel>("25%") AUI_OVERRIDE_STYLE { | ||
| BorderRadius { 25_pr }, | ||
| FixedSize { 200_px , 40_px }, | ||
| BackgroundSolid { 100_rgb }, | ||
| }, | ||
|
|
||
| _new<ALabel>("50%") AUI_OVERRIDE_STYLE { | ||
| Margin { 100_px, 0, 0, 0}, | ||
| BorderRadius { 50_pr }, | ||
| FixedSize { 200_px , 40_px }, | ||
| BackgroundSolid { 150_rgb }, | ||
| }, | ||
|
|
||
| _new<ALabel>("75%") AUI_OVERRIDE_STYLE { | ||
| Margin { 200_px, 0, 0, 0}, | ||
| BorderRadius { 75_pr }, | ||
| FixedSize { 200_px , 40_px }, | ||
| BackgroundSolid { 200_rgb }, | ||
| }, | ||
| _new<ALabel>("100%") AUI_OVERRIDE_STYLE { | ||
| Margin { 300_px, 0, 0, 0}, | ||
| BorderRadius { 100_pr }, | ||
| FixedSize { 200_px , 40_px }, | ||
| BackgroundSolid { 300_rgb }, | ||
| }, | ||
| //Circle! | ||
| _new<ALabel>("") AUI_OVERRIDE_STYLE { | ||
| Margin { 400_px, 0, 0, 0}, | ||
| BorderRadius { 100_pr }, | ||
| FixedSize { 40_px }, | ||
| BackgroundSolid { 5148_rgb }, | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+23
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The layout structure here is a bit confusing. window->setContents(
Vertical {
_new<ALabel>("10%") AUI_OVERRIDE_STYLE {
BorderRadius { 10_pr },
FixedSize { 200_px , 40_px },
BackgroundSolid { 100_rgb },
},
// ... other labels as direct children of Vertical
}
);This would make the example easier to understand and maintain. |
||
| ); | ||
| window->show(); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you