新的布局语法,修复部分编译警告

This commit is contained in:
daiqingshuang 2025-04-10 13:34:15 +08:00
parent 7f37e2098d
commit bbfe5ab665
11 changed files with 19 additions and 49 deletions

View File

@ -32,6 +32,8 @@ function(set_cpp_standard standard)
# GCC/Clang
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra)
# 使
add_compile_options(-Wno-unused-parameter)
# C++
if(${standard} GREATER 14) # 使 GREATER_EQUAL
add_compile_options(-Wshadow -Wnon-virtual-dtor)

View File

@ -75,9 +75,7 @@ int main(int argc, char* argv[]) {
mslot(mbutton)
.margin({10})
.visibility(visibility_t::visible)
[
text_block
]
(text_block)
);
// const auto button2 = mnew(mbutton)
@ -89,14 +87,12 @@ int main(int argc, char* argv[]) {
const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!");
window->set_content(
mborder()
mnew(mborder)
[
mslot(mborder)
.h_alignment(horizontal_alignment_t::center)
.v_alignment(vertical_alignment_t::center)
[
button
]
(button)
]
);

View File

@ -68,7 +68,7 @@ enum class key_code : uint16_t {
p = 0x29,
left_bracket = 0x2A, // [
right_bracket = 0x2B, // ]
backslash = 0x2C, // \
backslash = 0x2C, // 左斜杠
caps_lock = 0x2D,
a = 0x2E,

View File

@ -137,14 +137,14 @@ std::optional<linear_color> parse_rgb_rgba_color(const std::string& in_str) {
// **按逗号分割**
const auto& components_str = split_string(content, ',');
const size_t expected_components = is_rgba ? 4 : 3;
const auto expected_components = is_rgba ? 4uz : 3uz;
if (components_str.size() != expected_components) {
return std::nullopt; // 组件数量不正确
}
std::array<float, 4> components;
int32_t index = 0;
auto index = 0uz;
bool uses_float = false;
bool uses_int = false;

View File

@ -48,6 +48,7 @@ bool windows_render_state::init(ID3D11Device* in_device, IDXGIFactory* in_factor
.Denominator = 1
},
.Format = format,
.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
},
.SampleDesc = {
.Count = 1,
@ -181,13 +182,11 @@ void windows_render_state::rebuild_swapchain(const Eigen::Vector2i& size) {
context->Flush();
// 2. 释放当前渲染目标视图
DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM; // 默认格式
auto dx_render_target_view = get_dx_render_target_view();
if (dx_render_target_view) {
// 保存格式以便稍后使用
// 保存格式以便稍后使用
D3D11_RENDER_TARGET_VIEW_DESC rtv_desc = {};
dx_render_target_view->GetDesc(&rtv_desc);
format = rtv_desc.Format;
// 释放资源
dx_render_target_view->Release();

View File

@ -48,7 +48,6 @@ void rw_texture2d::create(const texture_data& in_data) {
desc.sample_count = 1;
auto d3d_device = (ID3D11Device*)sg_d3d11_device();
auto d3d_context = (ID3D11DeviceContext*)sg_d3d11_device_context();
// 创建纹理
ID3D11Texture2D* tex2d = nullptr;

View File

@ -39,7 +39,7 @@ public:
auto get_line_spacing() const { return line_spacing_; }
auto get_max_width() const { return max_width_; }
hit_test_handle on_mouse_move(const Eigen::Vector2f& in_position) override { return hit_test_handle::handled(); }
hit_test_handle on_mouse_move(const Eigen::Vector2f& in_position) override { (void)in_position; return hit_test_handle::handled(); }
auto compute_desired_size(float in_layout_scale_multiplier) const -> Eigen::Vector2f override;
hit_test_handle on_mouse_wheel(const Eigen::Vector2f& in_position, const wheel_event& in_delta) override;
private:

View File

@ -7,5 +7,5 @@
*/
class mleaf_widget : public mwidget {
public:
void arrange_children(const geometry_t& in_allotted_geometry) override {}
void arrange_children(const geometry_t& in_allotted_geometry) override { (void)in_allotted_geometry; }
};

View File

@ -31,7 +31,7 @@
return me(); \
} \
const auto& get() const { return widget_; } \
auto& operator[](const std::shared_ptr<mwidget>& in_widget) { \
auto& operator()(const std::shared_ptr<mwidget>& in_widget) { \
set(in_widget); \
return me(); \
} \

View File

@ -6,29 +6,6 @@
#include "widget_new.h"
#include "compound_widget/mbutton.h"
// 前向声明
template<typename WidgetType>
struct mwidget_decl;
template<typename T>
concept has_add_slot = requires(T& t) {
{ t.add_slot() };
};
template<typename T>
concept has_set_content = requires(T& t, std::shared_ptr<mwidget> in_widget) {
t.set_content(in_widget);
};
template<typename WidgetType>
struct mwidget_slot_guard {
auto& operator+(const typename WidgetType::slot_type& in_slot) {
slots_.push_back(in_slot);
return *this;
}
std::vector<typename WidgetType::slot_type> slots_;
};
template<typename WidgetType>
struct mwidget_decl {
mwidget_decl() {
@ -44,16 +21,14 @@ struct mwidget_decl {
mwidget_decl(const mwidget_decl&) = delete;
mwidget_decl& operator=(const mwidget_decl&) = delete;
std::shared_ptr<WidgetType> operator<<=(const mwidget_slot_guard<WidgetType>& in_guard) {
for (const auto& slot: in_guard.slots_) {
widget_->push_slot(slot);
}
return widget_;
}
template<typename ...Args>
auto operator[](Args&&... in_args) {
return (*widget_)[std::forward<Args>(in_args)...];
}
operator std::shared_ptr<mwidget>() const { return widget_; }
std::shared_ptr<WidgetType> widget_;
};
#define mslot(type) type::slot_type()
#define mnew(type, ...) mwidget_decl<type>(__VA_ARGS__) <<= mwidget_slot_guard<type>()
#define mnew(type, ...) mwidget_decl<type>(__VA_ARGS__)

View File

@ -288,7 +288,7 @@ public:
mouse_.position = window_pos;
// 执行命中测试,查找鼠标位置下的控件
const auto& result = perform_hit_test(window_pos, [this](mwidget* widget, const Eigen::Vector2f& local_pos) {
const auto& result = perform_hit_test(window_pos, [](mwidget* widget, const Eigen::Vector2f& local_pos) {
return widget->on_mouse_move(local_pos);
});
@ -330,7 +330,6 @@ public:
return widget->on_mouse_button_up(local_pos, button);
});
const auto& hit_widget = hit_result.widget;
const auto& widget_local_pos = hit_result.widget_space_pos;
// 获取之前点击的控件