Commit 64a54969 authored by Florian Blasius's avatar Florian Blasius 🤘
Browse files

Start working on text selection with cursor.

parent 5e817f62
......@@ -7,6 +7,8 @@ use layout_object::{LayoutObject, LayoutResult};
use properties::{Constraint, Offset, Rect, ScrollViewerMode};
use theme::Theme;
// todo: not finished yet!!!!
#[derive(Default)]
pub struct ScrollLayoutObject {
child_bounds: Cell<Rect>,
......
......@@ -110,7 +110,7 @@ cursor:focus {
background: #f8de4c;
}
cursor.selected {
cursor:expanded {
opacity: 0.3;
}
......
use std::rc::Rc;
use layout_object::TextSelectionLayoutObject;
use properties::{Label, TextSelection};
use render_object::RectangleRenderObject;
use theme::Selector;
use widget::{Template, Widget};
use properties::{TextSelection, Label};
use widget::{
add_selector_to_widget, remove_selector_from_widget, Context, State, Template, Widget,
};
// Default state of the `Cursor` widget.
struct CursorState;
impl State for CursorState {
fn update(&self, context: &mut Context) {
let mut selection_length = 0;
if let Ok(selection) = context.widget.borrow_property::<TextSelection>() {
selection_length = selection.length;
}
if selection_length > 0 {
add_selector_to_widget("expanded", context.widget);
} else {
remove_selector_from_widget("expanded", context.widget)
}
}
}
/// The `Cursor` represents a text cursor used to mark text.
///
///
/// # Properties
///
///
/// * `TextSelection` - Represents the current selection of the text used by the cursor.
///
///
/// # Others
///
///
/// * `RectangleRenderObject` - Used to draw the widget.
/// * `TextSelectionLayoutObject` - Used to layout the widget.
pub struct Cursor;
......@@ -24,6 +46,7 @@ impl Widget for Cursor {
.with_property(TextSelection::default())
.with_render_object(RectangleRenderObject)
.with_layout_object(TextSelectionLayoutObject)
.with_state(Rc::new(CursorState))
.with_debug_name("Cursor")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment