浏览代码

LibGUI: Add set_selection() convenience helper to GlyphMapWidget

thankyouverycool 3 年之前
父节点
当前提交
df443863bd
共有 2 个文件被更改,包括 9 次插入0 次删除
  1. 8 0
      Userland/Libraries/LibGUI/GlyphMapWidget.cpp
  2. 1 0
      Userland/Libraries/LibGUI/GlyphMapWidget.h

+ 8 - 0
Userland/Libraries/LibGUI/GlyphMapWidget.cpp

@@ -89,6 +89,14 @@ void GlyphMapWidget::set_active_glyph(int glyph, ShouldResetSelection should_res
     update();
 }
 
+void GlyphMapWidget::set_selection(int start, int size, Optional<u32> active_glyph)
+{
+    m_selection.set_start(start);
+    m_selection.set_size(size);
+    if (active_glyph.has_value())
+        set_active_glyph(active_glyph.value(), ShouldResetSelection::No);
+}
+
 Gfx::IntRect GlyphMapWidget::get_outer_rect(int glyph) const
 {
     glyph -= m_active_range.first;

+ 1 - 0
Userland/Libraries/LibGUI/GlyphMapWidget.h

@@ -55,6 +55,7 @@ public:
 
     void set_active_range(Unicode::CodePointRange);
     void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
+    void set_selection(int start, int size, Optional<u32> active_glyph = {});
     void clear_selection() { m_selection.set_size(0); }
     void scroll_to_glyph(int);
     void update_glyph(int);