按钮
This commit is contained in:
parent
28980f8c41
commit
21a12b257f
@ -40,7 +40,7 @@ void mbutton::on_paint(mirage_paint_context& in_context) {
|
|||||||
void mbutton::on_click(const Eigen::Vector2f& in_position, mouse_button in_button) {
|
void mbutton::on_click(const Eigen::Vector2f& in_position, mouse_button in_button) {
|
||||||
mborder::on_click(in_position, in_button);
|
mborder::on_click(in_position, in_button);
|
||||||
std::println(std::cout, "点击 Button: {}, {}", in_position.x(), in_position.y());
|
std::println(std::cout, "点击 Button: {}, {}", in_position.x(), in_position.y());
|
||||||
color_ = pressed_color_;
|
color_ = normal_color_;
|
||||||
invalidate(invalidate_reason::paint);
|
invalidate(invalidate_reason::paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
struct button_args {
|
struct button_args {
|
||||||
WARG(linear_color, normal_color, linear_color(0.2f, 0.2f, 0.2f, 1))
|
WARG(linear_color, normal_color, linear_color(0.2f, 0.2f, 0.2f, 1))
|
||||||
WARG(linear_color, hover_color, linear_color(0.2f, 0.2f, 0.2f, 1))
|
WARG(linear_color, hover_color, linear_color(0.1f, 0.1f, 0.1f, 1))
|
||||||
WARG(linear_color, pressed_color, linear_color(0.1f, 0.1f, 0.1f, 1))
|
WARG(linear_color, pressed_color, linear_color(0.1f, 0.1f, 0.1f, 1))
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ public:
|
|||||||
|
|
||||||
virtual void on_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
virtual void on_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
||||||
virtual void on_double_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
virtual void on_double_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
||||||
|
hit_test_handle on_mouse_move(const Eigen::Vector2f& in_position) override { return hit_test_handle::handled(); }
|
||||||
virtual void on_mouse_enter() override;
|
virtual void on_mouse_enter() override;
|
||||||
virtual void on_mouse_leave() override;
|
virtual void on_mouse_leave() override;
|
||||||
virtual hit_test_handle on_mouse_button_down(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
virtual hit_test_handle on_mouse_button_down(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
||||||
|
@ -29,12 +29,6 @@ auto mtext_block::compute_desired_size(float in_layout_scale_multiplier) const -
|
|||||||
return layout_.total_size;
|
return layout_.total_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
hit_test_handle mtext_block::on_mouse_wheel(const Eigen::Vector2f& in_position, const wheel_event& in_delta) {
|
|
||||||
font_size_ += in_delta.delta_y;
|
|
||||||
update_layout();
|
|
||||||
return mleaf_widget::on_mouse_wheel(in_position, in_delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mtext_block::update_layout() {
|
void mtext_block::update_layout() {
|
||||||
layout_ = font_manager::instance().layout_text(text_, font_, font_size_, max_width_, line_spacing_);
|
layout_ = font_manager::instance().layout_text(text_, font_, font_size_, max_width_, line_spacing_);
|
||||||
invalidate(invalidate_reason::layout);
|
invalidate(invalidate_reason::layout);
|
||||||
|
@ -48,9 +48,7 @@ public:
|
|||||||
auto get_line_spacing() const { return line_spacing_; }
|
auto get_line_spacing() const { return line_spacing_; }
|
||||||
auto get_max_width() const { return max_width_; }
|
auto get_max_width() const { return max_width_; }
|
||||||
|
|
||||||
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;
|
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:
|
private:
|
||||||
void update_layout();
|
void update_layout();
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
void mh_box::arrange_children(const geometry_t& in_allotted_geometry) {
|
void mh_box::arrange_children(const geometry_t& in_allotted_geometry) {
|
||||||
arrange_box_children<orientation_t::horizontal>(in_allotted_geometry,
|
arrange_box_children<orientation_t::horizontal>(in_allotted_geometry,
|
||||||
get_dpi_scale(),
|
get_dpi_scale(),
|
||||||
visibility_t::any_visible,
|
visibility_t::any_layout,
|
||||||
get_slots());
|
get_slots());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ Eigen::Vector2f mh_box::compute_desired_size(float in_layout_scale_multiplier) c
|
|||||||
void mv_box::arrange_children(const geometry_t& in_allotted_geometry) {
|
void mv_box::arrange_children(const geometry_t& in_allotted_geometry) {
|
||||||
arrange_box_children<orientation_t::vertical>(in_allotted_geometry,
|
arrange_box_children<orientation_t::vertical>(in_allotted_geometry,
|
||||||
get_dpi_scale(),
|
get_dpi_scale(),
|
||||||
visibility_t::any_visible,
|
visibility_t::any_layout,
|
||||||
get_slots());
|
get_slots());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <ranges>
|
||||||
|
|
||||||
#include "mwindow.h"
|
#include "mwindow.h"
|
||||||
#include "geometry/dpi_helper.h"
|
#include "geometry/dpi_helper.h"
|
||||||
#include "platform_window/platform_window.h"
|
#include "platform_window/platform_window.h"
|
||||||
@ -390,11 +392,10 @@ public:
|
|||||||
return perform_hit_test(content_widget_.get(), window_pos, hit_func);
|
return perform_hit_test(content_widget_.get(), window_pos, hit_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
hit_test_result perform_hit_test(
|
static hit_test_result perform_hit_test(
|
||||||
mwidget_interface* widget,
|
mwidget_interface* widget,
|
||||||
const Eigen::Vector2f& window_pos,
|
const Eigen::Vector2f& window_pos,
|
||||||
const std::function<hit_test_handle(mwidget_interface*, const Eigen::Vector2f&)>& hit_func) const
|
const std::function<hit_test_handle(mwidget_interface*, const Eigen::Vector2f&)>& hit_func) {
|
||||||
{
|
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -402,15 +403,15 @@ public:
|
|||||||
const auto& widget_geo = widget->get_geometry();
|
const auto& widget_geo = widget->get_geometry();
|
||||||
|
|
||||||
// 检查点是否在控件区域内
|
// 检查点是否在控件区域内
|
||||||
auto widget_local_pos = widget_geo.is_under_location(window_pos);
|
const auto widget_local_pos = widget_geo.is_under_location(window_pos);
|
||||||
if (!widget_local_pos) {
|
if (!widget_local_pos) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先递归查找子控件(从前到后)
|
// 先递归查找子控件(从前到后)
|
||||||
// 这样可以优先处理上层控件的点击
|
// 这样可以优先处理上层控件的点击
|
||||||
for (auto it = widget->get_children().rbegin(); it != widget->get_children().rend(); ++it) {
|
for (const auto& it : std::ranges::reverse_view(widget->get_children())) {
|
||||||
if (const auto& result = perform_hit_test(it->get(), window_pos, hit_func)) {
|
if (const auto& result = perform_hit_test(it.get(), window_pos, hit_func)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,11 +428,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 访问器
|
// 访问器
|
||||||
platform_window* get_platform_window() const {
|
[[nodiscard]] auto get_platform_window() const {
|
||||||
return platform_window_.get();
|
return platform_window_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const mirage_window_state& get_render_state() const {
|
[[nodiscard]] const auto& get_render_state() const {
|
||||||
return *window_state_;
|
return *window_state_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user